public ResultWrapper <TransactionWithProof> proof_getTransactionByHash(Keccak txHash, bool includeHeader) { Keccak blockHash = _receiptFinder.FindBlockHash(txHash); if (blockHash == null) { return(ResultWrapper <TransactionWithProof> .Fail($"{txHash} receipt (transaction) could not be found", ErrorCodes.ResourceNotFound)); } SearchResult <Block> searchResult = _blockFinder.SearchForBlock(new BlockParameter(blockHash)); if (searchResult.IsError) { return(ResultWrapper <TransactionWithProof> .Fail(searchResult)); } Block block = searchResult.Object; TxReceipt receipt = _receiptFinder.Get(block).ForTransaction(txHash); Transaction[] txs = block.Transactions; Transaction transaction = txs[receipt.Index]; TransactionWithProof txWithProof = new TransactionWithProof(); txWithProof.Transaction = new TransactionForRpc(block.Hash, block.Number, receipt.Index, transaction); txWithProof.TxProof = BuildTxProofs(txs, _specProvider.GetSpec(block.Number), receipt.Index); if (includeHeader) { txWithProof.BlockHeader = _headerDecoder.Encode(block.Header).Bytes; } return(ResultWrapper <TransactionWithProof> .Success(txWithProof)); }
public static SearchResult <Keccak> SearchForReceiptBlockHash(this IReceiptFinder receiptFinder, Keccak txHash) { Keccak blockHash = receiptFinder.FindBlockHash(txHash); return(blockHash == null ? new SearchResult <Keccak>($"{txHash} receipt could not be found", ErrorCodes.ResourceNotFound) : new SearchResult <Keccak>(blockHash)); }
public (TxReceipt Receipt, UInt256?EffectiveGasPrice) GetReceiptAndEffectiveGasPrice(Keccak txHash) { Keccak blockHash = _receiptFinder.FindBlockHash(txHash); if (blockHash != null) { Block block = _blockTree.FindBlock(blockHash, BlockTreeLookupOptions.TotalDifficultyNotNeeded); TxReceipt txReceipt = _receiptFinder.Get(block).ForTransaction(txHash); Transaction tx = block?.Transactions[txReceipt.Index]; bool is1559Enabled = _specProvider.GetSpec(block.Number).IsEip1559Enabled; UInt256 effectiveGasPrice = tx.CalculateEffectiveGasPrice(is1559Enabled, block.Header.BaseFeePerGas); return(txReceipt, effectiveGasPrice); } return(null, null); }
public (TxReceipt Receipt, Transaction Transaction) GetTransaction(Keccak txHash) { Keccak blockHash = _receiptFinder.FindBlockHash(txHash); if (blockHash != null) { Block block = _blockTree.FindBlock(blockHash, BlockTreeLookupOptions.TotalDifficultyNotNeeded); TxReceipt txReceipt = _receiptFinder.Get(block).ForTransaction(txHash); return(txReceipt, block?.Transactions[txReceipt.Index]); } if (_txPool.TryGetPendingTransaction(txHash, out var transaction)) { return(null, transaction); } return(null, null); }
public (TxReceipt Receipt, UInt256?EffectiveGasPrice, int LogIndexStart) GetReceiptAndEffectiveGasPrice(Keccak txHash) { Keccak blockHash = _receiptFinder.FindBlockHash(txHash); if (blockHash != null) { Block?block = _processingEnv.BlockTree.FindBlock(blockHash, BlockTreeLookupOptions.RequireCanonical); if (block is not null) { TxReceipt[] txReceipts = _receiptFinder.Get(block); TxReceipt txReceipt = txReceipts.ForTransaction(txHash); int logIndexStart = txReceipts.GetBlockLogFirstIndex(txReceipt.Index); Transaction tx = block.Transactions[txReceipt.Index]; bool is1559Enabled = _specProvider.GetSpec(block.Number).IsEip1559Enabled; UInt256 effectiveGasPrice = tx.CalculateEffectiveGasPrice(is1559Enabled, block.Header.BaseFeePerGas); return(txReceipt, effectiveGasPrice, logIndexStart); } } return(null, null, 0); }
public void Get_receipt_when_block_has_few_receipts(bool withHeader, string expectedResult) { IReceiptFinder _receiptFinder = Substitute.For <IReceiptFinder>(); LogEntry[] logEntries = new[] { Build.A.LogEntry.TestObject, Build.A.LogEntry.TestObject }; TxReceipt receipt1 = new TxReceipt() { Bloom = new Bloom(logEntries), Index = 0, Recipient = TestItem.AddressA, Sender = TestItem.AddressB, BlockHash = _blockTree.FindBlock(1).Hash, BlockNumber = 1, ContractAddress = TestItem.AddressC, GasUsed = 1000, TxHash = _blockTree.FindBlock(1).Transactions[0].Hash, StatusCode = 0, GasUsedTotal = 2000, Logs = logEntries }; TxReceipt receipt2 = new TxReceipt() { Bloom = new Bloom(logEntries), Index = 1, Recipient = TestItem.AddressC, Sender = TestItem.AddressD, BlockHash = _blockTree.FindBlock(1).Hash, BlockNumber = 1, ContractAddress = TestItem.AddressC, GasUsed = 1000, TxHash = _blockTree.FindBlock(1).Transactions[1].Hash, StatusCode = 0, GasUsedTotal = 2000, Logs = logEntries }; Block block = _blockTree.FindBlock(1); Keccak txHash = _blockTree.FindBlock(1).Transactions[1].Hash; TxReceipt[] receipts = { receipt1, receipt2 }; _receiptFinder.Get(Arg.Any <Block>()).Returns(receipts); _receiptFinder.Get(Arg.Any <Keccak>()).Returns(receipts); _receiptFinder.FindBlockHash(Arg.Any <Keccak>()).Returns(_blockTree.FindBlock(1).Hash); ProofModuleFactory moduleFactory = new ProofModuleFactory( _dbProvider, _blockTree, new TrieStore(_dbProvider.StateDb, LimboLogs.Instance).AsReadOnly(), new CompositeBlockPreprocessorStep(new RecoverSignatures(new EthereumEcdsa(ChainId.Mainnet, LimboLogs.Instance), NullTxPool.Instance, _specProvider, LimboLogs.Instance)), _receiptFinder, _specProvider, LimboLogs.Instance); _proofRpcModule = moduleFactory.Create(); ReceiptWithProof receiptWithProof = _proofRpcModule.proof_getTransactionReceipt(txHash, withHeader).Data; if (withHeader) { Assert.NotNull(receiptWithProof.BlockHeader); } else { Assert.Null(receiptWithProof.BlockHeader); } string response = RpcTest.TestSerializedRequest(_proofRpcModule, "proof_getTransactionReceipt", $"{txHash}", $"{withHeader}"); Assert.AreEqual(expectedResult, response); }
public Keccak FindBlockHash(Keccak txHash) => _innerFinder.FindBlockHash(txHash);