From 8b6598633819a193f6c1d36f22559dc31b2d39d6 Mon Sep 17 00:00:00 2001 From: Dmitry Lavrenov Date: Sun, 18 Jun 2023 11:21:56 +0300 Subject: [PATCH] Move NativeSystemAccountProvider to pallet-evm --- frame/ethereum/src/mock.rs | 2 +- frame/evm/precompile/dispatch/src/mock.rs | 2 +- frame/evm/src/lib.rs | 24 +++++++++++++++++++++++ frame/evm/src/mock.rs | 2 +- primitives/evm/src/account_provider.rs | 23 ---------------------- primitives/evm/src/lib.rs | 2 +- 6 files changed, 28 insertions(+), 27 deletions(-) diff --git a/frame/ethereum/src/mock.rs b/frame/ethereum/src/mock.rs index 9b313f2799..9614fb8a0c 100644 --- a/frame/ethereum/src/mock.rs +++ b/frame/ethereum/src/mock.rs @@ -152,7 +152,7 @@ impl AddressMapping for HashedAddressMapping { } impl pallet_evm::Config for Test { - type AccountProvider = fp_evm::NativeSystemAccountProvider; + type AccountProvider = pallet_evm::NativeSystemAccountProvider; type FeeCalculator = FixedGasPrice; type GasWeightMapping = pallet_evm::FixedGasWeightMapping; type WeightPerGas = WeightPerGas; diff --git a/frame/evm/precompile/dispatch/src/mock.rs b/frame/evm/precompile/dispatch/src/mock.rs index d5202e906c..7163d8ea2d 100644 --- a/frame/evm/precompile/dispatch/src/mock.rs +++ b/frame/evm/precompile/dispatch/src/mock.rs @@ -139,7 +139,7 @@ parameter_types! { pub WeightPerGas: Weight = Weight::from_ref_time(20_000); } impl pallet_evm::Config for Test { - type AccountProvider = fp_evm::NativeSystemAccountProvider; + type AccountProvider = pallet_evm::NativeSystemAccountProvider; type FeeCalculator = FixedGasPrice; type GasWeightMapping = pallet_evm::FixedGasWeightMapping; type WeightPerGas = WeightPerGas; diff --git a/frame/evm/src/lib.rs b/frame/evm/src/lib.rs index f1d95fcda3..19b2cea2d2 100644 --- a/frame/evm/src/lib.rs +++ b/frame/evm/src/lib.rs @@ -916,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/mock.rs b/frame/evm/src/mock.rs index 31261c5d77..ad886616db 100644 --- a/frame/evm/src/mock.rs +++ b/frame/evm/src/mock.rs @@ -132,7 +132,7 @@ parameter_types! { pub MockPrecompiles: MockPrecompileSet = MockPrecompileSet; } impl crate::Config for Test { - type AccountProvider = fp_evm::NativeSystemAccountProvider; + type AccountProvider = crate::NativeSystemAccountProvider; type FeeCalculator = FixedGasPrice; type GasWeightMapping = crate::FixedGasWeightMapping; type WeightPerGas = WeightPerGas; diff --git a/primitives/evm/src/account_provider.rs b/primitives/evm/src/account_provider.rs index 7be007f32c..4fbd07530b 100644 --- a/primitives/evm/src/account_provider.rs +++ b/primitives/evm/src/account_provider.rs @@ -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 = 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/primitives/evm/src/lib.rs b/primitives/evm/src/lib.rs index 4b241b1da0..60b320d1fc 100644 --- a/primitives/evm/src/lib.rs +++ b/primitives/evm/src/lib.rs @@ -35,7 +35,7 @@ pub use evm::{ }; pub use self::{ - account_provider::{AccountProvider, NativeSystemAccountProvider}, + account_provider::AccountProvider, precompile::{ Context, ExitError, ExitRevert, ExitSucceed, LinearCostPrecompile, Precompile, PrecompileFailure, PrecompileHandle, PrecompileOutput, PrecompileResult, PrecompileSet,