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
This commit is contained in:
Kim De Mey 2023-03-27 21:10:43 +02:00 committed by GitHub
parent c01045c246
commit 0ea08655a0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 2 deletions

View File

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

View File

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