forked from s7techlab/cckit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.go
More file actions
40 lines (31 loc) · 1.22 KB
/
client.go
File metadata and controls
40 lines (31 loc) · 1.22 KB
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
package gateway
import (
"github.com/hyperledger/fabric-chaincode-go/shim"
"github.com/s7techlab/cckit/state"
)
type ChaincodeClient interface {
Query(stub shim.ChaincodeStubInterface, fn string, args []interface{}, target interface{}) (interface{}, error)
}
type ClientOpt func(*chaincodeClient)
type chaincodeClient struct {
Channel string
Chaincode string
}
func NewChaincodeClient(channelName, chaincodeName string, opts ...Opt) *chaincodeClient {
c := &chaincodeClient{
Channel: channelName,
Chaincode: chaincodeName,
}
return c
}
func (c *chaincodeClient) Query(stub shim.ChaincodeStubInterface, fn string, args []interface{}, target interface{}) (interface{}, error) {
// if target chaincode is encrypted we only can invoke `stateGet` function
// for example < encrypted(`orgGet`), encrypted( &schema.OrganizationId { Id : `123` }) > will be < `stateGet`, []string { key } >
// we know target ( &schema.Organization ), know input parameter type ( &schema.OrganizationId )
// if target has primary key with this type or uniq key with this type - we create state,Ke
//if 1==2 {
// fn = `stateGet`
//
//}
return state.InvokeChaincode(stub, c.Chaincode, append([]interface{}{fn}, args...), c.Channel, target)
}