From af84be0eea630a41db26e133b47589389d54a8f3 Mon Sep 17 00:00:00 2001 From: andri lim Date: Wed, 28 Nov 2018 22:04:57 +0700 Subject: [PATCH] keep in sync with eth_common#23 --- nimbus/rpc/p2p.nim | 22 ++++++++++++---------- nimbus/rpc/rpc_types.nim | 6 +++--- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/nimbus/rpc/p2p.nim b/nimbus/rpc/p2p.nim index 550498380..cef2e0cb7 100644 --- a/nimbus/rpc/p2p.nim +++ b/nimbus/rpc/p2p.nim @@ -349,24 +349,25 @@ proc setupEthRpc*(node: EthereumNode, chain: BaseChainDB, rpcsrv: RpcServer) = transaction = getBlockBody(blockHash).transactions[quantity] populateTransactionObject(transaction, quantity, header, blockHash) - proc populateReceipt(receipt: Receipt, cumulativeGas: GasInt, transaction: Transaction, txIndex: int, blockHeader: BlockHeader): ReceiptObject = + proc populateReceipt(receipt: Receipt, gasUsed: GasInt, transaction: Transaction, txIndex: int, blockHeader: BlockHeader): ReceiptObject = result.transactionHash = transaction.rlpHash result.transactionIndex = txIndex result.blockHash = blockHeader.hash result.blockNumber = blockHeader.blockNumber result.sender = transaction.getSender() result.to = some(transaction.to) - result.cumulativeGasUsed = cumulativeGas - result.gasUsed = receipt.gasUsed + result.cumulativeGasUsed = receipt.cumulativeGasUsed + result.gasUsed = gasUsed # TODO: Get contract address if the transaction was a contract creation. result.contractAddress = none(EthAddress) result.logs = receipt.logs result.logsBloom = blockHeader.bloom # post-transaction stateroot (pre Byzantium). - result.root = blockHeader.stateRoot - # TODO: Respond to success/failure - # 1 = success, 0 = failure. - result.status = 1 + if receipt.hasStateRoot: + result.root = some(receipt.stateRoot) + else: + # 1 = success, 0 = failure. + result.status = some(receipt.status) rpcsrv.rpc("eth_getTransactionReceipt") do(data: HexDataStr) -> ReceiptObject: ## Returns the receipt of a transaction by transaction hash. @@ -380,11 +381,12 @@ proc setupEthRpc*(node: EthereumNode, chain: BaseChainDB, rpcsrv: RpcServer) = body = getBlockBody(header.hash) var idx = 0 - cumulativeGas: GasInt + prevGasUsed = GasInt(0) for receipt in chain.getReceipts(header, Receipt): - cumulativeGas += receipt.gasUsed + let gasUsed = receipt.cumulativeGasUsed - prevGasUsed + prevGasUsed = receipt.cumulativeGasUsed if idx == txDetails.index: - return populateReceipt(receipt, cumulativeGas, body.transactions[txDetails.index], txDetails.index, header) + return populateReceipt(receipt, gasUsed, body.transactions[txDetails.index], txDetails.index, header) idx.inc rpcsrv.rpc("eth_getUncleByBlockHashAndIndex") do(data: HexDataStr, quantity: int) -> Option[BlockObject]: diff --git a/nimbus/rpc/rpc_types.nim b/nimbus/rpc/rpc_types.nim index f715cb20b..f63599105 100644 --- a/nimbus/rpc/rpc_types.nim +++ b/nimbus/rpc/rpc_types.nim @@ -26,7 +26,7 @@ type gasPrice*: GasInt # (optional, default: To-Be-Determined) integer of the gasPrice used for each paid gas. value*: int # (optional) integer of the value sent with this transaction. data*: EthHashStr # TODO: Support more data. The compiled code of a contract OR the hash of the invoked method signature and encoded parameters. For details see Ethereum Contract ABI. - nonce*: int # (optional) integer of a nonce. This allows to overwrite your own pending transactions that use the same nonce + nonce*: int # (optional) integer of a nonce. This allows to overwrite your own pending transactions that use the same nonce EthCall* = object # Parameter from user @@ -102,8 +102,8 @@ type 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. logsBloom*: BloomFilter # bloom filter for light clients to quickly retrieve related logs. - root*: Hash256 # post-transaction stateroot (pre Byzantium). - status*: int # 1 = success, 0 = failure. + root*: Option[Hash256] # post-transaction stateroot (pre Byzantium). + status*: Option[int] # 1 = success, 0 = failure. FilterDataKind* = enum fkItem, fkList FilterData* = object