Skip to content

Commit

Permalink
feat: Add clearing addresses on killed account (#87)
Browse files Browse the repository at this point in the history
  • Loading branch information
conr2d authored Oct 28, 2024
1 parent eb8db91 commit 96aca0c
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion frame/babel/src/extensions/unify_account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@

use crate::traits::AccountIdProvider;
use core::marker::PhantomData;
use frame_support::traits::tokens::{fungible, Fortitude, Preservation};
use frame_support::traits::{
tokens::{fungible, Fortitude, Preservation},
OnKilledAccount as OnKilledAccountT,
};
use np_babel::VarAddress;
use pallet_multimap::traits::UniqueMultimap;
use parity_scale_codec::{Decode, Encode, MaxEncodedLen};
Expand Down Expand Up @@ -182,6 +185,14 @@ where
}
}

pub struct OnKilledAccount<T: Config>(PhantomData<T>);

impl<T: Config> OnKilledAccountT<T::AccountId> for OnKilledAccount<T> {
fn on_killed_account(who: &T::AccountId) {
T::AddressMap::remove_all(who);
}
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down Expand Up @@ -222,4 +233,13 @@ mod tests {
assert_eq!(<MockConfig as Config>::AddressMap::find_key(nostr), Some(who));
}
}

#[test]
fn on_killed_account_works() {
let who = AccountId::from(dev_public());
let _ = UnifyAccount::<MockConfig>::unify_ecdsa(&who);
assert!(!<MockConfig as Config>::AddressMap::get(&who).is_empty());
OnKilledAccount::<MockConfig>::on_killed_account(&who);
assert!(<MockConfig as Config>::AddressMap::get(&who).is_empty());
}
}

0 comments on commit 96aca0c

Please sign in to comment.