More Extensible Multiaddress Format (#7380)

* More extensible multiaddress format

* update name

* Don't depend on indices to define multiaddress type

* Use MultiAddress in Node Template too!

* reduce traits, fix build

* support multiple `StaticLookup`

* bump tx version

* feedback
This commit is contained in:
Shawn Tabrizi
2020-11-19 12:40:12 +01:00
committed by GitHub
parent 0e9e2ed5a8
commit 4637100ac7
10 changed files with 125 additions and 177 deletions
+7 -8
View File
@@ -21,13 +21,13 @@
#![cfg_attr(not(feature = "std"), no_std)]
mod mock;
pub mod address;
mod tests;
mod benchmarking;
pub mod weights;
use sp_std::prelude::*;
use codec::Codec;
use sp_runtime::MultiAddress;
use sp_runtime::traits::{
StaticLookup, Member, LookupError, Zero, Saturating, AtLeast32Bit
};
@@ -35,10 +35,8 @@ use frame_support::{Parameter, decl_module, decl_error, decl_event, decl_storage
use frame_support::dispatch::DispatchResult;
use frame_support::traits::{Currency, ReservableCurrency, Get, BalanceStatus::Reserved};
use frame_system::{ensure_signed, ensure_root};
use self::address::Address as RawAddress;
pub use weights::WeightInfo;
pub type Address<T> = RawAddress<<T as frame_system::Trait>::AccountId, <T as Trait>::AccountIndex>;
type BalanceOf<T> = <<T as Trait>::Currency as Currency<<T as frame_system::Trait>::AccountId>>::Balance;
/// The module's config trait.
@@ -287,17 +285,18 @@ impl<T: Trait> Module<T> {
/// Lookup an address to get an Id, if there's one there.
pub fn lookup_address(
a: address::Address<T::AccountId, T::AccountIndex>
a: MultiAddress<T::AccountId, T::AccountIndex>
) -> Option<T::AccountId> {
match a {
address::Address::Id(i) => Some(i),
address::Address::Index(i) => Self::lookup_index(i),
MultiAddress::Id(i) => Some(i),
MultiAddress::Index(i) => Self::lookup_index(i),
_ => None,
}
}
}
impl<T: Trait> StaticLookup for Module<T> {
type Source = address::Address<T::AccountId, T::AccountIndex>;
type Source = MultiAddress<T::AccountId, T::AccountIndex>;
type Target = T::AccountId;
fn lookup(a: Self::Source) -> Result<Self::Target, LookupError> {
@@ -305,6 +304,6 @@ impl<T: Trait> StaticLookup for Module<T> {
}
fn unlookup(a: Self::Target) -> Self::Source {
address::Address::Id(a)
MultiAddress::Id(a)
}
}