@@ -59,7 +59,7 @@ func GetPayloads(txActions *peer.TransactionAction) (*peer.ChaincodeActionPayloa
59
59
return ccPayload , respPayload , nil
60
60
}
61
61
62
- // GetEndorserTxFromBlock gets Transaction2 from Block.Data.Data
62
+ // GetEndorserTxFromBlock gets Transaction from Block.Data.Data
63
63
func GetEnvelopeFromBlock (data []byte ) (* common.Envelope , error ) {
64
64
//Block always begins with an envelope
65
65
var err error
@@ -71,42 +71,10 @@ func GetEnvelopeFromBlock(data []byte) (*common.Envelope, error) {
71
71
return env , nil
72
72
}
73
73
74
- // CreateSignedTx assembles an Envelope message from proposal, endorsements and a signer.
74
+ // assemble an Envelope message from proposal, endorsements and a signer.
75
75
// This function should be called by a client when it has collected enough endorsements
76
76
// for a proposal to create a transaction and submit it to peers for ordering
77
77
func CreateSignedTx (proposal * peer.Proposal , signer msp.SigningIdentity , resps ... * peer.ProposalResponse ) (* common.Envelope , error ) {
78
- // the original header
79
- hdr , err := GetHeader (proposal .Header )
80
- if err != nil {
81
- return nil , fmt .Errorf ("Could not unmarshal the proposal header" )
82
- }
83
- // check that the signer is the same that is referenced in the header
84
- // TODO: maybe worth removing?
85
- signerBytes , err := signer .Serialize ()
86
- if err != nil {
87
- return nil , err
88
- }
89
-
90
- if bytes .Compare (signerBytes , hdr .SignatureHeader .Creator ) != 0 {
91
- return nil , fmt .Errorf ("The signer needs to be the same as the one referenced in the header" )
92
- }
93
-
94
- // create the payload
95
- txEnvelope , err := ConstructUnsignedTxEnvelope (proposal , resps ... )
96
- if err != nil {
97
- return nil , err
98
- }
99
- // sign the payload
100
- sig , err := signer .Sign (txEnvelope .Payload )
101
- if err != nil {
102
- return nil , err
103
- }
104
- txEnvelope .Signature = sig
105
- return txEnvelope , nil
106
- }
107
-
108
- // ConstructUnsignedTxEnvelope constructs payload for the transaction from proposal and endorsements.
109
- func ConstructUnsignedTxEnvelope (proposal * peer.Proposal , resps ... * peer.ProposalResponse ) (* common.Envelope , error ) {
110
78
if len (resps ) == 0 {
111
79
return nil , fmt .Errorf ("At least one proposal response is necessary" )
112
80
}
@@ -123,6 +91,17 @@ func ConstructUnsignedTxEnvelope(proposal *peer.Proposal, resps ...*peer.Proposa
123
91
return nil , fmt .Errorf ("Could not unmarshal the proposal payload" )
124
92
}
125
93
94
+ // check that the signer is the same that is referenced in the header
95
+ // TODO: maybe worth removing?
96
+ signerBytes , err := signer .Serialize ()
97
+ if err != nil {
98
+ return nil , err
99
+ }
100
+
101
+ if bytes .Compare (signerBytes , hdr .SignatureHeader .Creator ) != 0 {
102
+ return nil , fmt .Errorf ("The signer needs to be the same as the one referenced in the header" )
103
+ }
104
+
126
105
// get header extensions so we have the visibility field
127
106
hdrExt , err := GetChaincodeHeaderExtension (hdr )
128
107
if err != nil {
@@ -184,40 +163,25 @@ func ConstructUnsignedTxEnvelope(proposal *peer.Proposal, resps ...*peer.Proposa
184
163
if err != nil {
185
164
return nil , err
186
165
}
166
+
167
+ // create the payload
187
168
payl := & common.Payload {Header : hdr , Data : txBytes }
188
169
paylBytes , err := GetBytesPayload (payl )
189
170
if err != nil {
190
171
return nil , err
191
172
}
192
173
193
- // here's the envelope
194
- return & common.Envelope {Payload : paylBytes , Signature : nil }, nil
195
- }
196
-
197
- // CreateProposalResponse creates the proposal response and endorses the payload
198
- func CreateProposalResponse (hdr []byte , payl []byte , results []byte , events []byte , visibility []byte , signingEndorser msp.SigningIdentity ) (* peer.ProposalResponse , error ) {
199
- resp , err := ConstructUnsignedProposalResponse (hdr , payl , results , events , visibility )
174
+ // sign the payload
175
+ sig , err := signer .Sign (paylBytes )
200
176
if err != nil {
201
177
return nil , err
202
178
}
203
- // serialize the signing identity
204
- endorser , err := signingEndorser .Serialize ()
205
- if err != nil {
206
- return nil , fmt .Errorf ("Could not serialize the signing identity for %s, err %s" , signingEndorser .Identifier (), err )
207
- }
208
179
209
- // sign the concatenation of the proposal response and the serialized endorser identity with this endorser's key
210
- signature , err := signingEndorser .Sign (append (resp .Payload , endorser ... ))
211
- if err != nil {
212
- return nil , fmt .Errorf ("Could not sign the proposal response payload, err %s" , err )
213
- }
214
- resp .Endorsement .Endorser = endorser
215
- resp .Endorsement .Signature = signature
216
- return resp , nil
180
+ // here's the envelope
181
+ return & common.Envelope {Payload : paylBytes , Signature : sig }, nil
217
182
}
218
183
219
- // ConstructUnsignedProposalResponse constructs the proposal response structure only
220
- func ConstructUnsignedProposalResponse (hdr []byte , payl []byte , results []byte , events []byte , visibility []byte ) (* peer.ProposalResponse , error ) {
184
+ func CreateProposalResponse (hdr []byte , payl []byte , results []byte , events []byte , visibility []byte , signingEndorser msp.SigningIdentity ) (* peer.ProposalResponse , error ) {
221
185
// obtain the proposal hash given proposal header, payload and the requested visibility
222
186
pHashBytes , err := GetProposalHash1 (hdr , payl , visibility )
223
187
if err != nil {
@@ -229,10 +193,23 @@ func ConstructUnsignedProposalResponse(hdr []byte, payl []byte, results []byte,
229
193
if err != nil {
230
194
return nil , errors .New ("Failure while unmarshalling the ProposalResponsePayload" )
231
195
}
196
+
197
+ // serialize the signing identity
198
+ endorser , err := signingEndorser .Serialize ()
199
+ if err != nil {
200
+ return nil , fmt .Errorf ("Could not serialize the signing identity for %s, err %s" , signingEndorser .Identifier (), err )
201
+ }
202
+
203
+ // sign the concatenation of the proposal response and the serialized endorser identity with this endorser's key
204
+ signature , err := signingEndorser .Sign (append (prpBytes , endorser ... ))
205
+ if err != nil {
206
+ return nil , fmt .Errorf ("Could not sign the proposal response payload, err %s" , err )
207
+ }
208
+
232
209
resp := & peer.ProposalResponse {
233
210
// Timestamp: TODO!
234
211
Version : 1 , // TODO: pick right version number
235
- Endorsement : & peer.Endorsement {Signature : nil , Endorser : nil },
212
+ Endorsement : & peer.Endorsement {Signature : signature , Endorser : endorser },
236
213
Payload : prpBytes ,
237
214
Response : & peer.Response {Status : 200 , Message : "OK" }}
238
215
0 commit comments