diff --git a/frame/babel/src/lib.rs b/frame/babel/src/lib.rs index 62b3d2aa..8ec9be9b 100644 --- a/frame/babel/src/lib.rs +++ b/frame/babel/src/lib.rs @@ -54,7 +54,10 @@ pub mod pallet { }, }; use frame_system::{ensure_root, pallet_prelude::*}; - use np_multimap::traits::{UniqueMap, UniqueMultimap}; + use np_multimap::{ + traits::{UniqueMap, UniqueMultimap}, + Error as MapError, UniqueMapAdapter, UniqueMultimapAdapter, + }; use pallet_cosmos::{ types::{AssetIdOf, DenomOf}, AddressMapping as _, @@ -104,6 +107,34 @@ pub mod pallet { InvalidTransaction, } + /// Mapping from addresses to accounts. + pub type AddressMap = UniqueMultimapAdapter< + ::AccountId, + VarAddress, + AddressMapStorage, + AddressIndex, + ConstU32<{ VarAddress::variant_count() }>, + MapError, + >; + #[pallet::storage] + pub type AddressMapStorage = StorageMap< + _, + Twox64Concat, + T::AccountId, + BoundedBTreeSet>, + ValueQuery, + >; + #[pallet::storage] + pub type AddressIndex = StorageMap<_, Twox64Concat, VarAddress, T::AccountId>; + + /// Mapping from asset IDs to denoms. + pub type AssetMap = + UniqueMapAdapter, DenomOf, AssetMapStorage, AssetIndex, MapError>; + #[pallet::storage] + pub type AssetMapStorage = StorageMap<_, Twox64Concat, AssetIdOf, DenomOf>; + #[pallet::storage] + pub type AssetIndex = StorageMap<_, Twox64Concat, DenomOf, AssetIdOf>; + #[pallet::call] impl Pallet where diff --git a/frame/babel/src/mock.rs b/frame/babel/src/mock.rs index c640d856..f01bd0d1 100644 --- a/frame/babel/src/mock.rs +++ b/frame/babel/src/mock.rs @@ -43,6 +43,7 @@ use frame_support::{ }; use frame_system::EnsureRoot; use np_babel::cosmos::traits::CosmosHub; +use np_multimap::traits::UniqueMap; use np_runtime::{AccountId32, MultiSigner}; use pallet_cosmos::{ config_preludes::{MaxDenomLimit, NativeAssetId}, @@ -64,7 +65,6 @@ use pallet_cosmos_x_wasm::msgs::{ MsgStoreCodeHandler, MsgUpdateAdminHandler, }; use pallet_cosmwasm::instrument::CostRules; -use pallet_multimap::traits::UniqueMap; use sp_core::{ConstU128, Pair, H256}; use sp_runtime::{ traits::{IdentityLookup, TryConvert}, @@ -115,10 +115,6 @@ mod runtime { #[runtime::pallet_index(41)] pub type Cosmwasm = pallet_cosmwasm; - #[runtime::pallet_index(50)] - pub type AddressMap = pallet_multimap; - #[runtime::pallet_index(51)] - pub type AssetMap = pallet_multimap; #[runtime::pallet_index(100)] pub type Babel = frame_babel; } @@ -198,7 +194,7 @@ impl TryConvert for AssetToDenom { } else { let denom_raw: BoundedVec = denom.as_bytes().to_vec().try_into().map_err(|_| denom.clone())?; - AssetMap::find_key(denom_raw).ok_or(denom.clone()) + ::AssetMap::find_key(denom_raw).ok_or(denom.clone()) } } } @@ -207,9 +203,7 @@ impl TryConvert for AssetToDenom { if asset_id == NativeAssetId::get() { Ok(NativeDenom::get().to_string()) } else { - let denom = - >>::get(asset_id) - .ok_or(asset_id)?; + let denom = ::AssetMap::get(asset_id).ok_or(asset_id)?; String::from_utf8(denom.into()).map_err(|_| asset_id) } } @@ -343,13 +337,13 @@ impl pallet_multimap::Config for Test { } impl frame_babel::Config for Test { - type AddressMap = AddressMap; - type AssetMap = AssetMap; + type AddressMap = frame_babel::AddressMap; + type AssetMap = frame_babel::AssetMap; type Balance = Balance; } impl unify_account::Config for Test { - type AddressMap = AddressMap; + type AddressMap = frame_babel::AddressMap; type DrainBalance = Balances; }