Add cumulativeGas to receipts, update FilterLog type, getWork type

This commit is contained in:
coffeepots 2018-08-22 18:45:31 +01:00 committed by zah
parent f151911ddf
commit f51fca2cae
1 changed files with 14 additions and 18 deletions

View File

@ -395,10 +395,7 @@ proc setupP2PRPC*(node: EthereumNode, rpcsrv: RpcServer) =
accountGas = 0 accountGas = 0
populateTransactionObject(transaction, txHash, txCount, quantity, header, accountGas) populateTransactionObject(transaction, txHash, txCount, quantity, header, accountGas)
# Currently defined as a variant type so this might need rethinking proc populateReceipt(receipt: Receipt, cumulativeGas: GasInt, transaction: Transaction, txIndex: int, blockHeader: BlockHeader): ReceiptObject =
# See: https://github.com/status-im/nim-json-rpc/issues/29
proc populateReceipt(receipt: Receipt, transaction: Transaction, txIndex: int, blockHeader: BlockHeader): ReceiptObject =
result.transactionHash = transaction.rlpHash result.transactionHash = transaction.rlpHash
result.transactionIndex = txIndex result.transactionIndex = txIndex
result.blockHash = blockHeader.hash result.blockHash = blockHeader.hash
@ -407,13 +404,11 @@ proc setupP2PRPC*(node: EthereumNode, rpcsrv: RpcServer) =
#result.sender: EthAddress #result.sender: EthAddress
result.to = new EthAddress result.to = new EthAddress
result.to[] = transaction.to result.to[] = transaction.to
# TODO: Get gas used result.cumulativeGasUsed = cumulativeGas
#result.cumulativeGasUsed: int result.gasUsed = receipt.gasUsed
#result.gasUsed: int
# TODO: Get contract address if the transaction was a contract creation. # TODO: Get contract address if the transaction was a contract creation.
result.contractAddress = nil result.contractAddress = nil
# TODO: See Wiki for details. list of log objects, which this transaction generated. result.logs = receipt.logs
result.logs = @[]
result.logsBloom = blockHeader.bloom result.logsBloom = blockHeader.bloom
# post-transaction stateroot (pre Byzantium). # post-transaction stateroot (pre Byzantium).
result.root = blockHeader.stateRoot result.root = blockHeader.stateRoot
@ -432,10 +427,13 @@ proc setupP2PRPC*(node: EthereumNode, rpcsrv: RpcServer) =
body = chain.getBlockBody(h) body = chain.getBlockBody(h)
if body == nil: if body == nil:
raise newException(ValueError, "Cannot find hash") raise newException(ValueError, "Cannot find hash")
var idx = 0 var
idx = 0
cumulativeGas: GasInt
for receipt in chain.getReceipts(header, Receipt): for receipt in chain.getReceipts(header, Receipt):
cumulativeGas += receipt.gasUsed
if idx == txDetails.index: if idx == txDetails.index:
return populateReceipt(receipt, body.transactions[txDetails.index], txDetails.index, header) return populateReceipt(receipt, cumulativeGas, body.transactions[txDetails.index], txDetails.index, header)
idx.inc idx.inc
rpcsrv.rpc("eth_getUncleByBlockHashAndIndex") do(data: HexDataStr, quantity: int) -> BlockObject: rpcsrv.rpc("eth_getUncleByBlockHashAndIndex") do(data: HexDataStr, quantity: int) -> BlockObject:
@ -510,31 +508,29 @@ proc setupP2PRPC*(node: EthereumNode, rpcsrv: RpcServer) =
## Returns true if the filter was successfully uninstalled, otherwise false. ## Returns true if the filter was successfully uninstalled, otherwise false.
discard discard
rpcsrv.rpc("eth_getFilterChanges") do(filterId: int) -> seq[LogObject]: rpcsrv.rpc("eth_getFilterChanges") do(filterId: int) -> seq[FilterLog]:
## Polling method for a filter, which returns an list of logs which occurred since last poll. ## Polling method for a filter, which returns an list of logs which occurred since last poll.
## ##
## filterId: the filter id. ## filterId: the filter id.
result = @[] result = @[]
rpcsrv.rpc("eth_getFilterLogs") do(filterId: int) -> seq[LogObject]: rpcsrv.rpc("eth_getFilterLogs") do(filterId: int) -> seq[FilterLog]:
## filterId: the filter id. ## filterId: the filter id.
## Returns a list of all logs matching filter with given id. ## Returns a list of all logs matching filter with given id.
result = @[] result = @[]
#[ rpcsrv.rpc("eth_getLogs") do(filterOptions: FilterOptions) -> seq[FilterLog]:
rpcsrv.rpc("eth_getLogs") do(filterOptions: FilterOptions) -> seq[LogObject]:
## filterOptions: settings for this filter. ## filterOptions: settings for this filter.
## Returns a list of all logs matching a given filter object. ## Returns a list of all logs matching a given filter object.
result = @[] result = @[]
]#
rpcsrv.rpc("eth_getWork") do() -> seq[HexDataStr]: rpcsrv.rpc("eth_getWork") do() -> array[3, UInt256]:
## Returns the hash of the current block, the seedHash, and the boundary condition to be met ("target"). ## Returns the hash of the current block, the seedHash, and the boundary condition to be met ("target").
## Returned list has the following properties: ## Returned list has the following properties:
## DATA, 32 Bytes - current block header pow-hash. ## DATA, 32 Bytes - current block header pow-hash.
## DATA, 32 Bytes - the seed hash used for the DAG. ## DATA, 32 Bytes - the seed hash used for the DAG.
## DATA, 32 Bytes - the boundary condition ("target"), 2^256 / difficulty. ## DATA, 32 Bytes - the boundary condition ("target"), 2^256 / difficulty.
result = @[] discard
rpcsrv.rpc("eth_submitWork") do(nonce: int64, powHash: HexDataStr, mixDigest: HexDataStr) -> bool: rpcsrv.rpc("eth_submitWork") do(nonce: int64, powHash: HexDataStr, mixDigest: HexDataStr) -> bool:
## Used for submitting a proof-of-work solution. ## Used for submitting a proof-of-work solution.