github.com/s7techlab/cckit@v0.10.5/extensions/encryption/testdata/cc_external.go (about) 1 package testdata 2 3 import ( 4 "github.com/s7techlab/cckit/examples/payment" 5 "github.com/s7techlab/cckit/examples/payment/schema" 6 7 "github.com/s7techlab/cckit/extensions/encryption" 8 "github.com/s7techlab/cckit/router" 9 "github.com/s7techlab/cckit/router/param" 10 ) 11 12 // Test interaction with external encrypted chaincode (payments) 13 // see example/payment 14 func NewExternaldCC(encCCName, channelName string) *router.Chaincode { 15 r := router.New(`external`) 16 17 r. 18 // returns payment state entry from external encrypted cc 19 Query(`checkPayment`, func(c router.Context) (interface{}, error) { 20 var ( 21 paymentType = c.ParamString(`paymentType`) 22 paymentId = c.ParamString(`paymentId`) 23 encKey, err = encryption.KeyFromTransient(c) 24 ) 25 if err != nil { 26 return nil, err 27 } 28 29 // create state key using payments mapping 30 paymentKey, err := payment.StateMappings.PrimaryKey(&schema.Payment{Type: paymentType, Id: paymentId}) 31 if err != nil { 32 return nil, err 33 } 34 35 // we need to encrypt state key, not all args (method name `debugStateGet` must remain unencrypted ) 36 encPaymentKey, err := encryption.KeyEncryptor(encKey)(paymentKey) 37 if err != nil { 38 return nil, err 39 } 40 41 // payment state entry returns decrypted 42 return encryption.InvokeChaincode(c.Stub(), encKey, 43 encCCName, []interface{}{`debugStateGet`, []string(encPaymentKey)}, channelName, &schema.Payment{}) 44 }, param.String(`paymentType`), param.String(`paymentId`)) 45 46 return router.NewChaincode(r) 47 }