Ejemplo n.º 1
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);
        }