-
Notifications
You must be signed in to change notification settings - Fork 2
/
chaincode.go
47 lines (37 loc) · 1.19 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
46
47
package chaincode
import (
"github.com/s7techlab/cckit/extensions/encryption"
"github.com/s7techlab/cckit/extensions/owner"
"github.com/s7techlab/cckit/router"
"github.com/s7techlab/hyperledger-fabric-samples/samples/cpaper"
)
func Router(name string) (*router.Group, error) {
r := router.New(name)
// Store on the ledger the information about chaincode instantiation
r.Init(owner.InvokeSetFromCreator)
if err := cpaper.RegisterCPaperServiceChaincode(r, &cpaper.CPaperService{}); err != nil {
return nil, err
}
return r, nil
}
func New() (*router.Chaincode, error) {
r, err := Router(`CommercialPaper`)
if err != nil {
return nil, err
}
return router.NewChaincode(r), nil
}
func NewEncrypted() (*router.Chaincode, error) {
r, err := Router(`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
}