private Task <Block> FillBlockAfterExecutionAsync(BlockHeader header,
                                                          IEnumerable <Transaction> transactions, ExecutionReturnSetCollection executionReturnSetCollection, BlockStateSet blockStateSet)
        {
            Logger.LogTrace("Start block field filling after execution.");
            var bloom = new Bloom();

            foreach (var returnSet in executionReturnSetCollection.Executed)
            {
                bloom.Combine(new[] { new Bloom(returnSet.Bloom.ToByteArray()) });
            }

            var allExecutedTransactionIds = transactions.Select(x => x.GetHash()).ToList();
            var orderedReturnSets         = executionReturnSetCollection.GetExecutionReturnSetList()
                                            .OrderBy(d => allExecutedTransactionIds.IndexOf(d.TransactionId)).ToList();

            var block = new Block
            {
                Header = new BlockHeader(header)
                {
                    Bloom = ByteString.CopyFrom(bloom.Data),
                    MerkleTreeRootOfWorldState        = CalculateWorldStateMerkleTreeRoot(blockStateSet),
                    MerkleTreeRootOfTransactionStatus = CalculateTransactionStatusMerkleTreeRoot(orderedReturnSets),
                    MerkleTreeRootOfTransactions      = CalculateTransactionMerkleTreeRoot(allExecutedTransactionIds)
                },
                Body = new BlockBody
                {
                    TransactionIds = { allExecutedTransactionIds }
                }
            };

            Logger.LogTrace("Finish block field filling after execution.");
            return(Task.FromResult(block));
        }
        private async Task <List <TransactionResult> > SetTransactionResultsAsync(ExecutionReturnSetCollection executionReturnSetCollection, BlockHeader blockHeader)
        {
            //save all transaction results
            var results = executionReturnSetCollection.GetExecutionReturnSetList()
                          .Select(p =>
            {
                p.TransactionResult.BlockHash   = blockHeader.GetHash();
                p.TransactionResult.BlockNumber = blockHeader.Height;
                return(p.TransactionResult);
            }).ToList();

            await _transactionResultService.AddTransactionResultsAsync(results, blockHeader);

            return(results);
        }