github.com/koko1123/flow-go-1@v0.29.6/engine/execution/ingestion/uploader/model.go (about) 1 package uploader 2 3 import ( 4 "fmt" 5 "io" 6 7 "github.com/fxamacker/cbor/v2" 8 9 "github.com/koko1123/flow-go-1/engine/execution" 10 "github.com/koko1123/flow-go-1/ledger" 11 "github.com/koko1123/flow-go-1/model/flow" 12 "github.com/koko1123/flow-go-1/module/mempool/entity" 13 ) 14 15 type BlockData struct { 16 Block *flow.Block 17 Collections []*entity.CompleteCollection 18 TxResults []*flow.TransactionResult 19 Events []*flow.Event 20 TrieUpdates []*ledger.TrieUpdate 21 FinalStateCommitment flow.StateCommitment 22 } 23 24 func ComputationResultToBlockData(computationResult *execution.ComputationResult) *BlockData { 25 26 txResults := make([]*flow.TransactionResult, len(computationResult.TransactionResults)) 27 for i := 0; i < len(computationResult.TransactionResults); i++ { 28 txResults[i] = &computationResult.TransactionResults[i] 29 } 30 31 events := make([]*flow.Event, 0) 32 for _, eventsList := range computationResult.Events { 33 for i := 0; i < len(eventsList); i++ { 34 events = append(events, &eventsList[i]) 35 } 36 } 37 38 return &BlockData{ 39 Block: computationResult.ExecutableBlock.Block, 40 Collections: computationResult.ExecutableBlock.Collections(), 41 TxResults: txResults, 42 Events: events, 43 TrieUpdates: computationResult.TrieUpdates, 44 FinalStateCommitment: computationResult.StateCommitments[len(computationResult.StateCommitments)-1], 45 } 46 } 47 48 func WriteComputationResultsTo(computationResult *execution.ComputationResult, writer io.Writer) error { 49 blockData := ComputationResultToBlockData(computationResult) 50 51 mode, err := cbor.CoreDetEncOptions().EncMode() 52 if err != nil { 53 return fmt.Errorf("cannot create deterministic cbor encoding mode: %w", err) 54 } 55 encoder := mode.NewEncoder(writer) 56 57 return encoder.Encode(blockData) 58 }