From 037028a1bb07e96ecbc5c6ab8d03c4b680010da3 Mon Sep 17 00:00:00 2001 From: Ashutosh Varma Date: Tue, 26 Sep 2023 20:27:48 +0530 Subject: [PATCH] feat: inline `add_mappings()` method --- pallets/unified-accounts/src/lib.rs | 27 ++++++++++++++------------- pallets/unified-accounts/src/tests.rs | 5 +++-- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/pallets/unified-accounts/src/lib.rs b/pallets/unified-accounts/src/lib.rs index 19dbced7ba..102c87c881 100644 --- a/pallets/unified-accounts/src/lib.rs +++ b/pallets/unified-accounts/src/lib.rs @@ -206,7 +206,13 @@ pub mod pallet { } // create double mappings for the pair - Self::add_mappings(who, evm_address); + NativeToEvm::::insert(&evm_address, &who); + EvmToNative::::insert(&who, &evm_address); + + Self::deposit_event(Event::AccountClaimed { + account_id: who, + evm_address, + }); Ok(()) } @@ -226,17 +232,6 @@ pub mod pallet { } impl Pallet { - /// Add the given pair to create double mappings - fn add_mappings(account_id: T::AccountId, evm_address: EvmAddress) { - NativeToEvm::::insert(&evm_address, &account_id); - EvmToNative::::insert(&account_id, &evm_address); - - Self::deposit_event(Event::AccountClaimed { - account_id, - evm_address, - }); - } - /// Claim the default evm address fn do_claim_default_evm_address(account_id: T::AccountId) -> Result { ensure!( @@ -252,7 +247,13 @@ impl Pallet { Error::::AlreadyMapped ); // create double mappings for the pair with default evm address - Self::add_mappings(account_id, evm_address.clone()); + NativeToEvm::::insert(&evm_address, &account_id); + EvmToNative::::insert(&account_id, &evm_address); + + Self::deposit_event(Event::AccountClaimed { + account_id, + evm_address, + }); Ok(evm_address) } } diff --git a/pallets/unified-accounts/src/tests.rs b/pallets/unified-accounts/src/tests.rs index 4e92a04322..dfb96efc4e 100644 --- a/pallets/unified-accounts/src/tests.rs +++ b/pallets/unified-accounts/src/tests.rs @@ -227,9 +227,10 @@ fn account_default_claim_should_not_work_if_collision() { ExtBuilder::default().build().execute_with(|| { let bob_default_h160 = >::to_default_h160(&BOB); - // connect alice native with bob's default address + // create mapping of alice native with bob's default address // in real world possibilty of this happening is minuscule - UnifiedAccounts::add_mappings(ALICE, bob_default_h160); + NativeToEvm::::insert(&bob_default_h160, &ALICE); + EvmToNative::::insert(&ALICE, &bob_default_h160); // bob try claiming default h160 address, it should fail since alice already // has mapping in place with it.