github.com/s7techlab/cckit@v0.10.5/extensions/crosscc/cclocator_setting.go (about) 1 package crosscc 2 3 import ( 4 "fmt" 5 6 "github.com/golang/protobuf/ptypes/empty" 7 8 "github.com/s7techlab/cckit/gateway" 9 "github.com/s7techlab/cckit/router" 10 ) 11 12 type SettingService struct{} 13 14 var _ SettingServiceChaincode = &SettingService{} 15 16 func NewSettingService() *SettingService { 17 return &SettingService{} 18 } 19 20 func LocatorResolver(c SettingServiceChaincode) gateway.ChaincodeLocatorResolver { 21 return func(ctx router.Context, service string) (*gateway.ChaincodeLocator, error) { 22 locator, err := c.ServiceLocatorGet(ctx, &ServiceLocatorId{Service: service}) 23 if err != nil { 24 return nil, fmt.Errorf("chaincode locator not found, service=%s d: %w", service, err) 25 } 26 27 return &gateway.ChaincodeLocator{Channel: locator.Channel, Chaincode: locator.Chaincode}, nil 28 } 29 } 30 31 func (c *SettingService) LocatorResolver() gateway.ChaincodeLocatorResolver { 32 return LocatorResolver(c) 33 } 34 35 func (c *SettingService) ServiceLocatorSet(ctx router.Context, locatorSet *ServiceLocatorSetRequest) (*ServiceLocator, error) { 36 if err := router.ValidateRequest(locatorSet); err != nil { 37 return nil, err 38 } 39 40 locator := &ServiceLocator{ 41 Service: locatorSet.Service, 42 Channel: locatorSet.Channel, 43 Chaincode: locatorSet.Chaincode, 44 } 45 46 return locator, State(ctx).Put(locator) 47 } 48 49 func (c *SettingService) ServiceLocatorGet(ctx router.Context, id *ServiceLocatorId) (*ServiceLocator, error) { 50 if err := router.ValidateRequest(id); err != nil { 51 return nil, err 52 } 53 54 if res, err := State(ctx).Get(id, &ServiceLocator{}); err != nil { 55 return nil, err 56 } else { 57 return res.(*ServiceLocator), nil 58 } 59 } 60 61 func (c *SettingService) ListServiceLocators(ctx router.Context, _ *empty.Empty) (*ServiceLocators, error) { 62 if res, err := State(ctx).List(&ServiceLocator{}); err != nil { 63 return nil, err 64 } else { 65 return res.(*ServiceLocators), nil 66 } 67 } 68 69 func (c *SettingService) PingService(context router.Context, id *ServiceLocatorId) (*PingServiceResponse, error) { 70 panic("implement me") 71 } 72 73 func (c *SettingService) PingServices(context router.Context, empty *empty.Empty) (*PingServiceResponses, error) { 74 panic("implement me") 75 }