keep in sync with eth_common#23

This commit is contained in:
andri lim 2018-11-28 22:04:57 +07:00 committed by zah
parent 03ca4ef24a
commit af84be0eea
2 changed files with 15 additions and 13 deletions

View File

@ -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]:

View File

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