Implement JSON-RPC method: eth_getBlockReceipts (#1984)

* Implement JSON-RPC method: eth_getBlockReceipts

* Increment index in eth_getBlockReceipts
This commit is contained in:
andri lim 2024-01-24 18:04:59 +07:00 committed by GitHub
parent b6599b73f0
commit 31c288d5e5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 30 additions and 0 deletions

View File

@ -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).

View File

@ -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()