github.com/s7techlab/cckit@v0.10.5/examples/cars/cars_proxy.go (about) 1 package cars 2 3 import ( 4 "errors" 5 6 "github.com/hyperledger/fabric-chaincode-go/shim" 7 "github.com/s7techlab/cckit/router" 8 p "github.com/s7techlab/cckit/router/param" 9 ) 10 11 // NewProxy created chaincode, related to cars chaincode 12 func NewProxy(carsChannel, carsChaincode string) *router.Chaincode { 13 r := router.New(`cars_proxy`) // also initialized logger with "cars_related" prefix 14 15 r.Init(invokeInit) 16 17 r.Query(`carGet`, queryCarProxy, p.String(`id`)) 18 19 return router.NewChaincode(r) 20 } 21 22 // 23 func queryCarProxy(c router.Context) (interface{}, error) { 24 var ( 25 id = c.ParamString(`id`) 26 ) 27 28 // query external chaincode 29 response := c.Stub().InvokeChaincode(`cars`, [][]byte{[]byte(`carGet`), []byte(id)}, `my_channel`) 30 if response.Status == shim.ERROR { 31 return nil, errors.New(response.Message) 32 } 33 return response.Payload, nil 34 }