From 727a3ee7b1aac8883a7c996b395d13f97de6994a Mon Sep 17 00:00:00 2001 From: jangko Date: Mon, 21 Mar 2022 16:17:28 +0700 Subject: [PATCH] fix BlockHeader object of json-rpc - add missing baseFeePerGas field - add missing mixHash field --- nimbus/rpc/rpc_types.nim | 2 ++ nimbus/rpc/rpc_utils.nim | 10 +++++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/nimbus/rpc/rpc_types.nim b/nimbus/rpc/rpc_types.nim index f4e5a7a65..bef79110c 100644 --- a/nimbus/rpc/rpc_types.nim +++ b/nimbus/rpc/rpc_types.nim @@ -62,10 +62,12 @@ type difficulty*: HexQuantityStr # integer of the difficulty for this block. totalDifficulty*: HexQuantityStr# integer of the total difficulty of the chain until this block. extraData*: HexDataStr # the "extra data" field of this block. + mixHash*: Hash256 size*: HexQuantityStr # integer the size of this block in bytes. gasLimit*: HexQuantityStr # the maximum gas allowed in this block. gasUsed*: HexQuantityStr # the total used gas by all transactions in this block. timestamp*: HexQuantityStr # the unix timestamp for when the block was collated. + baseFeePerGas*: Option[HexQuantityStr] transactions*: seq[JsonNode] # list of transaction objects, or 32 Bytes transaction hashes depending on the last given parameter. uncles*: seq[Hash256] # list of uncle hashes. diff --git a/nimbus/rpc/rpc_utils.nim b/nimbus/rpc/rpc_utils.nim index 5c3dc1230..96ae8fcb9 100644 --- a/nimbus/rpc/rpc_utils.nim +++ b/nimbus/rpc/rpc_utils.nim @@ -102,8 +102,8 @@ template optionalU256(src, dst: untyped) = template optionalBytes(src, dst: untyped) = if src.isSome: dst = hexToSeqByte(src.get.string) - -proc callData*(call: EthCall): RpcCallData = + +proc callData*(call: EthCall): RpcCallData = optionalAddress(call.source, result.source) optionalAddress(call.to, result.to) optionalGas(call.gas, result.gasLimit) @@ -144,6 +144,7 @@ proc populateBlockObject*(header: BlockHeader, chain: BaseChainDB, fullTx: bool, result.miner = header.coinbase result.difficulty = encodeQuantity(header.difficulty) result.extraData = hexDataStr(header.extraData) + result.mixHash = header.mixDigest # discard sizeof(seq[byte]) of extraData and use actual length let size = sizeof(BlockHeader) - sizeof(Blob) + header.extraData.len @@ -152,7 +153,10 @@ proc populateBlockObject*(header: BlockHeader, chain: BaseChainDB, fullTx: bool, result.gasLimit = encodeQuantity(header.gasLimit.uint64) result.gasUsed = encodeQuantity(header.gasUsed.uint64) result.timestamp = encodeQuantity(header.timeStamp.toUnix.uint64) - + result.baseFeePerGas = if header.fee.isSome: + some(encodeQuantity(header.baseFee)) + else: + none(HexQuantityStr) if not isUncle: result.totalDifficulty = encodeQuantity(chain.getScore(blockHash)) result.uncles = chain.getUncleHashes(header)