-
Notifications
You must be signed in to change notification settings - Fork 6
/
chaincode.go
45 lines (36 loc) · 1.15 KB
/
chaincode.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package cpaper_asservice
import (
"github.com/hyperledger-labs/cckit/extensions/encryption"
"github.com/hyperledger-labs/cckit/extensions/owner"
"github.com/hyperledger-labs/cckit/router"
)
func CCRouter(name string) (*router.Group, error) {
r := router.New(name)
// Store on the ledger the information about chaincode instantiation
r.Init(owner.InvokeSetFromCreator)
if err := RegisterCPaperServiceChaincode(r, &CPaperService{}); err != nil {
return nil, err
}
return r, nil
}
func NewCC() (*router.Chaincode, error) {
r, err := CCRouter(`CommercialPaper`)
if err != nil {
return nil, err
}
return router.NewChaincode(r), nil
}
func NewCCEncrypted() (*router.Chaincode, error) {
r, err := CCRouter(`CommercialPaperEncrypted`)
if err != nil {
return nil, err
}
r.
// encryption key in transient map and encrypted args required
Pre(encryption.ArgsDecrypt).
// default Context replaced with EncryptedStateContext only if key is provided in transient map
Use(encryption.EncStateContext).
// invoke response will be encrypted cause it will be placed in blocks
After(encryption.EncryptInvokeResponse())
return router.NewChaincode(r), nil
}