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]
|
||||||
|
|
||||||
|
@ -269,7 +269,7 @@ proc setupEthRpc*(node: EthereumNode, chain: BaseChainDB, rpcsrv: RpcServer) =
|
||||||
gasPrice =
|
gasPrice =
|
||||||
if call.gasPrice.isSome: call.gasPrice.get
|
if call.gasPrice.isSome: call.gasPrice.get
|
||||||
else: 0.GasInt
|
else: 0.GasInt
|
||||||
|
|
||||||
# Set defaults for gas limit if required
|
# Set defaults for gas limit if required
|
||||||
# Price remains zero by default
|
# Price remains zero by default
|
||||||
if gaslimit == 0.GasInt:
|
if gaslimit == 0.GasInt:
|
||||||
|
@ -285,7 +285,7 @@ proc setupEthRpc*(node: EthereumNode, chain: BaseChainDB, rpcsrv: RpcServer) =
|
||||||
data = if call.data.isSome: call.data.get.string.fromHex else: @[]
|
data = if call.data.isSome: call.data.get.string.fromHex else: @[]
|
||||||
value = if call.value.isSome: call.value.get else: 0.u256
|
value = if call.value.isSome: call.value.get else: 0.u256
|
||||||
comp = setupComputation(vmState, header.blockNumber, value, data, sender, destination, gasLimit, gasPrice)
|
comp = setupComputation(vmState, header.blockNumber, value, data, sender, destination, gasLimit, gasPrice)
|
||||||
|
|
||||||
discard comp.execComputation
|
discard comp.execComputation
|
||||||
result = ("0x" & nimcrypto.toHex(comp.output)).HexDataStr
|
result = ("0x" & nimcrypto.toHex(comp.output)).HexDataStr
|
||||||
|
|
||||||
|
@ -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