Ejemplo n.º 1
0
        internal async Task MineBlockAsync(Block block)
        {
            var transactions = block.Body.TransactionIds.Count > 0
                ? await _blockchainService.GetTransactionsAsync(block.TransactionIds)
                : new List <Transaction>();

            var executionReturnSets = await _transactionExecutingService.ExecuteAsync(new TransactionExecutingDto
            {
                BlockHeader  = block.Header,
                Transactions = transactions,
            }, CancellationToken.None);

            await _transactionResultManager.AddTransactionResultsAsync(
                executionReturnSets.Select(s => s.TransactionResult).ToList(), block.GetHash());

            var blockStateSet = new BlockStateSet
            {
                BlockHash    = block.GetHash(),
                PreviousHash = block.Header.PreviousBlockHash,
                BlockHeight  = block.Height
            };

            foreach (var stateChange in executionReturnSets.SelectMany(executionReturnSet => executionReturnSet.StateChanges))
            {
                blockStateSet.Changes[stateChange.Key] = stateChange.Value;
            }

            await _blockStateSetManger.SetBlockStateSetAsync(blockStateSet);
        }
Ejemplo n.º 2
0
 public async Task AddTransactionResultsAsync(IList <TransactionResult> transactionResults,
                                              BlockHeader blockHeader)
 {
     await _transactionResultManager.AddTransactionResultsAsync(transactionResults,
                                                                blockHeader.GetDisambiguatingHash());
 }
Ejemplo n.º 3
0
 public async Task AddTransactionResultsAsync(IList <TransactionResult> transactionResults,
                                              BlockHeader blockHeader)
 {
     var disambiguatingHash = blockHeader.IsMined() ? blockHeader.GetHash() : blockHeader.GetPreMiningHash();
     await _transactionResultManager.AddTransactionResultsAsync(transactionResults, disambiguatingHash);
 }