From 306e327b08f8118fa2d6444caf11bfcb413a5dee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=BC=82=E6=B5=81?= Date: Tue, 22 Aug 2023 13:45:15 +0800 Subject: [PATCH] fix(API): gas limit conversion error (#1344) --- core/api/src/jsonrpc/web3_types.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/core/api/src/jsonrpc/web3_types.rs b/core/api/src/jsonrpc/web3_types.rs index 297a2f6f9..07b9898ab 100644 --- a/core/api/src/jsonrpc/web3_types.rs +++ b/core/api/src/jsonrpc/web3_types.rs @@ -6,8 +6,8 @@ use serde::{Deserialize, Deserializer, Serialize, Serializer}; use protocol::codec::ProtocolCodec; use protocol::types::{ - AccessList, Block, Bloom, Bytes, Hash, Header, Hex, Public, Receipt, SignedTransaction, H160, - H256, H64, MAX_PRIORITY_FEE_PER_GAS, U256, U64, + AccessList, Block, Bloom, Bytes, Hash, Header, Hex, Public, Receipt, SignedTransaction, + UnsignedTransaction, H160, H256, H64, MAX_PRIORITY_FEE_PER_GAS, U256, U64, }; pub const EMPTY_UNCLE_HASH: H256 = H256([ @@ -97,13 +97,19 @@ impl From for Web3Transaction { ) }; + let gas_limit = match stx.transaction.unsigned { + UnsignedTransaction::Legacy(ref inner) => inner.gas_limit, + UnsignedTransaction::Eip1559(ref inner) => inner.gas_limit, + UnsignedTransaction::Eip2930(ref inner) => inner.gas_limit, + }; + Web3Transaction { type_: Some(stx.type_().into()), block_number: None, block_hash: None, raw: Hex::encode(stx.transaction.encode().unwrap()), public_key: stx.public, - gas: U256::zero(), + gas: gas_limit, gas_price: stx.transaction.unsigned.gas_price(), max_fee_per_gas: if is_eip1559 { Some(U256::from(MAX_PRIORITY_FEE_PER_GAS))