json rpc: eth_getTransactionReceipt: add effectiveGasPrice field

This commit is contained in:
jangko 2022-04-05 17:32:54 +07:00
parent fdbabf0b80
commit 8d208acaf9
No known key found for this signature in database
GPG Key ID: 31702AE10541E6B9
3 changed files with 12 additions and 4 deletions

View File

@ -17,7 +17,8 @@ import
../db/[db_chain, state_db],
rpc_types, rpc_utils,
../transaction/call_evm,
../utils/tx_pool
../utils/tx_pool,
../chain_config
#[
Note:
@ -387,12 +388,13 @@ proc setupEthRpc*(node: EthereumNode, ctx: EthContext, chain: BaseChainDB, txPoo
var
idx = 0
prevGasUsed = GasInt(0)
fork = toFork(chain.networkParams.config, header.blockNumber)
for receipt in chain.getReceipts(header.receiptRoot):
let gasUsed = receipt.cumulativeGasUsed - prevGasUsed
prevGasUsed = receipt.cumulativeGasUsed
if idx == txDetails.index:
return some(populateReceipt(receipt, gasUsed, tx, txDetails.index, header))
return some(populateReceipt(receipt, gasUsed, tx, txDetails.index, header, fork))
idx.inc
server.rpc("eth_getUncleByBlockHashAndIndex") do(data: EthHashStr, quantity: HexQuantityStr) -> Option[BlockObject]:

View File

@ -117,6 +117,9 @@ type
logsBloom*: FixedBytes[256] # bloom filter for light clients to quickly retrieve related logs.
root*: Option[Hash256] # post-transaction stateroot (pre Byzantium).
status*: Option[int] # 1 = success, 0 = failure.
effectiveGasPrice*: HexQuantityStr # The actual value per gas deducted from the senders account.
# Before EIP-1559, this is equal to the transaction's gas price.
# After, it is equal to baseFeePerGas + min(maxFeePerGas - baseFeePerGas, maxPriorityFeePerGas).
FilterDataKind* = enum fkItem, fkList
FilterData* = object

View File

@ -11,7 +11,7 @@ import hexstrings, eth/[common, rlp, keys, trie/db], stew/byteutils, nimcrypto,
../db/db_chain, strutils, algorithm, options, times, json,
../constants, stint, hexstrings, rpc_types,
../utils, ../transaction,
../transaction/call_evm
../transaction/call_evm, ../forks
func toAddress*(value: EthAddressStr): EthAddress = hexToPaddedByteArray[20](value.string)
@ -170,7 +170,7 @@ proc populateBlockObject*(header: BlockHeader, chain: BaseChainDB, fullTx: bool,
for x in chain.getBlockTransactionHashes(header):
result.transactions.add %(x)
proc populateReceipt*(receipt: Receipt, gasUsed: GasInt, tx: Transaction, txIndex: int, header: BlockHeader): ReceiptObject =
proc populateReceipt*(receipt: Receipt, gasUsed: GasInt, tx: Transaction, txIndex: int, header: BlockHeader, fork: Fork): ReceiptObject =
result.transactionHash = tx.rlpHash
result.transactionIndex = encodeQuantity(txIndex.uint)
result.blockHash = header.hash
@ -195,3 +195,6 @@ proc populateReceipt*(receipt: Receipt, gasUsed: GasInt, tx: Transaction, txInde
else:
# 1 = success, 0 = failure.
result.status = some(receipt.status.int)
let normTx = eip1559TxNormalization(tx, header.baseFee.truncate(GasInt), fork)
result.effectiveGasPrice = encodeQuantity(normTx.gasPrice.uint64)