Implement JSON-RPC method: eth_getBlockReceipts (#1984)
* Implement JSON-RPC method: eth_getBlockReceipts * Increment index in eth_getBlockReceipts
This commit is contained in:
parent
b6599b73f0
commit
31c288d5e5
|
@ -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).
|
||||
|
|
|
@ -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()
|
||||
|
||||
|
|
Loading…
Reference in New Issue