Ejemplo n.º 1
0
        private async Task CheckBlockExecutedSetAsync(BlockExecutedSet blockExecutedSet, int transactionCount)
        {
            blockExecutedSet.Block.Body.TransactionIds.Count.ShouldBe(transactionCount);
            blockExecutedSet.TransactionResultMap.Values.Select(t => t.Status)
            .ShouldAllBe(status => status == TransactionResultStatus.Mined);
            var blockStateSet = await _blockStateSetManger.GetBlockStateSetAsync(blockExecutedSet.GetHash());

            blockStateSet.ShouldNotBeNull();
            var transactionResults = await _transactionResultManager.GetTransactionResultsAsync(
                blockExecutedSet.TransactionIds.ToList(),
                blockExecutedSet.GetHash());

            transactionResults.Count.ShouldBe(transactionCount);
            foreach (var transactionResult in transactionResults)
            {
                blockExecutedSet.TransactionResultMap[transactionResult.TransactionId].ShouldBe(transactionResult);
            }
        }
Ejemplo n.º 2
0
        public async Task ProcessTransactionResultAfterExecutionAsync(BlockHeader blockHeader,
                                                                      List <Hash> transactionIds)
        {
            var preMiningHash = blockHeader.GetPreMiningHash();
            var blockIndex    = new BlockIndex
            {
                BlockHash   = blockHeader.GetHash(),
                BlockHeight = blockHeader.Height
            };

            if (transactionIds.Count == 0)
            {
                // This will only happen during test environment
                return;
            }

            var firstTransaction = transactionIds.First();
            var withBlockHash    = await _transactionResultManager.HasTransactionResultAsync(
                firstTransaction, blockHeader.GetHash());

            var withPreMiningHash = await _transactionResultManager.HasTransactionResultAsync(
                firstTransaction, preMiningHash);

            if (!withBlockHash)
            {
                // TransactionResult is not saved with real BlockHash
                // Save results with real (post mining) Hash, so that it can be queried with TransactionBlockIndex
                var result = await _transactionResultManager.GetTransactionResultsAsync(transactionIds, preMiningHash);

                await _transactionResultManager.AddTransactionResultsAsync(result, blockIndex.BlockHash);
            }

            // Add TransactionBlockIndex
            if (withPreMiningHash)
            {
                await _transactionResultManager.RemoveTransactionResultsAsync(transactionIds, preMiningHash);
            }

            await _transactionBlockIndexService.AddBlockIndexAsync(transactionIds, blockIndex);
        }