diff --git a/frame/evm-system/src/lib.rs b/frame/evm-system/src/lib.rs index 0910a82ee5..919d298d9d 100644 --- a/frame/evm-system/src/lib.rs +++ b/frame/evm-system/src/lib.rs @@ -20,7 +20,8 @@ // Ensure we're `no_std` when compiling for Wasm. #![cfg_attr(not(feature = "std"), no_std)] -use sp_runtime::{traits::One, RuntimeDebug, DispatchResult}; +use frame_support::traits::StoredMap; +use sp_runtime::{traits::One, RuntimeDebug, DispatchResult, DispatchError}; use scale_codec::{Encode, Decode, MaxEncodedLen, FullCodec}; use scale_info::TypeInfo; @@ -172,6 +173,28 @@ impl Pallet { } } +impl StoredMap<::AccountId, ::AccountData> for Pallet { + fn get(k: &::AccountId) -> ::AccountData { + FullAccount::::get(k).data + } + + fn try_mutate_exists>( + k: &::AccountId, + f: impl FnOnce(&mut Option<::AccountData>) -> Result, + ) -> Result { + let mut maybe_account_data = if Self::account_exists(k) { + Some(FullAccount::::get(k).data) + } else { + None + }; + let r = f(&mut maybe_account_data)?; + if let Some(account_data) = maybe_account_data { + FullAccount::::mutate(k, |a| a.data = account_data); + } + Ok(r) + } +} + /// Interface to handle account creation. pub trait OnNewAccount { /// A new account `who` has been registered.