fix getTransactionReceipt
This commit is contained in:
parent
9c0bb70ba7
commit
8c6cec4999
|
@ -12,7 +12,7 @@ import
|
||||||
nimcrypto, json_rpc/rpcserver, hexstrings, stint, byteutils, ranges/typedranges,
|
nimcrypto, json_rpc/rpcserver, hexstrings, stint, byteutils, ranges/typedranges,
|
||||||
eth_common, eth_p2p, eth_keys, eth_trie/db, rlp,
|
eth_common, eth_p2p, eth_keys, eth_trie/db, rlp,
|
||||||
../utils/header, ../transaction, ../config, ../vm_state, ../constants, ../vm_types,
|
../utils/header, ../transaction, ../config, ../vm_state, ../constants, ../vm_types,
|
||||||
../vm_state_transactions,
|
../vm_state_transactions, ../utils/addresses,
|
||||||
../db/[db_chain, state_db, storage_types],
|
../db/[db_chain, state_db, storage_types],
|
||||||
rpc_types, rpc_utils, ../vm/[message, computation]
|
rpc_types, rpc_utils, ../vm/[message, computation]
|
||||||
|
|
||||||
|
@ -411,19 +411,28 @@ proc setupEthRpc*(node: EthereumNode, chain: BaseChainDB, rpcsrv: RpcServer) =
|
||||||
transaction = getBlockBody(blockHash).transactions[quantity]
|
transaction = getBlockBody(blockHash).transactions[quantity]
|
||||||
populateTransactionObject(transaction, quantity, header, blockHash)
|
populateTransactionObject(transaction, quantity, header, blockHash)
|
||||||
|
|
||||||
proc populateReceipt(receipt: Receipt, gasUsed: GasInt, transaction: Transaction, txIndex: int, blockHeader: BlockHeader): ReceiptObject =
|
proc populateReceipt(receipt: Receipt, gasUsed: GasInt, tx: Transaction, txIndex: int, blockHeader: BlockHeader): ReceiptObject =
|
||||||
result.transactionHash = transaction.rlpHash
|
result.transactionHash = tx.rlpHash
|
||||||
result.transactionIndex = txIndex
|
result.transactionIndex = txIndex
|
||||||
result.blockHash = blockHeader.hash
|
result.blockHash = blockHeader.hash
|
||||||
result.blockNumber = blockHeader.blockNumber
|
result.blockNumber = blockHeader.blockNumber
|
||||||
result.sender = transaction.getSender()
|
result.sender = tx.getSender()
|
||||||
result.to = some(transaction.to)
|
result.to = some(tx.to)
|
||||||
result.cumulativeGasUsed = receipt.cumulativeGasUsed
|
result.cumulativeGasUsed = receipt.cumulativeGasUsed
|
||||||
result.gasUsed = gasUsed
|
result.gasUsed = gasUsed
|
||||||
# TODO: Get contract address if the transaction was a contract creation.
|
|
||||||
result.contractAddress = none(EthAddress)
|
if tx.isContractCreation:
|
||||||
|
var sender: EthAddress
|
||||||
|
if tx.getSender(sender):
|
||||||
|
let contractAddress = generateAddress(sender, tx.accountNonce)
|
||||||
|
result.contractAddress = some(contractAddress)
|
||||||
|
else:
|
||||||
|
assert(false)
|
||||||
|
else:
|
||||||
|
result.contractAddress = none(EthAddress)
|
||||||
|
|
||||||
result.logs = receipt.logs
|
result.logs = receipt.logs
|
||||||
result.logsBloom = blockHeader.bloom
|
result.logsBloom = receipt.bloom
|
||||||
# post-transaction stateroot (pre Byzantium).
|
# post-transaction stateroot (pre Byzantium).
|
||||||
if receipt.hasStateRoot:
|
if receipt.hasStateRoot:
|
||||||
result.root = some(receipt.stateRoot)
|
result.root = some(receipt.stateRoot)
|
||||||
|
@ -444,10 +453,12 @@ proc setupEthRpc*(node: EthereumNode, chain: BaseChainDB, rpcsrv: RpcServer) =
|
||||||
var
|
var
|
||||||
idx = 0
|
idx = 0
|
||||||
prevGasUsed = GasInt(0)
|
prevGasUsed = GasInt(0)
|
||||||
for receipt in chain.getReceipts(header, Receipt):
|
|
||||||
|
for receipt in chain.getReceipts(header):
|
||||||
let gasUsed = receipt.cumulativeGasUsed - prevGasUsed
|
let gasUsed = receipt.cumulativeGasUsed - prevGasUsed
|
||||||
prevGasUsed = receipt.cumulativeGasUsed
|
prevGasUsed = receipt.cumulativeGasUsed
|
||||||
if idx == txDetails.index:
|
if idx == txDetails.index:
|
||||||
|
echo idx
|
||||||
return populateReceipt(receipt, gasUsed, body.transactions[txDetails.index], txDetails.index, header)
|
return populateReceipt(receipt, gasUsed, body.transactions[txDetails.index], txDetails.index, header)
|
||||||
idx.inc
|
idx.inc
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue