-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathfabric.go
79 lines (73 loc) · 2.45 KB
/
fabric.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package golang
import (
"github.com/davidkhala/fabric-common-chaincode-golang/classic"
. "github.com/davidkhala/goutils"
"github.com/golang/protobuf/ptypes/timestamp"
"github.com/hyperledger/fabric-chaincode-go/shim"
"github.com/hyperledger/fabric-protos-go/peer"
)
func (cc CommonChaincode) InvokeChaincode(chaincodeName string, args [][]byte, channel string) peer.Response {
var resp = cc.CCAPI.InvokeChaincode(chaincodeName, args, channel)
classic.PanicPeerResponse(resp)
return resp
}
func (cc CommonChaincode) GetBinding() []byte {
var result, err = cc.CCAPI.GetBinding()
PanicError(err)
return result
}
func (cc CommonChaincode) GetState(key string) []byte {
var bytes, err = cc.CCAPI.GetState(key)
PanicError(err)
return bytes
}
func (cc CommonChaincode) GetStateObj(key string, v interface{}) bool {
var bytes = cc.GetState(key)
if bytes == nil {
return false
}
FromJson(bytes, v)
return true
}
func (cc CommonChaincode) GetTransient() map[string][]byte {
transient, err := cc.CCAPI.GetTransient()
PanicError(err)
return transient
}
func (cc CommonChaincode) PutStateObj(key string, v interface{}) {
var bytes = ToJson(v)
cc.PutState(key, bytes)
}
func (cc CommonChaincode) PutState(key string, value []byte) {
var err = cc.CCAPI.PutState(key, value)
PanicError(err)
}
func (cc CommonChaincode) DelState(key string) {
var err = cc.CCAPI.DelState(key)
PanicError(err)
}
func (cc CommonChaincode) GetTxTimestamp() timestamp.Timestamp {
ts, err := cc.CCAPI.GetTxTimestamp()
PanicError(err)
return *ts
}
func (cc CommonChaincode) GetHistoryForKey(key string) shim.HistoryQueryIteratorInterface {
var r, err = cc.CCAPI.GetHistoryForKey(key)
PanicError(err)
return r
}
func (cc CommonChaincode) GetStateByRange(startKey string, endKey string) shim.StateQueryIteratorInterface {
var r, err = cc.CCAPI.GetStateByRange(startKey, endKey)
PanicError(err)
return r
}
// GetStateByRangeWithPagination This call is only supported in a read only transaction.
func (cc CommonChaincode) GetStateByRangeWithPagination(startKey, endKey string, pageSize int, bookmark string) (shim.StateQueryIteratorInterface, QueryResponseMetadata) {
var iterator, r, err = cc.CCAPI.GetStateByRangeWithPagination(startKey, endKey, int32(pageSize), bookmark)
PanicError(err)
return iterator, QueryResponseMetadata{int(r.FetchedRecordsCount), r.Bookmark}
}
func (cc CommonChaincode) SetEvent(name string, payload []byte) {
var err = cc.CCAPI.SetEvent(name, payload)
PanicError(err)
}