diff --git a/Cargo.lock b/Cargo.lock index 87cb0af0b2..0de6bf9e5d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4933,6 +4933,7 @@ dependencies = [ name = "pallet-evm-system" version = "1.0.0-dev" dependencies = [ + "fp-evm", "frame-support", "frame-system", "log", diff --git a/frame/evm-system/Cargo.toml b/frame/evm-system/Cargo.toml index 235931bd08..0327d9f3bc 100644 --- a/frame/evm-system/Cargo.toml +++ b/frame/evm-system/Cargo.toml @@ -19,6 +19,8 @@ frame-support = { workspace = true } frame-system = { workspace = true } sp-runtime = { workspace = true } sp-std = { workspace = true } +# Frontier +fp-evm = { workspace = true } [dev-dependencies] mockall = "0.11" @@ -36,6 +38,8 @@ std = [ "frame-system/std", "sp-runtime/std", "sp-std/std", + # Frontier + "fp-evm/std", ] try-runtime = [ "frame-support/try-runtime", diff --git a/frame/evm-system/src/lib.rs b/frame/evm-system/src/lib.rs index ad38522983..ad2a6b18d0 100644 --- a/frame/evm-system/src/lib.rs +++ b/frame/evm-system/src/lib.rs @@ -211,6 +211,27 @@ impl StoredMap<::AccountId, ::AccountData> } } +impl fp_evm::AccountProvider for Pallet { + type AccountId = ::AccountId; + type Index = ::Index; + + fn create_account(who: &Self::AccountId) { + let _ = Self::create_account(who); + } + + fn remove_account(who: &Self::AccountId) { + let _ = Self::remove_account(who); + } + + fn account_nonce(who: &Self::AccountId) -> Self::Index { + Self::account_nonce(who) + } + + fn inc_account_nonce(who: &Self::AccountId) { + Self::inc_account_nonce(who); + } +} + /// Interface to handle account creation. pub trait OnNewAccount { /// A new account `who` has been registered. diff --git a/frame/evm/src/lib.rs b/frame/evm/src/lib.rs index 76bfb498a2..19b2cea2d2 100644 --- a/frame/evm/src/lib.rs +++ b/frame/evm/src/lib.rs @@ -64,9 +64,6 @@ pub mod runner; #[cfg(test)] mod tests; -mod account_provider; -pub use account_provider::{AccountProvider, NativeSystemAccountProvider}; - use frame_support::{ dispatch::{DispatchResultWithPostInfo, Pays, PostDispatchInfo}, traits::{ @@ -79,7 +76,7 @@ use frame_system::RawOrigin; use impl_trait_for_tuples::impl_for_tuples; use sp_core::{Hasher, H160, H256, U256}; use sp_runtime::{ - traits::{BadOrigin, Saturating, UniqueSaturatedInto, AtLeast32Bit, Zero}, + traits::{BadOrigin, Saturating, UniqueSaturatedInto, Zero}, AccountId32, DispatchErrorWithPostInfo, }; use sp_std::{cmp::min, vec::Vec}; @@ -90,9 +87,9 @@ pub use evm::{ #[cfg(feature = "std")] use fp_evm::GenesisAccount; pub use fp_evm::{ - Account, CallInfo, CreateInfo, ExecutionInfo, FeeCalculator, InvalidEvmTransactionError, - LinearCostPrecompile, Log, Precompile, PrecompileFailure, PrecompileHandle, PrecompileOutput, - PrecompileResult, PrecompileSet, Vicinity, + Account, AccountProvider, CallInfo, CreateInfo, ExecutionInfo, FeeCalculator, + InvalidEvmTransactionError, LinearCostPrecompile, Log, Precompile, PrecompileFailure, + PrecompileHandle, PrecompileOutput, PrecompileResult, PrecompileSet, Vicinity, }; pub use self::{ @@ -919,3 +916,27 @@ impl OnCreate for Tuple { )*) } } + +/// Native system account provider that `frame_system` provides. +pub struct NativeSystemAccountProvider(sp_std::marker::PhantomData); + +impl AccountProvider for NativeSystemAccountProvider { + type AccountId = T::AccountId; + type Index = T::Index; + + fn account_nonce(who: &Self::AccountId) -> Self::Index { + frame_system::Pallet::::account_nonce(&who) + } + + fn inc_account_nonce(who: &Self::AccountId) { + frame_system::Pallet::::inc_account_nonce(&who) + } + + fn create_account(who: &Self::AccountId) { + let _ = frame_system::Pallet::::inc_sufficients(&who); + } + fn remove_account(who: &Self::AccountId) { + let _ = frame_system::Pallet::::dec_sufficients(&who); + } +} + diff --git a/frame/evm/src/account_provider.rs b/primitives/evm/src/account_provider.rs similarity index 66% rename from frame/evm/src/account_provider.rs rename to primitives/evm/src/account_provider.rs index 69484222cf..4fbd07530b 100644 --- a/frame/evm/src/account_provider.rs +++ b/primitives/evm/src/account_provider.rs @@ -1,6 +1,6 @@ //! Custom account provider logic. -use super::*; +use sp_runtime::traits::AtLeast32Bit; /// The account provider interface abstraction layer. /// @@ -39,26 +39,3 @@ pub trait AccountProvider { /// Incremented with each new transaction submitted by the account. fn inc_account_nonce(who: &Self::AccountId); } - -/// Native system account provider that `frame_system` provides. -pub struct NativeSystemAccountProvider(sp_std::marker::PhantomData); - -impl AccountProvider for NativeSystemAccountProvider { - type AccountId = ::AccountId; - type Index = ::Index; - - fn account_nonce(who: &Self::AccountId) -> Self::Index { - frame_system::Pallet::::account_nonce(&who) - } - - fn inc_account_nonce(who: &Self::AccountId) { - frame_system::Pallet::::inc_account_nonce(&who) - } - - fn create_account(who: &Self::AccountId) { - let _ = frame_system::Pallet::::inc_sufficients(&who); - } - fn remove_account(who: &Self::AccountId) { - let _ = frame_system::Pallet::::dec_sufficients(&who); - } -} diff --git a/primitives/evm/src/lib.rs b/primitives/evm/src/lib.rs index 43e0929cda..60b320d1fc 100644 --- a/primitives/evm/src/lib.rs +++ b/primitives/evm/src/lib.rs @@ -17,6 +17,7 @@ #![cfg_attr(not(feature = "std"), no_std)] +mod account_provider; mod precompile; mod validation; @@ -34,6 +35,7 @@ pub use evm::{ }; pub use self::{ + account_provider::AccountProvider, precompile::{ Context, ExitError, ExitRevert, ExitSucceed, LinearCostPrecompile, Precompile, PrecompileFailure, PrecompileHandle, PrecompileOutput, PrecompileResult, PrecompileSet,