This repository has been archived by the owner on Apr 5, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
/
api.go
146 lines (114 loc) · 4.31 KB
/
api.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/*
Copyright SecureKey Technologies Inc. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package api
import (
"errors"
"github.com/hyperledger/fabric-sdk-go/pkg/client/channel"
"github.com/hyperledger/fabric-sdk-go/pkg/client/channel/invoke"
"github.com/hyperledger/fabric-sdk-go/pkg/common/providers/fab"
)
// Request contains the data required for endorsements
type Request struct {
// ChaincodeID identifies the chaincode to invoke
ChaincodeID string
// Args to pass to the chaincode
Args [][]byte
// TransientData map (optional)
TransientData map[string][]byte
// Targets for the transaction (optional)
Targets []fab.Peer
// InvocationChain contains meta-data that's used by some Selection Service implementations
// to choose endorsers that satisfy the endorsement policies of all chaincodes involved
// in an invocation chain (i.e. for CC-to-CC invocations).
// Each chaincode may also be associated with a set of private data collection names
// which are used by some Selection Services (e.g. Fabric Selection) to exclude endorsers
// that do NOT have read access to the collections.
// The invoked chaincode (specified by ChaincodeID) may optionally be added to the invocation
// chain along with any collections, otherwise it may be omitted.
InvocationChain []*ChaincodeCall
// CommitType specifies how commits should be handled (default CommitOnWrite)
CommitType CommitType
// IgnoreNameSpaces ignore these namespaces in the write set when CommitType is CommitOnWrite
IgnoreNameSpaces []Namespace
// PeerFilter filters out peers using application-specific logic (optional)
PeerFilter PeerFilter
//TransactionID txn id
TransactionID string
//Nonce nonce
Nonce []byte
// AsyncCommit, if true, indicates that we should NOT wait for a block commit event for the transaction
// before responding. If true, the commit request returns only after reciving a block with the transaction.
AsyncCommit bool
// Handler is a custom invocation handler. If nil then the default handler is used
Handler invoke.Handler
}
// CommitRequest contains the endorsements to be committed along with options
type CommitRequest struct {
// EndorsementResponse is the response received from an endorsement request
EndorsementResponse *channel.Response
// CommitType specifies how commits should be handled (default CommitOnWrite)
CommitType CommitType
// IgnoreNameSpaces ignore these namespaces in the write set when CommitType is CommitOnWrite
IgnoreNameSpaces []Namespace
// AsyncCommit, if true, indicates that we should NOT wait for a block commit event for the transaction
// before responding. If true, the commit request returns only after reciving a block with the transaction.
AsyncCommit bool
// Handler is a custom invocation handler. If nil then the default handler is used
Handler invoke.Handler
}
// ChaincodeCall ...
type ChaincodeCall struct {
ChaincodeName string
Collections []string
}
// PeerConfig contains peer configuration
type PeerConfig interface {
PeerID() string
MSPID() string
PeerAddress() string
MSPConfigPath() string
TLSCertPath() string
}
// CommitType specifies how commits should be handled
type CommitType int
const (
// CommitOnWrite indicates that the transaction should be committed only if
// the consumer chaincode produces a write-set
CommitOnWrite CommitType = iota
// Commit indicates that the transaction should be committed
Commit
// NoCommit indicates that the transaction should not be committed
NoCommit
)
// String returns the string value of CommitType
func (t CommitType) String() string {
switch t {
case CommitOnWrite:
return "commitOnWrite"
case Commit:
return "commit"
case NoCommit:
return "noCommit"
default:
return "unknown"
}
}
// Namespace contains a chaincode name and an optional set of private data collections to ignore
type Namespace struct {
Name string
Collections []string
}
// Peer provides basic information about a peer
type Peer interface {
MSPID() string
Endpoint() string
}
// PeerFilter is applied to peers selected for endorsement and removes
// those groups that don't pass the filter acceptance test
type PeerFilter interface {
Accept(peer Peer) bool
}
// ErrInvalidTxnID indicates that the transaction ID in the request is invalid
var ErrInvalidTxnID = errors.New("transaction ID is invalid for the given nonce")