From 31c288d5e5374b979f0e2c0eb1f6c34472f1b293 Mon Sep 17 00:00:00 2001 From: andri lim Date: Wed, 24 Jan 2024 18:04:59 +0700 Subject: [PATCH] Implement JSON-RPC method: eth_getBlockReceipts (#1984) * Implement JSON-RPC method: eth_getBlockReceipts * Increment index in eth_getBlockReceipts --- nimbus/rpc/p2p.nim | 21 +++++++++++++++++++++ tests/test_rpc.nim | 9 +++++++++ 2 files changed, 30 insertions(+) diff --git a/nimbus/rpc/p2p.nim b/nimbus/rpc/p2p.nim index 6462f6dfe..7264aa54a 100644 --- a/nimbus/rpc/p2p.nim +++ b/nimbus/rpc/p2p.nim @@ -555,6 +555,27 @@ proc setupEthRpc*( getProof(accDB, address, slots) + server.rpc("eth_getBlockReceipts") do(quantityTag: BlockTag) -> Option[seq[ReceiptObject]]: + try: + let header = chainDB.headerFromTag(quantityTag) + var + prevGasUsed = GasInt(0) + recs: seq[ReceiptObject] + txs: seq[Transaction] + index = 0 + + for tx in chainDB.getBlockTransactions(header): + txs.add tx + + for receipt in chainDB.getReceipts(header.receiptRoot): + let gasUsed = receipt.cumulativeGasUsed - prevGasUsed + prevGasUsed = receipt.cumulativeGasUsed + recs.add populateReceipt(receipt, gasUsed, txs[index], index, header) + inc index + + return some(recs) + except CatchableError: + return none(seq[ReceiptObject]) #[ server.rpc("eth_newFilter") do(filterOptions: FilterOptions) -> int: ## Creates a filter object, based on filter options, to notify when the state changes (logs). diff --git a/tests/test_rpc.nim b/tests/test_rpc.nim index a9f2dd06b..ca2593cc4 100644 --- a/tests/test_rpc.nim +++ b/tests/test_rpc.nim @@ -733,6 +733,15 @@ proc rpcMain*() = storageProof.len() == 1 verifySlotProof(proofResponse.storageHash, storageProof[0]).isValid() + test "eth_getBlockReceipts": + let recs = await client.eth_getBlockReceipts(blockId("latest")) + check recs.isSome + if recs.isSome: + let receipts = recs.get + check receipts.len == 2 + check receipts[0].transactionIndex == 0.Quantity + check receipts[1].transactionIndex == 1.Quantity + rpcServer.stop() rpcServer.close()