From 0ea08655a051411dde341297e6da7f6f86c79a8d Mon Sep 17 00:00:00 2001 From: Kim De Mey Date: Mon, 27 Mar 2023 21:10:43 +0200 Subject: [PATCH] Fix the ReceiptObject JSON-RPC type (#1522) * Fix the ReceiptObject JSON-RPC type * Fix also the json marshalling for the server side * Fix populateReceipt by adding receipt type --- nimbus/rpc/rpc_types.nim | 3 ++- nimbus/rpc/rpc_utils.nim | 26 +++++++++++++++++++++++++- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/nimbus/rpc/rpc_types.nim b/nimbus/rpc/rpc_types.nim index 7604d7c47..d1d84d95c 100644 --- a/nimbus/rpc/rpc_types.nim +++ b/nimbus/rpc/rpc_types.nim @@ -116,8 +116,9 @@ type cumulativeGasUsed*: HexQuantityStr # the total amount of gas used when this transaction was executed in the block. gasUsed*: HexQuantityStr # the amount of gas used by this specific transaction alone. contractAddress*: Option[EthAddress] # the contract address created, if the transaction was a contract creation, otherwise null. - logs*: seq[Log] # list of log objects which this transaction generated. + logs*: seq[FilterLog] # list of log objects which this transaction generated. logsBloom*: FixedBytes[256] # bloom filter for light clients to quickly retrieve related logs. + `type`*: HexQuantityStr root*: Option[Hash256] # post-transaction stateroot (pre Byzantium). status*: Option[HexQuantityStr] # 1 = success, 0 = failure. effectiveGasPrice*: HexQuantityStr # The actual value per gas deducted from the senders account. diff --git a/nimbus/rpc/rpc_utils.nim b/nimbus/rpc/rpc_utils.nim index 1cd15a539..4f85d913f 100644 --- a/nimbus/rpc/rpc_utils.nim +++ b/nimbus/rpc/rpc_utils.nim @@ -205,6 +205,7 @@ proc populateReceipt*(receipt: Receipt, gasUsed: GasInt, tx: Transaction, result.to = some(tx.destination) result.cumulativeGasUsed = encodeQuantity(receipt.cumulativeGasUsed.uint64) result.gasUsed = encodeQuantity(gasUsed.uint64) + result.`type` = encodeQuantity(uint(receipt.receiptType.ord)) if tx.contractCreation: var sender: EthAddress @@ -212,7 +213,30 @@ proc populateReceipt*(receipt: Receipt, gasUsed: GasInt, tx: Transaction, let contractAddress = generateAddress(sender, tx.nonce) result.contractAddress = some(contractAddress) - result.logs = receipt.logs + for log in receipt.logs: + # TODO: Work everywhere with either `Hash256` as topic or `array[32, byte]` + var topics: seq[Hash256] + for topic in log.topics: + topics.add(Hash256(data: topic)) + + let logObject = FilterLog( + removed: false, + # TODO: Not sure what is difference between logIndex and TxIndex and how + # to calculate it. + logIndex: some(result.transactionIndex), + # Note: the next 4 fields cause a lot of duplication of data, but the spec + # is what it is. Not sure if other clients actually add this. + transactionIndex: some(result.transactionIndex), + transactionHash: some(result.transactionHash), + blockHash: some(result.blockHash), + blockNumber: some(result.blockNumber), + # The actual fields + address: log.address, + data: log.data, + topics: topics + ) + result.logs.add(logObject) + result.logsBloom = FixedBytes[256] receipt.bloom # post-transaction stateroot (pre Byzantium).