@@ -172,14 +172,28 @@ func BlockToMessage(b flow.Block) (*entities.Block, error) {
172
172
return nil , err
173
173
}
174
174
175
+ execReceipts , err := ExecutionReceiptMetaListToMessage (b .ExecutionReceiptMetaList )
176
+ if err != nil {
177
+ return nil , fmt .Errorf ("error converting execution receipts: %w" , err )
178
+ }
179
+
180
+ execResults , err := ExecutionResultsToMessage (b .ExecutionResultsList )
181
+ if err != nil {
182
+ return nil , fmt .Errorf ("error converting execution results: %w" , err )
183
+ }
184
+
175
185
return & entities.Block {
176
- Id : b .BlockHeader .ID .Bytes (),
177
- ParentId : b .BlockHeader .ParentID .Bytes (),
178
- Height : b .BlockHeader .Height ,
179
- Timestamp : t ,
180
- CollectionGuarantees : CollectionGuaranteesToMessages (b .BlockPayload .CollectionGuarantees ),
181
- BlockSeals : BlockSealsToMessages (b .BlockPayload .Seals ),
182
- BlockHeader : header ,
186
+ Id : b .BlockHeader .ID .Bytes (),
187
+ ParentId : b .BlockHeader .ParentID .Bytes (),
188
+ Height : b .BlockHeader .Height ,
189
+ Timestamp : t ,
190
+ CollectionGuarantees : CollectionGuaranteesToMessages (b .BlockPayload .CollectionGuarantees ),
191
+ BlockSeals : BlockSealsToMessages (b .BlockPayload .Seals ),
192
+ Signatures : b .Signatures ,
193
+ ExecutionReceiptMetaList : execReceipts ,
194
+ ExecutionResultList : execResults ,
195
+ BlockHeader : header ,
196
+ ProtocolStateId : b .ProtocolStateID .Bytes (),
183
197
}, nil
184
198
}
185
199
@@ -193,7 +207,7 @@ func MessageToBlock(m *entities.Block) (flow.Block, error) {
193
207
194
208
tc , err := MessageToTimeoutCertificate (m .BlockHeader .GetLastViewTc ())
195
209
if err != nil {
196
- return flow.Block {}, err
210
+ return flow.Block {}, fmt . Errorf ( "error converting timeout certificate: %w" , err )
197
211
}
198
212
199
213
header := & flow.BlockHeader {
@@ -214,17 +228,31 @@ func MessageToBlock(m *entities.Block) (flow.Block, error) {
214
228
215
229
guarantees , err := MessagesToCollectionGuarantees (m .GetCollectionGuarantees ())
216
230
if err != nil {
217
- return flow.Block {}, err
231
+ return flow.Block {}, fmt . Errorf ( "error converting collection guarantees: %w" , err )
218
232
}
219
233
220
234
seals , err := MessagesToBlockSeals (m .GetBlockSeals ())
221
235
if err != nil {
222
- return flow.Block {}, err
236
+ return flow.Block {}, fmt .Errorf ("error converting block seals: %w" , err )
237
+ }
238
+
239
+ executionReceiptsMeta , err := MessageToExecutionReceiptMetaList (m .GetExecutionReceiptMetaList ())
240
+ if err != nil {
241
+ return flow.Block {}, fmt .Errorf ("error converting execution receipt meta list: %w" , err )
242
+ }
243
+
244
+ executionResults , err := MessageToExecutionResults (m .GetExecutionResultList ())
245
+ if err != nil {
246
+ return flow.Block {}, fmt .Errorf ("error converting execution results: %w" , err )
223
247
}
224
248
225
249
payload := & flow.BlockPayload {
226
- CollectionGuarantees : guarantees ,
227
- Seals : seals ,
250
+ CollectionGuarantees : guarantees ,
251
+ Seals : seals ,
252
+ Signatures : m .GetSignatures (),
253
+ ExecutionReceiptMetaList : executionReceiptsMeta ,
254
+ ExecutionResultsList : executionResults ,
255
+ ProtocolStateID : flow .HashToID (m .GetProtocolStateId ()),
228
256
}
229
257
230
258
return flow.Block {
@@ -233,6 +261,54 @@ func MessageToBlock(m *entities.Block) (flow.Block, error) {
233
261
}, nil
234
262
}
235
263
264
+ func MessageToExecutionReceiptMeta (m * entities.ExecutionReceiptMeta ) (* flow.ExecutionReceiptMeta , error ) {
265
+ if m == nil {
266
+ return nil , ErrEmptyMessage
267
+ }
268
+
269
+ return & flow.ExecutionReceiptMeta {
270
+ ExecutorID : flow .HashToID (m .GetExecutorId ()),
271
+ ResultID : flow .HashToID (m .GetResultId ()),
272
+ Spocks : m .GetSpocks (),
273
+ ExecutorSignature : m .GetExecutorSignature (),
274
+ }, nil
275
+ }
276
+
277
+ func ExecutionReceiptMetaToMessage (receipt flow.ExecutionReceiptMeta ) (* entities.ExecutionReceiptMeta , error ) {
278
+ return & entities.ExecutionReceiptMeta {
279
+ ExecutorId : receipt .ExecutorID .Bytes (),
280
+ ResultId : receipt .ResultID .Bytes (),
281
+ Spocks : receipt .Spocks ,
282
+ ExecutorSignature : receipt .ExecutorSignature ,
283
+ }, nil
284
+ }
285
+
286
+ func MessageToExecutionReceiptMetaList (m []* entities.ExecutionReceiptMeta ) ([]* flow.ExecutionReceiptMeta , error ) {
287
+ results := make ([]* flow.ExecutionReceiptMeta , len (m ))
288
+
289
+ for i , entity := range m {
290
+ executionReceiptMeta , err := MessageToExecutionReceiptMeta (entity )
291
+ if err != nil {
292
+ return nil , err
293
+ }
294
+ results [i ] = executionReceiptMeta
295
+ }
296
+
297
+ return results , nil
298
+ }
299
+
300
+ func ExecutionReceiptMetaListToMessage (receipts []* flow.ExecutionReceiptMeta ) ([]* entities.ExecutionReceiptMeta , error ) {
301
+ results := make ([]* entities.ExecutionReceiptMeta , len (receipts ))
302
+ for i , receipt := range receipts {
303
+ executionReceiptMeta , err := ExecutionReceiptMetaToMessage (* receipt )
304
+ if err != nil {
305
+ return nil , err
306
+ }
307
+ results [i ] = executionReceiptMeta
308
+ }
309
+ return results , nil
310
+ }
311
+
236
312
func BlockHeaderToMessage (b flow.BlockHeader ) (* entities.BlockHeader , error ) {
237
313
t := timestamppb .New (b .Timestamp )
238
314
tc , err := TimeoutCertificateToMessage (b .LastViewTimeoutCertificate )
@@ -896,6 +972,65 @@ func MessageToExecutionResult(execResult *entities.ExecutionResult) (*flow.Execu
896
972
}, nil
897
973
}
898
974
975
+ func ExecutionResultToMessage (result flow.ExecutionResult ) (* entities.ExecutionResult , error ) {
976
+ chunks := make ([]* entities.Chunk , len (result .Chunks ))
977
+ for i , chunk := range result .Chunks {
978
+ chunks [i ] = & entities.Chunk {
979
+ CollectionIndex : uint32 (chunk .CollectionIndex ),
980
+ StartState : IdentifierToMessage (flow .Identifier (chunk .StartState )),
981
+ EventCollection : chunk .EventCollection ,
982
+ BlockId : chunk .BlockID .Bytes (),
983
+ TotalComputationUsed : chunk .TotalComputationUsed ,
984
+ NumberOfTransactions : uint32 (chunk .NumberOfTransactions ),
985
+ Index : chunk .Index ,
986
+ EndState : IdentifierToMessage (flow .Identifier (chunk .EndState )),
987
+ }
988
+ }
989
+
990
+ serviceEvents := make ([]* entities.ServiceEvent , len (result .ServiceEvents ))
991
+ for i , event := range result .ServiceEvents {
992
+ serviceEvents [i ] = & entities.ServiceEvent {
993
+ Type : event .Type ,
994
+ Payload : event .Payload ,
995
+ }
996
+ }
997
+
998
+ return & entities.ExecutionResult {
999
+ PreviousResultId : result .PreviousResultID .Bytes (),
1000
+ BlockId : result .BlockID .Bytes (),
1001
+ Chunks : chunks ,
1002
+ ServiceEvents : serviceEvents ,
1003
+ }, nil
1004
+ }
1005
+
1006
+ func MessageToExecutionResults (m []* entities.ExecutionResult ) ([]* flow.ExecutionResult , error ) {
1007
+ results := make ([]* flow.ExecutionResult , len (m ))
1008
+
1009
+ for i , result := range m {
1010
+ res , err := MessageToExecutionResult (result )
1011
+ if err != nil {
1012
+ return nil , err
1013
+ }
1014
+ results [i ] = res
1015
+ }
1016
+
1017
+ return results , nil
1018
+ }
1019
+
1020
+ func ExecutionResultsToMessage (execResults []* flow.ExecutionResult ) ([]* entities.ExecutionResult , error ) {
1021
+ results := make ([]* entities.ExecutionResult , len (execResults ))
1022
+
1023
+ for i , result := range execResults {
1024
+ res , err := ExecutionResultToMessage (* result )
1025
+ if err != nil {
1026
+ return nil , err
1027
+ }
1028
+ results [i ] = res
1029
+ }
1030
+
1031
+ return results , nil
1032
+ }
1033
+
899
1034
func BlockExecutionDataToMessage (
900
1035
execData * flow.ExecutionData ,
901
1036
) (* entities.BlockExecutionData , error ) {
0 commit comments