Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename FullAccount into Account at pallet-evm-system #69

Merged
merged 1 commit into from
Jun 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions frame/evm-system/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ pub mod pallet {
/// The full account information for a particular account ID.
#[pallet::storage]
#[pallet::getter(fn full_account)]
pub type FullAccount<T: Config> = StorageMap<
pub type Account<T: Config> = StorageMap<
_,
Blake2_128Concat,
<T as Config>::AccountId,
Expand Down Expand Up @@ -125,7 +125,7 @@ pub mod pallet {
impl<T: Config> Pallet<T> {
/// Check the account existence.
pub fn account_exists(who: &<T as Config>::AccountId) -> bool {
FullAccount::<T>::contains_key(who)
Account::<T>::contains_key(who)
}

/// An account is being created.
Expand All @@ -142,12 +142,12 @@ impl<T: Config> Pallet<T> {

/// Retrieve the account transaction counter from storage.
pub fn account_nonce(who: &<T as Config>::AccountId) -> <T as Config>::Index {
FullAccount::<T>::get(who).nonce
Account::<T>::get(who).nonce
}

/// Increment a particular account's nonce by 1.
pub fn inc_account_nonce(who: &<T as Config>::AccountId) {
FullAccount::<T>::mutate(who, |a| a.nonce += <T as pallet::Config>::Index::one());
Account::<T>::mutate(who, |a| a.nonce += <T as pallet::Config>::Index::one());
}

/// Create an account.
Expand All @@ -156,7 +156,7 @@ impl<T: Config> Pallet<T> {
return Err(Error::<T>::AccountAlreadyExist.into());
}

FullAccount::<T>::insert(who.clone(), AccountInfo::<_, _>::default());
Account::<T>::insert(who.clone(), AccountInfo::<_, _>::default());
Self::on_created_account(who.clone());
Ok(())
}
Expand All @@ -167,29 +167,29 @@ impl<T: Config> Pallet<T> {
return Err(Error::<T>::AccountNotExist.into());
}

FullAccount::<T>::remove(who);
Account::<T>::remove(who);
Self::on_killed_account(who.clone());
Ok(())
}
}

impl<T: Config> StoredMap<<T as Config>::AccountId, <T as Config>::AccountData> for Pallet<T> {
fn get(k: &<T as Config>::AccountId) -> <T as Config>::AccountData {
FullAccount::<T>::get(k).data
Account::<T>::get(k).data
}

fn try_mutate_exists<R, E: From<DispatchError>>(
k: &<T as Config>::AccountId,
f: impl FnOnce(&mut Option<<T as Config>::AccountData>) -> Result<R, E>,
) -> Result<R, E> {
let mut maybe_account_data = if Self::account_exists(k) {
Some(FullAccount::<T>::get(k).data)
Some(Account::<T>::get(k).data)
} else {
None
};
let r = f(&mut maybe_account_data)?;
if let Some(account_data) = maybe_account_data {
FullAccount::<T>::mutate(k, |a| a.data = account_data);
Account::<T>::mutate(k, |a| a.data = account_data);
}
Ok(r)
}
Expand Down
4 changes: 2 additions & 2 deletions frame/evm-system/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ fn create_account_fails() {
new_test_ext().execute_with(|| {
// Prepare test data.
let account_id = H160::from_str("1000000000000000000000000000000000000001").unwrap();
<FullAccount<Test>>::insert(account_id.clone(), AccountInfo::<_, _>::default());
<Account<Test>>::insert(account_id.clone(), AccountInfo::<_, _>::default());

// Invoke the function under test.
assert_noop!(
Expand All @@ -65,7 +65,7 @@ fn remove_account_works() {
new_test_ext().execute_with(|| {
// Prepare test data.
let account_id = H160::from_str("1000000000000000000000000000000000000001").unwrap();
<FullAccount<Test>>::insert(account_id.clone(), AccountInfo::<_, _>::default());
<Account<Test>>::insert(account_id.clone(), AccountInfo::<_, _>::default());

// Set block number to enable events.
System::set_block_number(1);
Expand Down