Skip to content

Commit

Permalink
simplify eip1559 support
Browse files Browse the repository at this point in the history
  • Loading branch information
harryliisme3 committed Jan 6, 2023
1 parent 91c3fed commit 16129ab
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/components/contracts/primitives/rpc-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ description = "RPC traits of Ethereum."
license = "GPL-3.0-or-later WITH Classpath-exception-2.0"

[dependencies]
ethereum = { version = "0.12.0", default-features = false, features = ["with-serde"] }
ethereum-types = "0.13.1"
futures = "0.3.16"
jsonrpc-core = { git = "https://github.com/FindoraNetwork/jsonrpc.git", package = "jsonrpc-core" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ pub struct CallRequest {
pub to: Option<H160>,
/// Gas Price
pub gas_price: Option<U256>,
/// EIP-1559 Max base fee the caller is willing to pay
pub max_fee_per_gas: Option<U256>,
/// EIP-1559 Priority fee the caller is paying to the block author
pub max_priority_fee_per_gas: Option<U256>,
/// Gas
pub gas: Option<U256>,
/// Value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@
//! `TransactionRequest` type
use crate::types::Bytes;
use ethereum::AccessListItem;
use ethereum_types::{H160, U256};
use serde::{Deserialize, Serialize};

/// Transaction request coming from RPC
#[derive(Debug, Clone, Default, Eq, PartialEq, Hash, Serialize, Deserialize)]
#[derive(Debug, Clone, Default, Eq, PartialEq, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
#[serde(rename_all = "camelCase")]
pub struct TransactionRequest {
Expand All @@ -33,6 +34,10 @@ pub struct TransactionRequest {
pub to: Option<H160>,
/// Gas Price
pub gas_price: Option<U256>,
/// Max BaseFeePerGas the user is willing to pay.
pub max_fee_per_gas: Option<U256>,
/// The miner's tip.
pub max_priority_fee_per_gas: Option<U256>,
/// Gas
pub gas: Option<U256>,
/// Value of transaction in wei
Expand All @@ -41,4 +46,6 @@ pub struct TransactionRequest {
pub data: Option<Bytes>,
/// Transaction's nonce
pub nonce: Option<U256>,
/// Pre-pay to warm storage access.
pub access_list: Option<Vec<AccessListItem>>,
}
61 changes: 61 additions & 0 deletions src/components/contracts/rpc/src/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,25 @@ impl EthApi for EthApiImpl {
fn send_transaction(&self, request: TransactionRequest) -> BoxFuture<Result<H256>> {
debug!(target: "eth_rpc", "send_transaction, request:{:?}", request);

let mut request = request;
let curr_height = match self.block_number() {
Ok(v) => v,
Err(e) => {
return Box::pin(async move { Err(e) });
}
}
.as_u64();
if request.gas_price.is_none()
&& request.max_fee_per_gas.is_some()
&& request.max_priority_fee_per_gas.is_some()
{
request.gas_price = Some(
<BaseApp as module_evm::Config>::FeeCalculator::min_gas_price(
curr_height,
),
);
}

let from = match request.from {
Some(from) => from,
None => {
Expand Down Expand Up @@ -345,13 +364,34 @@ impl EthApi for EthApiImpl {
) -> BoxFuture<Result<Bytes>> {
debug!(target: "eth_rpc", "call, request:{:?}", request);

let mut request = request;
let curr_height = match self.block_number() {
Ok(v) => v,
Err(e) => {
return Box::pin(async move { Err(e) });
}
}
.as_u64();
if request.gas_price.is_none()
&& request.max_fee_per_gas.is_some()
&& request.max_priority_fee_per_gas.is_some()
{
request.gas_price = Some(
<BaseApp as module_evm::Config>::FeeCalculator::min_gas_price(
curr_height,
),
);
}

let account_base_app = self.account_base_app.clone();

let task = spawn_blocking(move || -> Result<Bytes> {
let CallRequest {
from,
to,
gas_price,
max_fee_per_gas: _max_fee_per_gas,
max_priority_fee_per_gas: _max_priority_fee_per_gas,
gas,
value,
data,
Expand Down Expand Up @@ -764,6 +804,25 @@ impl EthApi for EthApiImpl {
) -> BoxFuture<Result<U256>> {
debug!(target: "eth_rpc", "estimate_gas, block number {:?} request:{:?}", number, request);

let mut request = request;
let curr_height = match self.block_number() {
Ok(v) => v,
Err(e) => {
return Box::pin(async move { Err(e) });
}
}
.as_u64();
if request.gas_price.is_none()
&& request.max_fee_per_gas.is_some()
&& request.max_priority_fee_per_gas.is_some()
{
request.gas_price = Some(
<BaseApp as module_evm::Config>::FeeCalculator::min_gas_price(
curr_height,
),
);
}

let account_base_app = self.account_base_app.clone();

let task = spawn_blocking(move || {
Expand Down Expand Up @@ -861,6 +920,8 @@ impl EthApi for EthApiImpl {
from,
to,
gas_price,
max_fee_per_gas: _max_fee_per_gas,
max_priority_fee_per_gas: _max_priority_fee_per_gas,
gas,
value,
data,
Expand Down

0 comments on commit 16129ab

Please sign in to comment.