diff --git a/src/components/contracts/baseapp/src/extensions.rs b/src/components/contracts/baseapp/src/extensions.rs index d17977e40a..e75a9eaf92 100644 --- a/src/components/contracts/baseapp/src/extensions.rs +++ b/src/components/contracts/baseapp/src/extensions.rs @@ -4,7 +4,7 @@ use fp_core::{ context::Context, transaction::{ActionResult, SignedExtension}, }; -use fp_traits::account::{AccountAsset, FeeCalculator}; +use fp_traits::{account::AccountAsset, evm::FeeCalculator}; use fp_types::crypto::Address; use primitive_types::U256; use ruc::*; @@ -64,7 +64,9 @@ impl SignedExtension for CheckFee { type Pre = (Address, U256); fn validate(&self, ctx: &Context, who: &Self::AccountId) -> Result<()> { - let min_fee = ::FeeCalculator::min_fee(); + let min_fee = ::FeeCalculator::min_gas_price( + ctx.header.height as u64, + ); let tx_fee = match self.0 { None => min_fee, Some(fee) => { @@ -85,7 +87,9 @@ impl SignedExtension for CheckFee { } fn pre_execute(self, ctx: &Context, who: &Self::AccountId) -> Result { - let min_fee = ::FeeCalculator::min_fee(); + let min_fee = ::FeeCalculator::min_gas_price( + ctx.header.height as u64, + ); let tx_fee = match self.0 { None => min_fee, Some(fee) => { diff --git a/src/components/contracts/baseapp/src/lib.rs b/src/components/contracts/baseapp/src/lib.rs index eeffde329a..0d0ef3b98a 100644 --- a/src/components/contracts/baseapp/src/lib.rs +++ b/src/components/contracts/baseapp/src/lib.rs @@ -24,11 +24,12 @@ use fp_core::{ transaction::{ActionResult, Executable, ValidateUnsigned}, }; use fp_evm::BlockId; -use fp_traits::evm::FeeCalculator as FeeCalculator2; use fp_traits::{ - account::{AccountAsset, FeeCalculator}, + account::AccountAsset, base::BaseProvider, - evm::{DecimalsMapping, EthereumAddressMapping, EthereumDecimalsMapping}, + evm::{ + DecimalsMapping, EthereumAddressMapping, EthereumDecimalsMapping, FeeCalculator, + }, }; use fp_types::{actions::xhub::NonConfidentialOutput, actions::Action, crypto::Address}; use lazy_static::lazy_static; @@ -99,17 +100,8 @@ pub struct BaseApp { impl module_template::Config for BaseApp {} -pub struct StableTxFee; - -impl FeeCalculator for StableTxFee { - fn min_fee() -> U256 { - // TX_FEE_MIN - U256::from(1_0000_0000_0000_0000_u64) - } -} - impl module_account::Config for BaseApp { - type FeeCalculator = StableTxFee; + type FeeCalculator = (); } parameter_types! { diff --git a/src/components/contracts/modules/account/src/lib.rs b/src/components/contracts/modules/account/src/lib.rs index 7429c47dc3..4192005c6e 100644 --- a/src/components/contracts/modules/account/src/lib.rs +++ b/src/components/contracts/modules/account/src/lib.rs @@ -12,8 +12,8 @@ mod tests; use abci::{RequestQuery, ResponseQuery}; use fp_core::{context::Context, module::AppModule}; use fp_traits::{ - account::{AccountAsset, FeeCalculator}, - evm::{DecimalsMapping, EthereumDecimalsMapping}, + account::AccountAsset, + evm::{DecimalsMapping, EthereumDecimalsMapping, FeeCalculator}, }; use fp_types::crypto::Address; use std::marker::PhantomData; diff --git a/src/components/contracts/modules/ethereum/src/impls.rs b/src/components/contracts/modules/ethereum/src/impls.rs index 9281217a18..7aa553539e 100644 --- a/src/components/contracts/modules/ethereum/src/impls.rs +++ b/src/components/contracts/modules/ethereum/src/impls.rs @@ -255,9 +255,8 @@ impl App { let _chain_id; let mut _access_list = vec![]; - let is_eip1559 = match &transaction { - Transaction::Legacy(legacy_transaction_transaction) => { - let transaction = legacy_transaction_transaction; + match &transaction { + Transaction::Legacy(transaction) => { nonce = transaction.nonce; gas_price = transaction.gas_price; max_fee_per_gas = transaction.gas_price; @@ -270,11 +269,8 @@ impl App { Some(chain_id) => chain_id, None => return Err(eg!("Must provide chainId")), }; - - false } - Transaction::EIP1559(eip1559_transaction_transaction) => { - let transaction = eip1559_transaction_transaction; + Transaction::EIP1559(transaction) => { nonce = transaction.nonce; gas_limit = transaction.gas_limit; action = transaction.action; @@ -285,16 +281,12 @@ impl App { gas_price = transaction.max_fee_per_gas; _chain_id = transaction.chain_id; _access_list = transaction.access_list.clone(); - - true } _ => { - return Err(eg!("Transaction Type Error")); + return Err(eg!("Unsupported Transaction Type")); } }; - // let gas_limit = transaction.gas_limit; - let execute_ret = Self::execute_transaction( ctx, source, @@ -306,7 +298,6 @@ impl App { Some(max_priority_fee_per_gas), Some(nonce), action, - is_eip1559, ); if let Err(e) = execute_ret { @@ -474,81 +465,44 @@ impl App { max_priority_fee_per_gas: Option, nonce: Option, action: ethereum::TransactionAction, - is_eip1559: bool, ) -> Result<(Option, Option, CallOrCreateInfo)> { - if is_eip1559 { - match action { - ethereum::TransactionAction::Call(target) => { - let res = C::Runner::call_eip1559( - ctx, - EvmAction::CallEip1559 { - source: from, - target, - input, - value, - gas_limit: gas_limit.low_u64(), - max_fee_per_gas, - max_priority_fee_per_gas, - nonce, - }, - C::config(), - )?; - - Ok((Some(target), None, CallOrCreateInfo::Call(res))) - } - ethereum::TransactionAction::Create => { - let res = C::Runner::create_eip1559( - ctx, - EvmAction::CreateEip1559 { - source: from, - init: input, - value, - gas_limit: gas_limit.low_u64(), - max_fee_per_gas, - max_priority_fee_per_gas, - nonce, - }, - C::config(), - )?; - - Ok((None, Some(res.value), CallOrCreateInfo::Create(res))) - } + match action { + ethereum::TransactionAction::Call(target) => { + let res = C::Runner::call( + ctx, + EvmAction::Call { + source: from, + target, + input, + value, + gas_limit: gas_limit.low_u64(), + gas_price, + max_fee_per_gas, + max_priority_fee_per_gas, + nonce, + }, + C::config(), + )?; + + Ok((Some(target), None, CallOrCreateInfo::Call(res))) } - } else { - match action { - ethereum::TransactionAction::Call(target) => { - let res = C::Runner::call( - ctx, - EvmAction::Call { - source: from, - target, - input, - value, - gas_limit: gas_limit.low_u64(), - gas_price, - nonce, - }, - C::config(), - )?; - - Ok((Some(target), None, CallOrCreateInfo::Call(res))) - } - ethereum::TransactionAction::Create => { - let res = C::Runner::create( - ctx, - EvmAction::Create { - source: from, - init: input, - value, - gas_limit: gas_limit.low_u64(), - gas_price, - nonce, - }, - C::config(), - )?; - - Ok((None, Some(res.value), CallOrCreateInfo::Create(res))) - } + ethereum::TransactionAction::Create => { + let res = C::Runner::create( + ctx, + EvmAction::Create { + source: from, + init: input, + value, + gas_limit: gas_limit.low_u64(), + gas_price, + max_fee_per_gas, + max_priority_fee_per_gas, + nonce, + }, + C::config(), + )?; + + Ok((None, Some(res.value), CallOrCreateInfo::Create(res))) } } } diff --git a/src/components/contracts/modules/ethereum/src/lib.rs b/src/components/contracts/modules/ethereum/src/lib.rs index 1575b12572..de1c16f695 100644 --- a/src/components/contracts/modules/ethereum/src/lib.rs +++ b/src/components/contracts/modules/ethereum/src/lib.rs @@ -184,41 +184,37 @@ impl ValidateUnsigned for App { gas_limit, value, chain_id, - max_fee_per_gas, - max_priority_fee_per_gas, - is_eip1559, - ); - - match transaction { - Transaction::Legacy(t) => { - nonce = t.nonce; - gas_price = t.gas_price; - gas_limit = t.gas_limit; - value = t.value; - chain_id = match t.signature.chain_id() { + _max_fee_per_gas, + _max_priority_fee_per_gas, + _is_eip1559, + ) = match transaction { + Transaction::Legacy(t) => ( + t.nonce, + t.gas_price, + t.gas_limit, + t.value, + match t.signature.chain_id() { Some(chain_id) => chain_id, None => return Err(eg!("Must provide chainId")), - }; - is_eip1559 = false; - - max_fee_per_gas = U256::zero(); - max_priority_fee_per_gas = U256::zero(); - } - Transaction::EIP1559(t) => { - nonce = t.nonce; - gas_limit = t.gas_limit; - max_fee_per_gas = t.max_fee_per_gas; - max_priority_fee_per_gas = t.max_priority_fee_per_gas; - value = t.value; - chain_id = t.chain_id; - is_eip1559 = true; - - gas_price = U256::zero(); - } + }, + U256::zero(), + U256::zero(), + false, + ), + Transaction::EIP1559(t) => ( + t.nonce, + U256::zero(), + t.gas_limit, + t.value, + t.chain_id, + t.max_fee_per_gas, + t.max_priority_fee_per_gas, + true, + ), _ => { return Err(eg!("Transaction Type Error")); } - } + }; if chain_id != C::ChainId::get() { return Err(eg!(format!( @@ -240,16 +236,13 @@ impl ValidateUnsigned for App { ))); } - if !is_eip1559 { - let min_gas_price = - C::FeeCalculator::min_gas_price(ctx.header.height as u64); + let min_gas_price = C::FeeCalculator::min_gas_price(ctx.header.height as u64); - if gas_price < min_gas_price { - return Err(eg!(format!( - "InvalidGasPrice: got {}, but the minimum gas price is {}", - gas_price, min_gas_price - ))); - } + if gas_price < min_gas_price { + return Err(eg!(format!( + "InvalidGasPrice: got {}, but the minimum gas price is {}", + gas_price, min_gas_price + ))); } let account_id = C::AddressMapping::convert_to_account_id(origin); @@ -263,20 +256,7 @@ impl ValidateUnsigned for App { ))); } - let fee = if !is_eip1559 { - gas_price.saturating_mul(gas_limit) - } else { - let max_base_fee = max_fee_per_gas - .checked_mul(gas_limit) - .ok_or(eg!("FeeOverflow"))?; - let max_priority_fee = max_priority_fee_per_gas - .checked_mul(gas_limit) - .ok_or(eg!("FeeOverflow"))?; - max_base_fee - .checked_add(max_priority_fee) - .ok_or(eg!("FeeOverflow"))? - }; - + let fee = gas_price.saturating_mul(gas_limit); let total_payment = value.saturating_add(fee); if account.balance < total_payment { diff --git a/src/components/contracts/modules/evm/src/runtime/runner.rs b/src/components/contracts/modules/evm/src/runtime/runner.rs index e9414ed97a..0c45bad380 100644 --- a/src/components/contracts/modules/evm/src/runtime/runner.rs +++ b/src/components/contracts/modules/evm/src/runtime/runner.rs @@ -26,125 +26,6 @@ impl ActionRunner { #[allow(clippy::too_many_arguments)] /// Execute an EVM operation. pub fn execute<'config, 'precompiles, F, R>( - ctx: &Context, - source: H160, - value: U256, - gas_limit: u64, - gas_price: Option, - nonce: Option, - config: &'config evm::Config, - precompiles: &'precompiles C::PrecompilesType, - f: F, - ) -> Result> - where - F: FnOnce( - &mut StackExecutor< - 'config, - 'precompiles, - FindoraStackState<'_, '_, 'config, C>, - C::PrecompilesType, - >, - ) -> (ExitReason, R), - { - let min_gas_price = C::FeeCalculator::min_gas_price(ctx.header.height as u64); - - // Gas price check is skipped when performing a gas estimation. - let gas_price = match gas_price { - Some(gas_price) => { - ensure!(gas_price >= min_gas_price, "GasPriceTooLow"); - gas_price - } - None => Default::default(), - }; - - let vicinity = Vicinity { - gas_price, - origin: source, - }; - - let metadata = StackSubstateMetadata::new(gas_limit, config); - let state = FindoraStackState::new(ctx, &vicinity, metadata); - let mut executor = - StackExecutor::new_with_precompiles(state, config, precompiles); - - let total_fee = gas_price - .checked_mul(U256::from(gas_limit)) - .ok_or(eg!("FeeOverflow"))?; - let total_payment = - value.checked_add(total_fee).ok_or(eg!("PaymentOverflow"))?; - let source_account = App::::account_basic(ctx, &source); - - if let Some(nonce) = nonce { - ensure!( - source_account.nonce == nonce, - format!( - "InvalidNonce, expected: {}, actual: {}", - source_account.nonce, nonce - ) - ); - } - - if !config.estimate { - ensure!(source_account.balance >= total_payment, "BalanceLow"); - - // Deduct fee from the `source` account. - App::::withdraw_fee(ctx, &source, total_fee)?; - } - - // Execute the EVM call. - let (reason, retv) = f(&mut executor); - - let used_gas = U256::from(executor.used_gas()); - let actual_fee = executor.fee(gas_price); - tracing::debug!( - target: "evm", - "Execution {:?} [source: {:?}, value: {}, gas_price {}, gas_limit: {}, actual_fee: {}]", - reason, - source, - value, - gas_price, - gas_limit, - actual_fee - ); - - if !config.estimate { - // Refund fees to the `source` account if deducted more before, - App::::correct_and_deposit_fee(ctx, &source, actual_fee, total_fee)?; - } - - let state = executor.into_state(); - - for address in state.substate.deletes { - tracing::debug!( - target: "evm", - "Deleting account at {:?}", - address - ); - App::::remove_account(ctx, &address.into()) - } - - for log in &state.substate.logs { - tracing::trace!( - target: "evm", - "Inserting log for {:?}, topics ({}) {:?}, data ({}): {:?}]", - log.address, - log.topics.len(), - log.topics, - log.data.len(), - log.data - ); - } - - Ok(ExecutionInfo { - value: retv, - exit_reason: reason, - used_gas, - logs: state.substate.logs, - }) - } - - // eip1559 support - pub fn execute_eip1559<'config, 'precompiles, F, R>( ctx: &Context, source: H160, value: U256, @@ -167,6 +48,7 @@ impl ActionRunner { ) -> (ExitReason, R), { let base_fee = C::FeeCalculator::min_gas_price(ctx.header.height as u64); + // Gas price check is skipped when performing a gas estimation. let max_fee_per_gas = match max_fee_per_gas { Some(max_fee_per_gas) => { @@ -433,13 +315,13 @@ impl Runner for ActionRunner { fn call(ctx: &Context, args: Call, config: &evm::Config) -> Result { let precompiles = C::PrecompilesValue::get(ctx.clone()); let access_list = Vec::new(); - Self::execute( ctx, args.source, args.value, args.gas_limit, - args.gas_price, + args.max_fee_per_gas, + args.max_priority_fee_per_gas, args.nonce, config, &precompiles, @@ -459,13 +341,13 @@ impl Runner for ActionRunner { fn create(ctx: &Context, args: Create, config: &evm::Config) -> Result { let precompiles = C::PrecompilesValue::get(ctx.clone()); let access_list = Vec::new(); - Self::execute( ctx, args.source, args.value, args.gas_limit, - args.gas_price, + args.max_fee_per_gas, + args.max_priority_fee_per_gas, args.nonce, config, &precompiles, @@ -473,7 +355,6 @@ impl Runner for ActionRunner { let address = executor.create_address(evm::CreateScheme::Legacy { caller: args.source, }); - ( executor .transact_create( @@ -498,115 +379,7 @@ impl Runner for ActionRunner { let code_hash = H256::from_slice(Keccak256::digest(&args.init).as_slice()); let precompiles = C::PrecompilesValue::get(ctx.clone()); let access_list = Vec::new(); - Self::execute( - ctx, - args.source, - args.value, - args.gas_limit, - args.gas_price, - args.nonce, - config, - &precompiles, - |executor| { - let address = executor.create_address(evm::CreateScheme::Create2 { - caller: args.source, - code_hash, - salt: args.salt, - }); - ( - executor - .transact_create2( - args.source, - args.value, - args.init, - args.salt, - args.gas_limit, - access_list, - ) - .0, - address, - ) - }, - ) - } - - fn call_eip1559( - ctx: &Context, - args: CallEip1559, - config: &evm::Config, - ) -> Result { - let precompiles = C::PrecompilesValue::get(ctx.clone()); - let access_list = Vec::new(); - Self::execute_eip1559( - ctx, - args.source, - args.value, - args.gas_limit, - args.max_fee_per_gas, - args.max_priority_fee_per_gas, - args.nonce, - config, - &precompiles, - |executor| { - executor.transact_call( - args.source, - args.target, - args.value, - args.input, - args.gas_limit, - access_list, - ) - }, - ) - } - - fn create_eip1559( - ctx: &Context, - args: CreateEip1559, - config: &evm::Config, - ) -> Result { - let precompiles = C::PrecompilesValue::get(ctx.clone()); - let access_list = Vec::new(); - Self::execute_eip1559( - ctx, - args.source, - args.value, - args.gas_limit, - args.max_fee_per_gas, - args.max_priority_fee_per_gas, - args.nonce, - config, - &precompiles, - |executor| { - let address = executor.create_address(evm::CreateScheme::Legacy { - caller: args.source, - }); - ( - executor - .transact_create( - args.source, - args.value, - args.init, - args.gas_limit, - access_list, - ) - .0, - address, - ) - }, - ) - } - - fn create2_eip1559( - ctx: &Context, - args: Create2Eip1559, - config: &evm::Config, - ) -> Result { - let code_hash = H256::from_slice(Keccak256::digest(&args.init).as_slice()); - let precompiles = C::PrecompilesValue::get(ctx.clone()); - let access_list = Vec::new(); - Self::execute_eip1559( ctx, args.source, args.value, diff --git a/src/components/contracts/modules/evm/tests/evm_integration.rs b/src/components/contracts/modules/evm/tests/evm_integration.rs index 7f6163ce2f..14ae5db8a9 100644 --- a/src/components/contracts/modules/evm/tests/evm_integration.rs +++ b/src/components/contracts/modules/evm/tests/evm_integration.rs @@ -287,6 +287,8 @@ fn test_balance_of_with_eth_call(contract: ERC20, who: H160) -> U256 { value: U256::zero(), gas_limit: DEFAULT_GAS_LIMIT, gas_price: None, + max_fee_per_gas: None, + max_priority_fee_per_gas: None, nonce: None, }; diff --git a/src/components/contracts/modules/template/tests/template_integration.rs b/src/components/contracts/modules/template/tests/template_integration.rs index 85c5f1587e..34ff9615c0 100644 --- a/src/components/contracts/modules/template/tests/template_integration.rs +++ b/src/components/contracts/modules/template/tests/template_integration.rs @@ -3,7 +3,7 @@ //! Template module integration tests. use abci::*; use fp_mocks::*; -use fp_traits::account::{AccountAsset, FeeCalculator}; +use fp_traits::{account::AccountAsset, evm::FeeCalculator}; use fp_types::{actions::template::Action as TemplateAction, actions::Action, U256}; use fp_utils::tx::EvmRawTxWrapper; use module_template::ValueStore; @@ -149,7 +149,9 @@ fn test_abci_commit() { &ALICE_XFR.pub_key.into() ), U256::from(100_0000_0000_0000_0000_u64).saturating_sub( - ::FeeCalculator::min_fee() + ::FeeCalculator::min_gas_price( + BASE_APP.lock().unwrap().deliver_state.header.height as u64, + ) ) ); } diff --git a/src/components/contracts/primitives/evm/src/lib.rs b/src/components/contracts/primitives/evm/src/lib.rs index 06cbcc9c3e..62b37bda3c 100644 --- a/src/components/contracts/primitives/evm/src/lib.rs +++ b/src/components/contracts/primitives/evm/src/lib.rs @@ -5,7 +5,7 @@ use ethereum_types::{Bloom, H160, H256, U256}; use evm::ExitReason; use fp_core::context::Context; use fp_types::actions::evm::{ - Call, CallEip1559, Create, Create2, Create2Eip1559, CreateEip1559, + Call, Create, Create2, }; use ruc::*; use serde::{Deserialize, Serialize}; @@ -57,24 +57,6 @@ pub trait Runner { fn create2(ctx: &Context, args: Create2, config: &evm::Config) -> Result; - - fn call_eip1559( - ctx: &Context, - args: CallEip1559, - config: &evm::Config, - ) -> Result; - - fn create_eip1559( - ctx: &Context, - args: CreateEip1559, - config: &evm::Config, - ) -> Result; - - fn create2_eip1559( - ctx: &Context, - args: Create2Eip1559, - config: &evm::Config, - ) -> Result; } #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] diff --git a/src/components/contracts/primitives/traits/src/account.rs b/src/components/contracts/primitives/traits/src/account.rs index 0227483d1b..2397b0e1d0 100644 --- a/src/components/contracts/primitives/traits/src/account.rs +++ b/src/components/contracts/primitives/traits/src/account.rs @@ -59,14 +59,3 @@ pub trait AccountAsset
{ fn income(ctx: &Context, who: &Address, value: U256) -> Result<()>; } - -/// Outputs the current transaction fee. -pub trait FeeCalculator { - fn min_fee() -> U256; -} - -impl FeeCalculator for () { - fn min_fee() -> U256 { - U256::zero() - } -} diff --git a/src/components/contracts/primitives/types/src/actions/ethereum.rs b/src/components/contracts/primitives/types/src/actions/ethereum.rs index 4efd37397b..4e5ab9fc8a 100644 --- a/src/components/contracts/primitives/types/src/actions/ethereum.rs +++ b/src/components/contracts/primitives/types/src/actions/ethereum.rs @@ -1,4 +1,3 @@ -use ethereum::TransactionV0 as LegacyTransaction; use ethereum::TransactionV2 as Transaction; use serde::{Deserialize, Serialize}; @@ -6,8 +5,3 @@ use serde::{Deserialize, Serialize}; pub enum Action { Transact(Transaction), } - -#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] -pub enum LegacyAction { - Transact(LegacyTransaction), -} diff --git a/src/components/contracts/primitives/types/src/actions/evm.rs b/src/components/contracts/primitives/types/src/actions/evm.rs index 9510a461cc..39f2e62079 100644 --- a/src/components/contracts/primitives/types/src/actions/evm.rs +++ b/src/components/contracts/primitives/types/src/actions/evm.rs @@ -6,9 +6,6 @@ pub enum Action { Call(Call), Create(Create), Create2(Create2), - CallEip1559(CallEip1559), - CreateEip1559(CreateEip1559), - Create2Eip1559(Create2Eip1559), } #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] @@ -19,16 +16,6 @@ pub struct Call { pub value: U256, pub gas_limit: u64, pub gas_price: Option, - pub nonce: Option, -} - -#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] -pub struct CallEip1559 { - pub source: H160, - pub target: H160, - pub input: Vec, - pub value: U256, - pub gas_limit: u64, pub max_fee_per_gas: Option, pub max_priority_fee_per_gas: Option, pub nonce: Option, @@ -41,15 +28,6 @@ pub struct Create { pub value: U256, pub gas_limit: u64, pub gas_price: Option, - pub nonce: Option, -} - -#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] -pub struct CreateEip1559 { - pub source: H160, - pub init: Vec, - pub value: U256, - pub gas_limit: u64, pub max_fee_per_gas: Option, pub max_priority_fee_per_gas: Option, pub nonce: Option, @@ -63,16 +41,6 @@ pub struct Create2 { pub value: U256, pub gas_limit: u64, pub gas_price: Option, - pub nonce: Option, -} - -#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] -pub struct Create2Eip1559 { - pub source: H160, - pub init: Vec, - pub salt: H256, - pub value: U256, - pub gas_limit: u64, pub max_fee_per_gas: Option, pub max_priority_fee_per_gas: Option, pub nonce: Option, diff --git a/src/components/contracts/primitives/types/src/actions/mod.rs b/src/components/contracts/primitives/types/src/actions/mod.rs index 0f006107ea..b049ae7d2b 100644 --- a/src/components/contracts/primitives/types/src/actions/mod.rs +++ b/src/components/contracts/primitives/types/src/actions/mod.rs @@ -12,11 +12,3 @@ pub enum Action { XHub(xhub::Action), Template(template::Action), } - -#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] -pub enum LegacyAction { - Ethereum(ethereum::LegacyAction), - Evm(evm::Action), - XHub(xhub::Action), - Template(template::Action), -} diff --git a/src/components/contracts/primitives/types/src/assemble.rs b/src/components/contracts/primitives/types/src/assemble.rs index a2c709a7ac..3ea03b3e28 100644 --- a/src/components/contracts/primitives/types/src/assemble.rs +++ b/src/components/contracts/primitives/types/src/assemble.rs @@ -1,5 +1,5 @@ use crate::actions::ethereum::Action as EtherAction; -use crate::actions::{Action, LegacyAction}; +use crate::actions::Action; use crate::crypto::{Address, Signature}; use crate::transaction; use ethereum::TransactionV2 as Transaction; @@ -28,9 +28,6 @@ impl CheckFee { } } -pub type LegacyUncheckedTransaction = - transaction::UncheckedTransaction; - /// Unchecked transaction type as expected by this application. pub type UncheckedTransaction = transaction::UncheckedTransaction; diff --git a/src/components/contracts/primitives/wasm/src/wasm.rs b/src/components/contracts/primitives/wasm/src/wasm.rs index d79326c870..846f97c04f 100644 --- a/src/components/contracts/primitives/wasm/src/wasm.rs +++ b/src/components/contracts/primitives/wasm/src/wasm.rs @@ -1,15 +1,11 @@ #![allow(clippy::unused_unit)] use core::fmt::Display; -use ethereum::{ - LegacyTransactionMessage, TransactionV0 as LegacyTransaction, - TransactionV2 as Transaction, -}; +use ethereum::TransactionV2 as Transaction; use ethereum_types::{H160, H256}; use fp_types::{ actions::{ethereum::Action as EthAction, Action}, assemble::UncheckedTransaction, - crypto::secp256k1_ecdsa_recover, }; use fp_utils::tx::EvmRawTxWrapper; use ruc::{d, err::RucResult}; @@ -21,21 +17,6 @@ pub(crate) fn error_to_jsvalue(e: T) -> JsValue { JsValue::from_str(&e.to_string()) } -#[inline(always)] -pub fn legacy_recover_signer(transaction: &LegacyTransaction) -> Option { - let mut sig = [0u8; 65]; - let mut msg = [0u8; 32]; - sig[0..32].copy_from_slice(&transaction.signature.r()[..]); - sig[32..64].copy_from_slice(&transaction.signature.s()[..]); - sig[64] = transaction.signature.standard_v(); - msg.copy_from_slice(&LegacyTransactionMessage::from(transaction.clone()).hash()[..]); - - let pubkey = secp256k1_ecdsa_recover(&sig, &msg).ok()?; - Some(H160::from(H256::from_slice( - Keccak256::digest(pubkey).as_slice(), - ))) -} - #[inline(always)] pub fn recover_signer(transaction: &Transaction) -> Option { let mut sig = [0u8; 65]; @@ -111,33 +92,10 @@ pub fn evm_tx_hash(raw_tx: String) -> Result { #[allow(missing_docs)] mod test { use super::*; - use fp_types::{ - actions::{ - ethereum::Action as EthAction, ethereum::LegacyAction as LegacyEthAction, - Action, LegacyAction, - }, - assemble::LegacyUncheckedTransaction, - }; + use fp_types::actions::{ethereum::Action as EthAction, Action}; #[test] fn recover_signer_works() { - let raw_tx = String::from("ZXZtOnsic2lnbmF0dXJlIjpudWxsLCJmdW5jdGlvbiI6eyJFdGhlcmV1bSI6eyJUcmFuc2FjdCI6eyJub25jZSI6IjB4MSIsImdhc19wcmljZSI6IjB4MTc0ODc2ZTgwMCIsImdhc19saW1pdCI6IjB4NTIwOCIsImFjdGlvbiI6eyJDYWxsIjoiMHgyYWQzMjg0NmM2ZGQyZmZkM2VkYWRiZTUxY2Q1YWUwNGFhNWU1NzVlIn0sInZhbHVlIjoiMHg1NmJjNzVlMmQ2MzEwMDAwMCIsImlucHV0IjpbXSwic2lnbmF0dXJlIjp7InYiOjEwODIsInIiOiIweGY4YWVmN2Y4MDUzZDg5ZmVlMzk1MGM0ZDcwMjA4MGJmM2E4MDcyYmVkNWQ4NGEzYWYxOWEzNjAwODFiNjM2YTIiLCJzIjoiMHgyOTYyOTlhOGYyNDMwYjg2ZmQzZWI5NzZlYWJjNzMwYWMxY2ZiYmJlMzZlYjY5ZWFlMzM4Y2ZmMzNjNGE5OGMxIn19fX19"); - let tx_bytes = base64::decode_config(raw_tx, base64::URL_SAFE).unwrap(); - let evm_tx = EvmRawTxWrapper::unwrap(&tx_bytes).unwrap(); - let unchecked_tx: LegacyUncheckedTransaction<()> = - serde_json::from_slice(evm_tx).unwrap(); - if let LegacyAction::Ethereum(LegacyEthAction::Transact(tx)) = - unchecked_tx.function - { - let signer = legacy_recover_signer(&tx).unwrap(); - assert_eq!( - format!("{:?}", signer), - "0xa5225cbee5052100ec2d2d94aa6d258558073757" - ); - } else { - panic!() - } - let raw_tx = String::from("ZXZtOnsiRXRoZXJldW0iOnsiVHJhbnNhY3QiOnsiRUlQMTU1OSI6eyJjaGFpbl9pZCI6MjE1Miwibm9uY2UiOiIweDEiLCJtYXhfcHJpb3JpdHlfZmVlX3Blcl9nYXMiOiIweDI3MTAiLCJtYXhfZmVlX3Blcl9nYXMiOiIweDI3MTAiLCJnYXNfbGltaXQiOiIweDI3MTAiLCJhY3Rpb24iOnsiQ2FsbCI6IjB4MmFkMzI4NDZjNmRkMmZmZDNlZGFkYmU1MWNkNWFlMDRhYTVlNTc1ZSJ9LCJ2YWx1ZSI6IjB4MjcxMCIsImlucHV0IjpbXSwiYWNjZXNzX2xpc3QiOltdLCJvZGRfeV9wYXJpdHkiOmZhbHNlLCJyIjoiMHhmOGFlZjdmODA1M2Q4OWZlZTM5NTBjNGQ3MDIwODBiZjNhODA3MmJlZDVkODRhM2FmMTlhMzYwMDgxYjYzNmEyIiwicyI6IjB4Mjk2Mjk5YThmMjQzMGI4NmZkM2ViOTc2ZWFiYzczMGFjMWNmYmJiZTM2ZWI2OWVhZTMzOGNmZjMzYzRhOThjMSJ9fX19"); let tx_bytes = base64::decode_config(raw_tx, base64::URL_SAFE).unwrap(); let evm_tx = EvmRawTxWrapper::unwrap(&tx_bytes).unwrap(); @@ -154,18 +112,17 @@ mod test { } #[test] + // LegacyTransaction fn evm_tx_hash_works() { - let raw_tx = String::from("eyJzaWduYXR1cmUiOm51bGwsImZ1bmN0aW9uIjp7IkV0aGVyZXVtIjp7IlRyYW5zYWN0Ijp7Im5vbmNlIjoiMHg5IiwiZ2FzX3ByaWNlIjoiMHhlOGQ0YTUxMDAwIiwiZ2FzX2xpbWl0IjoiMHg1MjA4IiwiYWN0aW9uIjp7IkNhbGwiOiIweGE1MjI1Y2JlZTUwNTIxMDBlYzJkMmQ5NGFhNmQyNTg1NTgwNzM3NTcifSwidmFsdWUiOiIweDk4YTdkOWI4MzE0YzAwMDAiLCJpbnB1dCI6W10sInNpZ25hdHVyZSI6eyJ2IjoxMDgyLCJyIjoiMHg4MDBjZjQ5ZTAzMmJhYzY4MjY3MzdhZGJhZDEzN2Y0MTk5OTRjNjgxZWE1ZDUyYjliMGJhZDJmNDAyYjMwMTI0IiwicyI6IjB4Mjk1Mjc3ZWY2NTYzNDAwY2VkNjFiODhkM2ZiNGM3YjMyY2NkNTcwYThiOWJiOGNiYmUyNTkyMTRhYjdkZTI1YSJ9fX19fQ=="); + let raw_tx = String::from("eyJzaWduYXR1cmUiOm51bGwsImZ1bmN0aW9uIjp7IkV0aGVyZXVtIjp7IlRyYW5zYWN0Ijp7IkxlZ2FjeSI6eyJub25jZSI6IjB4MCIsImdhc19wcmljZSI6IjB4MjU0MGJlNDAwIiwiZ2FzX2xpbWl0IjoiMHgxMDAwMDAiLCJhY3Rpb24iOnsiQ2FsbCI6IjB4MzMyNWE3ODQyNWYxN2E3ZTQ4N2ViNTY2NmIyYmZkOTNhYmIwNmM3MCJ9LCJ2YWx1ZSI6IjB4YSIsImlucHV0IjpbXSwic2lnbmF0dXJlIjp7InYiOjQzNDAsInIiOiIweDZiMjBjNzIzNTEzOTk4ZThmYTQ4NWM1MmI4ZjlhZTRmZDdiMWUwYmQwZGZiNzk4NTIzMThiMGMxMDBlOTFmNWUiLCJzIjoiMHg0ZDRjOGMxZjJlMTdjMDJjNGE4OTZlMjYyMTI3YjhiZDZlYmZkNWY1YTc1NWEzZTkyMjBjZmM2OGI4YzY5ZDVkIn19fX19fQ=="); let tx_bytes = base64::decode_config(raw_tx, base64::URL_SAFE).unwrap(); - let unchecked_tx: LegacyUncheckedTransaction<()> = + let unchecked_tx: UncheckedTransaction<()> = serde_json::from_slice(tx_bytes.as_slice()).unwrap(); - if let LegacyAction::Ethereum(LegacyEthAction::Transact(tx)) = - unchecked_tx.function - { + if let Action::Ethereum(EthAction::Transact(tx)) = unchecked_tx.function { let hash = H256::from_slice(Keccak256::digest(&rlp::encode(&tx)).as_slice()); assert_eq!( format!("{:?}", hash), - "0x0eeb0ff455b1b57b821634cf853e7247e584a675610f13097cc49c2022505df3" + "0x83901d025accca27ee53fdf1ee354f4437418731e0995ee031beb99499405d26" ); } else { panic!() diff --git a/src/components/contracts/rpc/src/eth.rs b/src/components/contracts/rpc/src/eth.rs index 88eec89c9a..c35ac11b79 100644 --- a/src/components/contracts/rpc/src/eth.rs +++ b/src/components/contracts/rpc/src/eth.rs @@ -26,7 +26,7 @@ use fp_traits::{ }; use fp_types::{ actions, - actions::evm::{Call, CallEip1559, Create, CreateEip1559}, + actions::evm::{Call, Create}, assemble::UncheckedTransaction, }; use fp_utils::ecdsa::SecpPair; @@ -394,14 +394,13 @@ impl EthApi for EthApiImpl { nonce, } = request; - let is_eip1559 = max_fee_per_gas.is_some() + let _is_eip1559 = max_fee_per_gas.is_some() && max_priority_fee_per_gas.is_some() && max_fee_per_gas.unwrap() > U256::from(0) && max_priority_fee_per_gas.unwrap() > U256::from(0); - let (gas_price, max_fee_per_gas, max_priority_fee_per_gas) = { - let details = - fee_details(gas_price, max_fee_per_gas, max_priority_fee_per_gas)?; + let (gas_price, _max_fee_per_gas, _max_priority_fee_per_gas) = { + let details = fee_details(gas_price, None, None)?; ( details.gas_price, details.max_fee_per_gas, @@ -441,105 +440,55 @@ impl EthApi for EthApiImpl { Vec::from(block.header.beneficiary.as_bytes()) } - if !is_eip1559 { - match to { - Some(to) => { - let call = Call { - source: from.unwrap_or_default(), - target: to, - input: data, - value: value.unwrap_or_default(), - gas_limit: gas_limit.as_u64(), - gas_price, - nonce, - }; - - let info = ::Runner::call( - &ctx, call, &config, - ) - .map_err(|err| { - internal_err(format!("evm runner call error: {:?}", err)) - })?; - debug!(target: "eth_rpc", "evm runner call result: {:?}", info); - - error_on_execution_failure(&info.exit_reason, &info.value)?; - - Ok(Bytes(info.value)) - } - None => { - let create = Create { - source: from.unwrap_or_default(), - init: data, - value: value.unwrap_or_default(), - gas_limit: gas_limit.as_u64(), - gas_price, - nonce, - }; + match to { + Some(to) => { + let call = Call { + source: from.unwrap_or_default(), + target: to, + input: data, + value: value.unwrap_or_default(), + gas_limit: gas_limit.as_u64(), + gas_price, + max_fee_per_gas: None, + max_priority_fee_per_gas: None, + nonce, + }; - let info = ::Runner::create( - &ctx, create, &config, - ) - .map_err(|err| { - internal_err(format!("evm runner create error: {:?}", err)) - })?; - debug!(target: "eth_rpc", "evm runner create result: {:?}", info); + let info = ::Runner::call( + &ctx, call, &config, + ) + .map_err(|err| { + internal_err(format!("evm runner call error: {:?}", err)) + })?; + debug!(target: "eth_rpc", "evm runner call result: {:?}", info); - error_on_execution_failure(&info.exit_reason, &[])?; + error_on_execution_failure(&info.exit_reason, &info.value)?; - Ok(Bytes(info.value[..].to_vec())) - } + Ok(Bytes(info.value)) } - } else { - match to { - Some(to) => { - let call = CallEip1559 { - source: from.unwrap_or_default(), - target: to, - input: data, - value: value.unwrap_or_default(), - gas_limit: gas_limit.as_u64(), - max_fee_per_gas, - max_priority_fee_per_gas, - nonce, - }; - - let info = - ::Runner::call_eip1559( - &ctx, call, &config, - ) - .map_err(|err| { - internal_err(format!("evm runner call error: {:?}", err)) - })?; - debug!(target: "eth_rpc", "evm runner call result: {:?}", info); - - error_on_execution_failure(&info.exit_reason, &info.value)?; - - Ok(Bytes(info.value)) - } - None => { - let create = CreateEip1559 { - source: from.unwrap_or_default(), - init: data, - value: value.unwrap_or_default(), - gas_limit: gas_limit.as_u64(), - max_fee_per_gas, - max_priority_fee_per_gas, - nonce, - }; + None => { + let create = Create { + source: from.unwrap_or_default(), + init: data, + value: value.unwrap_or_default(), + gas_limit: gas_limit.as_u64(), + gas_price, + max_fee_per_gas: None, + max_priority_fee_per_gas: None, + nonce, + }; - let info = - ::Runner::create_eip1559( - &ctx, create, &config, - ) - .map_err(|err| { - internal_err(format!("evm runner create error: {:?}", err)) - })?; - debug!(target: "eth_rpc", "evm runner create result: {:?}", info); + let info = ::Runner::create( + &ctx, create, &config, + ) + .map_err(|err| { + internal_err(format!("evm runner create error: {:?}", err)) + })?; + debug!(target: "eth_rpc", "evm runner create result: {:?}", info); - error_on_execution_failure(&info.exit_reason, &[])?; + error_on_execution_failure(&info.exit_reason, &[])?; - Ok(Bytes(info.value[..].to_vec())) - } + Ok(Bytes(info.value[..].to_vec())) } } }); @@ -923,17 +872,13 @@ impl EthApi for EthApiImpl { ) -> BoxFuture> { debug!(target: "eth_rpc", "estimate_gas, block number {:?} request:{:?}", number, request); - let is_eip1559 = request.max_fee_per_gas.is_some() + let _is_eip1559 = request.max_fee_per_gas.is_some() && request.max_priority_fee_per_gas.is_some() && request.max_fee_per_gas.unwrap() > U256::from(0) && request.max_priority_fee_per_gas.unwrap() > U256::from(0); - let (gas_price, max_fee_per_gas, max_priority_fee_per_gas) = { - if let Ok(details) = fee_details( - request.gas_price, - request.max_fee_per_gas, - request.max_priority_fee_per_gas, - ) { + let (gas_price, _max_fee_per_gas, _max_priority_fee_per_gas) = { + if let Ok(details) = fee_details(request.gas_price, None, None) { ( details.gas_price, details.max_fee_per_gas, @@ -1059,123 +1004,59 @@ impl EthApi for EthApiImpl { let mut config = ::config().clone(); config.estimate = true; - if !is_eip1559 { - match to { - Some(to) => { - let call = Call { - source: from.unwrap_or_default(), - target: to, - input: data.map(|d| d.0).unwrap_or_default(), - value: value.unwrap_or_default(), - gas_limit, - gas_price, - nonce, - }; - - let info = - ::Runner::call( - &ctx, call, &config, - ) - .map_err(|err| { - internal_err(format!( - "evm runner call error: {:?}", - err - )) - })?; - debug!(target: "eth_rpc", "evm runner call result: {:?}", info); + match to { + Some(to) => { + let call = Call { + source: from.unwrap_or_default(), + target: to, + input: data.map(|d| d.0).unwrap_or_default(), + value: value.unwrap_or_default(), + gas_limit, + gas_price, + max_fee_per_gas: None, + max_priority_fee_per_gas: None, + nonce, + }; - Ok(ExecuteResult { - data: info.value, - exit_reason: info.exit_reason, - used_gas: info.used_gas, - }) - } - None => { - let create = Create { - source: from.unwrap_or_default(), - init: data.map(|d| d.0).unwrap_or_default(), - value: value.unwrap_or_default(), - gas_limit, - gas_price, - nonce, - }; - - let info = - ::Runner::create( - &ctx, create, &config, - ) - .map_err(|err| { - internal_err(format!( - "evm runner create error: {:?}", - err - )) - })?; - debug!(target: "eth_rpc", "evm runner create result: {:?}", info); + let info = ::Runner::call( + &ctx, call, &config, + ) + .map_err(|err| { + internal_err(format!("evm runner call error: {:?}", err)) + })?; + debug!(target: "eth_rpc", "evm runner call result: {:?}", info); - Ok(ExecuteResult { - data: vec![], - exit_reason: info.exit_reason, - used_gas: info.used_gas, - }) - } + Ok(ExecuteResult { + data: info.value, + exit_reason: info.exit_reason, + used_gas: info.used_gas, + }) } - } else { - match to { - Some(to) => { - let call = CallEip1559 { - source: from.unwrap_or_default(), - target: to, - input: data.map(|d| d.0).unwrap_or_default(), - value: value.unwrap_or_default(), - gas_limit, - max_fee_per_gas, - max_priority_fee_per_gas, - nonce, - }; - - let info = - ::Runner::call_eip1559( - &ctx, call, &config, - ) - .map_err(|err| { - internal_err(format!("evm runner call error: {:?}", err)) - })?; - debug!(target: "eth_rpc", "evm runner call result: {:?}", info); - - Ok(ExecuteResult { - data: info.value, - exit_reason: info.exit_reason, - used_gas: info.used_gas, - }) - } - None => { - let create = CreateEip1559 { - source: from.unwrap_or_default(), - init: data.map(|d| d.0).unwrap_or_default(), - value: value.unwrap_or_default(), - gas_limit, - max_fee_per_gas, - max_priority_fee_per_gas, - nonce, - }; - - let info = ::Runner::create_eip1559( - &ctx, create, &config, - ) - .map_err(|err| { - internal_err(format!( - "evm runner create error: {:?}", - err - )) - })?; - debug!(target: "eth_rpc", "evm runner create result: {:?}", info); - - Ok(ExecuteResult { - data: vec![], - exit_reason: info.exit_reason, - used_gas: info.used_gas, - }) - } + None => { + let create = Create { + source: from.unwrap_or_default(), + init: data.map(|d| d.0).unwrap_or_default(), + value: value.unwrap_or_default(), + gas_limit, + gas_price, + max_fee_per_gas: None, + max_priority_fee_per_gas: None, + nonce, + }; + + let info = ::Runner::create( + &ctx, create, &config, + ) + .map_err(|err| { + internal_err(format!("evm runner create error: {:?}", err)) + })?; + debug!(target: "eth_rpc", "evm runner create result: {:?}", info); + + Ok(ExecuteResult { + data: vec![], + exit_reason: info.exit_reason, + used_gas: info.used_gas, + }) } } }; @@ -1257,24 +1138,14 @@ impl EthApi for EthApiImpl { } } - let is_eip1559 = !matches!( - &block.transactions[index], - EthereumTransaction::Legacy(_) - ); - // match &block.transactions[index] { - // EthereumTransaction::Legacy(_) => false, - // _ => true, - // }; - let base_fee = account_base_app.read().base_fee(id); - Ok(Some(transaction_build( + Ok(transaction_build( block.transactions[index].clone(), Some(block), Some(statuses[index].clone()), - is_eip1559, base_fee, - ))) + )) } _ => Ok(None), } @@ -1318,18 +1189,12 @@ impl EthApi for EthApiImpl { return Ok(None); } - let is_eip1559 = !matches!( - &block.transactions[index], - EthereumTransaction::Legacy(_) - ); - - Ok(Some(transaction_build( + Ok(transaction_build( block.transactions[index].clone(), Some(block), Some(statuses[index].clone()), - is_eip1559, base_fee, - ))) + )) } _ => Ok(None), } @@ -1365,24 +1230,14 @@ impl EthApi for EthApiImpl { return Ok(None); } - let is_eip1559 = !matches!( - &block.transactions[index], - EthereumTransaction::Legacy(_) - ); - // match &block.transactions[index] { - // EthereumTransaction::Legacy(_) => true, - // _ => false, - // }; - let base_fee = account_base_app.read().base_fee(id); - Ok(Some(transaction_build( + Ok(transaction_build( block.transactions[index].clone(), Some(block), Some(statuses[index].clone()), - is_eip1559, base_fee, - ))) + )) } _ => Ok(None), } @@ -1712,21 +1567,11 @@ fn rich_block_build( .transactions .iter() .enumerate() - .map(|(index, transaction)| { - let is_eip1559 = !matches!( - &block.transactions[index], - EthereumTransaction::Legacy(_) - ); - // match &transaction { - // EthereumTransaction::Legacy(_) => true, - // _ => false, - // }; - + .filter_map(|(index, transaction)| { transaction_build( transaction.clone(), Some(block.clone()), Some(statuses[index].clone().unwrap_or_default()), - is_eip1559, base_fee, ) }) @@ -1760,27 +1605,30 @@ fn transaction_build( ethereum_transaction: EthereumTransaction, block: Option>, status: Option, - is_eip1559: bool, base_fee: Option, -) -> Transaction { +) -> Option { let mut transaction: Transaction = ethereum_transaction.clone().into(); - if let EthereumTransaction::EIP1559(_) = ethereum_transaction { - if block.is_none() && status.is_none() { - transaction.gas_price = transaction.max_fee_per_gas; - } else { - let base_fee = base_fee.unwrap_or(U256::zero()); - let max_priority_fee_per_gas = - transaction.max_priority_fee_per_gas.unwrap_or(U256::zero()); - transaction.gas_price = Some( - base_fee - .checked_add(max_priority_fee_per_gas) - .unwrap_or_else(U256::max_value), - ); + match ðereum_transaction { + EthereumTransaction::EIP1559(_) => { + if block.is_none() && status.is_none() { + transaction.gas_price = transaction.max_fee_per_gas; + } else { + let base_fee = base_fee.unwrap_or(U256::zero()); + let max_priority_fee_per_gas = + transaction.max_priority_fee_per_gas.unwrap_or(U256::zero()); + transaction.gas_price = Some( + base_fee + .checked_add(max_priority_fee_per_gas) + .unwrap_or_else(U256::max_value), + ); + } + } + EthereumTransaction::Legacy(_) => { + transaction.max_fee_per_gas = None; + transaction.max_priority_fee_per_gas = None; } - } else if !is_eip1559 { - transaction.max_fee_per_gas = None; - transaction.max_priority_fee_per_gas = None; + _ => return None, } let pubkey = match public_key(ðereum_transaction) { @@ -1851,42 +1699,14 @@ fn transaction_build( EthereumTransaction::EIP1559(t) => { H256::from_slice(Keccak256::digest(&rlp::encode(&t)).as_slice()) } - EthereumTransaction::EIP2930(t) => { - H256::from_slice(Keccak256::digest(&rlp::encode(&t)).as_slice()) - } + EthereumTransaction::EIP2930(_) => return None, } }; - // // Block hash. - // transaction.block_hash = ; - // // Block number. - // transaction.block_number = ; - // // Transaction index. - // transaction.transaction_index = ; - // // From. - // transaction.from; - // // To. - // transaction.to; - // // Creates. - // transaction.creates; - // // Public key. - // transaction.public_key; - - transaction + Some(transaction) } pub fn public_key(transaction: &EthereumTransaction) -> ruc::Result<[u8; 64]> { - // let mut sig = [0u8; 65]; - // let mut msg = [0u8; 32]; - // sig[0..32].copy_from_slice(&transaction.signature.r()[..]); - // sig[32..64].copy_from_slice(&transaction.signature.s()[..]); - // sig[64] = transaction.signature.standard_v(); - // msg.copy_from_slice( - // &EthereumTransactionMessage::from(transaction.clone()).hash()[..], - // ); - - // fp_types::crypto::secp256k1_ecdsa_recover(&sig, &msg) - let mut sig = [0u8; 65]; let mut msg = [0u8; 32]; match transaction {