-
Notifications
You must be signed in to change notification settings - Fork 0
/
unmarshalers.go
259 lines (224 loc) · 9.35 KB
/
unmarshalers.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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
/*
Copyright IBM Corp. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package protoutil
import (
"github.com/hyperledger/fabric-protos-go-apiv2/common"
"github.com/hyperledger/fabric-protos-go-apiv2/ledger/rwset"
"github.com/hyperledger/fabric-protos-go-apiv2/ledger/rwset/kvrwset"
"github.com/hyperledger/fabric-protos-go-apiv2/msp"
"github.com/hyperledger/fabric-protos-go-apiv2/peer"
"github.com/pkg/errors"
"google.golang.org/protobuf/proto"
)
// the implicit contract of all these unmarshalers is that they
// will return a non-nil pointer whenever the error is nil
// UnmarshalBlock unmarshal bytes to a Block
func UnmarshalBlock(encoded []byte) (*common.Block, error) {
block := &common.Block{}
err := proto.Unmarshal(encoded, block)
return block, errors.Wrap(err, "error unmarshalling Block")
}
// UnmarshalChaincodeDeploymentSpec unmarshal bytes to a ChaincodeDeploymentSpec
func UnmarshalChaincodeDeploymentSpec(code []byte) (*peer.ChaincodeDeploymentSpec, error) {
cds := &peer.ChaincodeDeploymentSpec{}
err := proto.Unmarshal(code, cds)
return cds, errors.Wrap(err, "error unmarshalling ChaincodeDeploymentSpec")
}
// UnmarshalChaincodeInvocationSpec unmarshal bytes to a ChaincodeInvocationSpec
func UnmarshalChaincodeInvocationSpec(encoded []byte) (*peer.ChaincodeInvocationSpec, error) {
cis := &peer.ChaincodeInvocationSpec{}
err := proto.Unmarshal(encoded, cis)
return cis, errors.Wrap(err, "error unmarshalling ChaincodeInvocationSpec")
}
// UnmarshalPayload unmarshal bytes to a Payload
func UnmarshalPayload(encoded []byte) (*common.Payload, error) {
payload := &common.Payload{}
err := proto.Unmarshal(encoded, payload)
return payload, errors.Wrap(err, "error unmarshalling Payload")
}
// UnmarshalEnvelope unmarshal bytes to a Envelope
func UnmarshalEnvelope(encoded []byte) (*common.Envelope, error) {
envelope := &common.Envelope{}
err := proto.Unmarshal(encoded, envelope)
return envelope, errors.Wrap(err, "error unmarshalling Envelope")
}
// UnmarshalChannelHeader unmarshal bytes to a ChannelHeader
func UnmarshalChannelHeader(bytes []byte) (*common.ChannelHeader, error) {
chdr := &common.ChannelHeader{}
err := proto.Unmarshal(bytes, chdr)
return chdr, errors.Wrap(err, "error unmarshalling ChannelHeader")
}
// UnmarshalChaincodeID unmarshal bytes to a ChaincodeID
func UnmarshalChaincodeID(bytes []byte) (*peer.ChaincodeID, error) {
ccid := &peer.ChaincodeID{}
err := proto.Unmarshal(bytes, ccid)
return ccid, errors.Wrap(err, "error unmarshalling ChaincodeID")
}
// UnmarshalSignatureHeader unmarshal bytes to a SignatureHeader
func UnmarshalSignatureHeader(bytes []byte) (*common.SignatureHeader, error) {
sh := &common.SignatureHeader{}
err := proto.Unmarshal(bytes, sh)
return sh, errors.Wrap(err, "error unmarshalling SignatureHeader")
}
// UnmarshalIdentifierHeader unmarshal bytes to an IdentifierHeader
func UnmarshalIdentifierHeader(bytes []byte) (*common.IdentifierHeader, error) {
ih := &common.IdentifierHeader{}
err := proto.Unmarshal(bytes, ih)
return ih, errors.Wrap(err, "error unmarshalling IdentifierHeader")
}
func UnmarshalSerializedIdentity(bytes []byte) (*msp.SerializedIdentity, error) {
sid := &msp.SerializedIdentity{}
err := proto.Unmarshal(bytes, sid)
return sid, errors.Wrap(err, "error unmarshalling SerializedIdentity")
}
// UnmarshalHeader unmarshal bytes to a Header
func UnmarshalHeader(bytes []byte) (*common.Header, error) {
hdr := &common.Header{}
err := proto.Unmarshal(bytes, hdr)
return hdr, errors.Wrap(err, "error unmarshalling Header")
}
// UnmarshalConfigEnvelope unmarshal bytes to a ConfigEnvelope
func UnmarshalConfigEnvelope(bytes []byte) (*common.ConfigEnvelope, error) {
cfg := &common.ConfigEnvelope{}
err := proto.Unmarshal(bytes, cfg)
return cfg, errors.Wrap(err, "error unmarshalling ConfigEnvelope")
}
// UnmarshalChaincodeHeaderExtension unmarshal bytes to a ChaincodeHeaderExtension
func UnmarshalChaincodeHeaderExtension(hdrExtension []byte) (*peer.ChaincodeHeaderExtension, error) {
chaincodeHdrExt := &peer.ChaincodeHeaderExtension{}
err := proto.Unmarshal(hdrExtension, chaincodeHdrExt)
return chaincodeHdrExt, errors.Wrap(err, "error unmarshalling ChaincodeHeaderExtension")
}
// UnmarshalProposalResponse unmarshal bytes to a ProposalResponse
func UnmarshalProposalResponse(prBytes []byte) (*peer.ProposalResponse, error) {
proposalResponse := &peer.ProposalResponse{}
err := proto.Unmarshal(prBytes, proposalResponse)
return proposalResponse, errors.Wrap(err, "error unmarshalling ProposalResponse")
}
// UnmarshalChaincodeAction unmarshal bytes to a ChaincodeAction
func UnmarshalChaincodeAction(caBytes []byte) (*peer.ChaincodeAction, error) {
chaincodeAction := &peer.ChaincodeAction{}
err := proto.Unmarshal(caBytes, chaincodeAction)
return chaincodeAction, errors.Wrap(err, "error unmarshalling ChaincodeAction")
}
// UnmarshalResponse unmarshal bytes to a Response
func UnmarshalResponse(resBytes []byte) (*peer.Response, error) {
response := &peer.Response{}
err := proto.Unmarshal(resBytes, response)
return response, errors.Wrap(err, "error unmarshalling Response")
}
// UnmarshalChaincodeEvents unmarshal bytes to a ChaincodeEvent
func UnmarshalChaincodeEvents(eBytes []byte) (*peer.ChaincodeEvent, error) {
chaincodeEvent := &peer.ChaincodeEvent{}
err := proto.Unmarshal(eBytes, chaincodeEvent)
return chaincodeEvent, errors.Wrap(err, "error unmarshalling ChaicnodeEvent")
}
// UnmarshalProposalResponsePayload unmarshal bytes to a ProposalResponsePayload
func UnmarshalProposalResponsePayload(prpBytes []byte) (*peer.ProposalResponsePayload, error) {
prp := &peer.ProposalResponsePayload{}
err := proto.Unmarshal(prpBytes, prp)
return prp, errors.Wrap(err, "error unmarshalling ProposalResponsePayload")
}
// UnmarshalProposal unmarshal bytes to a Proposal
func UnmarshalProposal(propBytes []byte) (*peer.Proposal, error) {
prop := &peer.Proposal{}
err := proto.Unmarshal(propBytes, prop)
return prop, errors.Wrap(err, "error unmarshalling Proposal")
}
// UnmarshalTransaction unmarshal bytes to a Transaction
func UnmarshalTransaction(txBytes []byte) (*peer.Transaction, error) {
tx := &peer.Transaction{}
err := proto.Unmarshal(txBytes, tx)
return tx, errors.Wrap(err, "error unmarshalling Transaction")
}
// UnmarshalChaincodeActionPayload unmarshal bytes to a ChaincodeActionPayload
func UnmarshalChaincodeActionPayload(capBytes []byte) (*peer.ChaincodeActionPayload, error) {
cap := &peer.ChaincodeActionPayload{}
err := proto.Unmarshal(capBytes, cap)
return cap, errors.Wrap(err, "error unmarshalling ChaincodeActionPayload")
}
// UnmarshalChaincodeProposalPayload unmarshal bytes to a ChaincodeProposalPayload
func UnmarshalChaincodeProposalPayload(bytes []byte) (*peer.ChaincodeProposalPayload, error) {
cpp := &peer.ChaincodeProposalPayload{}
err := proto.Unmarshal(bytes, cpp)
return cpp, errors.Wrap(err, "error unmarshalling ChaincodeProposalPayload")
}
// UnmarshalTxReadWriteSet unmarshal bytes to a TxReadWriteSet
func UnmarshalTxReadWriteSet(bytes []byte) (*rwset.TxReadWriteSet, error) {
rws := &rwset.TxReadWriteSet{}
err := proto.Unmarshal(bytes, rws)
return rws, errors.Wrap(err, "error unmarshalling TxReadWriteSet")
}
// UnmarshalKVRWSet unmarshal bytes to a KVRWSet
func UnmarshalKVRWSet(bytes []byte) (*kvrwset.KVRWSet, error) {
rws := &kvrwset.KVRWSet{}
err := proto.Unmarshal(bytes, rws)
return rws, errors.Wrap(err, "error unmarshalling KVRWSet")
}
// UnmarshalHashedRWSet unmarshal bytes to a HashedRWSet
func UnmarshalHashedRWSet(bytes []byte) (*kvrwset.HashedRWSet, error) {
hrws := &kvrwset.HashedRWSet{}
err := proto.Unmarshal(bytes, hrws)
return hrws, errors.Wrap(err, "error unmarshalling HashedRWSet")
}
// UnmarshalSignaturePolicy unmarshal bytes to a SignaturePolicyEnvelope
func UnmarshalSignaturePolicy(bytes []byte) (*common.SignaturePolicyEnvelope, error) {
sp := &common.SignaturePolicyEnvelope{}
err := proto.Unmarshal(bytes, sp)
return sp, errors.Wrap(err, "error unmarshalling SignaturePolicyEnvelope")
}
// UnmarshalPayloadOrPanic unmarshal bytes to a Payload structure or panics
// on error
func UnmarshalPayloadOrPanic(encoded []byte) *common.Payload {
payload, err := UnmarshalPayload(encoded)
if err != nil {
panic(err)
}
return payload
}
// UnmarshalEnvelopeOrPanic unmarshal bytes to an Envelope structure or panics
// on error
func UnmarshalEnvelopeOrPanic(encoded []byte) *common.Envelope {
envelope, err := UnmarshalEnvelope(encoded)
if err != nil {
panic(err)
}
return envelope
}
// UnmarshalBlockOrPanic unmarshal bytes to an Block or panics
// on error
func UnmarshalBlockOrPanic(encoded []byte) *common.Block {
block, err := UnmarshalBlock(encoded)
if err != nil {
panic(err)
}
return block
}
// UnmarshalChannelHeaderOrPanic unmarshal bytes to a ChannelHeader or panics
// on error
func UnmarshalChannelHeaderOrPanic(bytes []byte) *common.ChannelHeader {
chdr, err := UnmarshalChannelHeader(bytes)
if err != nil {
panic(err)
}
return chdr
}
// UnmarshalSignatureHeaderOrPanic unmarshal bytes to a SignatureHeader or panics
// on error
func UnmarshalSignatureHeaderOrPanic(bytes []byte) *common.SignatureHeader {
sighdr, err := UnmarshalSignatureHeader(bytes)
if err != nil {
panic(err)
}
return sighdr
}
func UnmarshalTransactionActionOrPanic(bytes []byte) *peer.TransactionAction {
transactionAction := &peer.TransactionAction{}
err := proto.Unmarshal(bytes, transactionAction)
if err != nil {
panic(err)
}
return transactionAction
}