public TxReceipt[] Get(Block block) { var receipts = _receiptStorage.Get(block); if (_receiptsRecovery.TryRecover(block, receipts) == ReceiptsRecoveryResult.Success) { _receiptStorage.Insert(block, receipts); } return(receipts); }
public GethLikeTxTrace Trace(Keccak txHash) { TransactionReceipt transactionReceipt = _receiptStorage.Get(txHash); Block block = _blockTree.FindBlock(transactionReceipt.BlockNumber); if (block == null) { throw new InvalidOperationException("Only historical blocks"); } return(Trace(block, txHash)); }
public (TransactionReceipt Receipt, Transaction Transaction) GetTransaction(Keccak transactionHash) { TransactionReceipt receipt = _receiptStorage.Get(transactionHash); if (receipt.BlockHash == null) { return(null, null); } Block block = _blockTree.FindBlock(receipt.BlockHash, true); return(receipt, block.Transactions[receipt.Index]); }
private int GetTxReceiptsLength(Block block, bool useIterator) { if (useIterator) { int txReceiptsLength = 0; if (_receiptStorage.TryGetReceiptsIterator(block.Number, block.Hash, out var iterator)) { try { while (iterator.TryGetNext(out _)) { txReceiptsLength++; } } finally { iterator.Dispose(); } } return(txReceiptsLength); } else { return(_receiptStorage.Get(block)?.Where(r => r != null).Count() ?? 0); } }
private void OnNewHeadBlock(object?sender, BlockEventArgs e) { if (e.Block is not null) { TryPublishReceiptsInBackground(e.Block.Header, () => _receiptStorage.Get(e.Block), nameof(_blockTree.NewHeadBlock)); } }
private void ResetMigrationIndexIfNeeded() { ReceiptsRecovery recovery = new ReceiptsRecovery(_api.EthereumEcdsa, _api.SpecProvider); if (_receiptStorage.MigratedBlockNumber != long.MaxValue) { long blockNumber = _blockTree.Head?.Number ?? 0; while (blockNumber > 0) { ChainLevelInfo?level = _chainLevelInfoRepository.LoadLevel(blockNumber); BlockInfo? firstBlockInfo = level?.BlockInfos.FirstOrDefault(); if (firstBlockInfo != null) { TxReceipt[] receipts = _receiptStorage.Get(firstBlockInfo.BlockHash); if (receipts.Length > 0) { if (recovery.NeedRecover(receipts)) { _receiptStorage.MigratedBlockNumber = long.MaxValue; } break; } } blockNumber--; } } }
private void TestAddAndGetReceipt(IReceiptStorage storage) { var transaction = GetSignedTransaction(); var receipt = GetReceipt(transaction); storage.Add(receipt); var fetchedReceipt = storage.Get(transaction.Hash); receipt.PostTransactionState.Should().Be(fetchedReceipt.PostTransactionState); }
public void get_transaction_returns_receipt_and_transaction_when_found() { int index = 5; var receipt = Build.A.Receipt .WithBlockHash(TestItem.KeccakB) .WithTransactionHash(TestItem.KeccakA) .WithIndex(index) .TestObject; IEnumerable <Transaction> transactions = Enumerable.Range(0, 10) .Select(i => Build.A.Transaction.WithNonce((UInt256)i).TestObject); var block = Build.A.Block .WithTransactions(transactions.ToArray()) .TestObject; _blockTree.FindBlock(TestItem.KeccakB, Arg.Any <BlockTreeLookupOptions>()).Returns(block); _receiptStorage.FindBlockHash(TestItem.KeccakA).Returns(TestItem.KeccakB); _receiptStorage.Get(block).Returns(new[] { receipt }); _blockchainBridge.GetTransaction(TestItem.KeccakA).Should() .BeEquivalentTo((receipt, Build.A.Transaction.WithNonce((UInt256)index).TestObject)); }
private void TriggerReceiptInsertedEvent(Block newBlock, Block?previousBlock) { try { if (previousBlock is not null) { TxReceipt[] removedReceipts = _receiptStorage.Get(previousBlock); ReceiptsInserted?.Invoke(this, new ReceiptsEventArgs(previousBlock.Header, removedReceipts, true)); } TxReceipt[] insertedReceipts = _receiptStorage.Get(newBlock); ReceiptsInserted?.Invoke(this, new ReceiptsEventArgs(newBlock.Header, insertedReceipts)); } catch (Exception exception) { if (_logger.IsError) { _logger.Error($"Couldn't correctly trigger receipt event. New block {newBlock.ToString(Block.Format.FullHashAndNumber)}, Prev block {previousBlock?.ToString(Block.Format.FullHashAndNumber)}.", exception); } } }
private void RollbackReceipts(Block?previousBlock) { if (previousBlock != null) { TxReceipt[] txReceipts = _receiptStorage.Get(previousBlock); foreach (var txReceipt in txReceipts) { txReceipt.Removed = true; } _receiptStorage.Insert(previousBlock, txReceipts); } }
private void TestAddAndGetReceiptEip658(IReceiptStorage storage) { var transaction = GetSignedTransaction(); var block = GetBlock(transaction); var receipt = GetReceipt(transaction, block); storage.Insert(block, receipt); var blockHash = storage.FindBlockHash(transaction.Hash); blockHash.Should().Be(block.Hash); var fetchedReceipt = storage.Get(block).ForTransaction(transaction.Hash); receipt.StatusCode.Should().Be(fetchedReceipt.StatusCode); receipt.PostTransactionState.Should().Be(fetchedReceipt.PostTransactionState); receipt.TxHash.Should().Be(transaction.Hash); }
private List <(long GasUsed, UInt256 PremiumPerGas)>?GetRewardsInBlock(Block block) { TxReceipt[]? receipts = _receiptStorage.Get(block); Transaction[] txs = block.Transactions; List <(long GasUsed, UInt256 PremiumPerGas)> valueTuples = new(txs.Length); for (int i = 0; i < txs.Length; i++) { Transaction tx = txs[i]; tx.TryCalculatePremiumPerGas(block.BaseFeePerGas, out UInt256 premiumPerGas); valueTuples.Add((receipts[i].GasUsed, premiumPerGas)); } valueTuples.Sort((i1, i2) => i1.PremiumPerGas.CompareTo(i2.PremiumPerGas)); return(valueTuples); }
private void TestAddAndGetReceipt(IReceiptStorage storage, bool recoverSender) { var transaction = GetSignedTransaction(); transaction.SenderAddress = null; var block = GetBlock(transaction); var receipt = GetReceipt(transaction, block); storage.Insert(block, receipt); var blockHash = storage.FindBlockHash(transaction.Hash); blockHash.Should().Be(block.Hash); var fetchedReceipt = storage.Get(block).ForTransaction(transaction.Hash); receipt.StatusCode.Should().Be(fetchedReceipt.StatusCode); receipt.PostTransactionState.Should().Be(fetchedReceipt.PostTransactionState); receipt.TxHash.Should().Be(transaction.Hash); if (recoverSender) { receipt.Sender.Should().BeEquivalentTo(TestItem.AddressA); } }
public TransactionReceipt[][] GetReceipts(Keccak[] blockHashes) { var transactionReceipts = new TransactionReceipt[blockHashes.Length][]; for (int blockIndex = 0; blockIndex < blockHashes.Length; blockIndex++) { Block block = Find(blockHashes[blockIndex]); var blockTransactionReceipts = new TransactionReceipt[block?.Transactions.Length ?? 0]; for (int receiptIndex = 0; receiptIndex < (block?.Transactions.Length ?? 0); receiptIndex++) { if (block == null) { continue; } blockTransactionReceipts[receiptIndex] = _receiptStorage.Get(block.Transactions[receiptIndex].Hash); } transactionReceipts[blockIndex] = blockTransactionReceipts; } return(transactionReceipts); }
public TxReceipt[] Get(Block block) => _inStorage.Get(block);