Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.

Commit 20d1a70

Browse files
committed
Simple implementation of TwoStaticLookup
1 parent b7c120d commit 20d1a70

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

bin/node/runtime/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ use sp_runtime::{
5353
use sp_runtime::curve::PiecewiseLinear;
5454
use sp_runtime::transaction_validity::{TransactionValidity, TransactionSource, TransactionPriority};
5555
use sp_runtime::traits::{
56-
self, BlakeTwo256, Block as BlockT, StaticLookup, SaturatedConversion,
56+
self, BlakeTwo256, Block as BlockT, StaticLookup, TwoStaticLookup, SaturatedConversion,
5757
ConvertInto, OpaqueKeys, NumberFor, Saturating,
5858
};
5959
use sp_version::RuntimeVersion;
@@ -169,7 +169,7 @@ impl frame_system::Trait for Runtime {
169169
type Hash = Hash;
170170
type Hashing = BlakeTwo256;
171171
type AccountId = AccountId;
172-
type Lookup = NameService;
172+
type Lookup = TwoStaticLookup<Indices, NameService>;
173173
type Header = generic::Header<BlockNumber, BlakeTwo256>;
174174
type Event = Event;
175175
type BlockHashCount = BlockHashCount;

primitives/runtime/src/traits.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,29 @@ impl<AccountId: Codec + Clone + PartialEq + Debug> StaticLookup for AccountIdLoo
225225
}
226226
}
227227

228+
/// Perform a StaticLookup where there are two lookup sources of the same type.
229+
pub struct TwoStaticLookup<A, B>(PhantomData<(A, B)>);
230+
impl<A, B> StaticLookup for TwoStaticLookup<A, B>
231+
where
232+
A: StaticLookup,
233+
B: StaticLookup<Source = A::Source, Target = A::Target>,
234+
{
235+
type Source = A::Source;
236+
type Target = A::Target;
237+
238+
fn lookup(x: Self::Source) -> Result<Self::Target, LookupError> {
239+
let a = A::lookup(x.clone());
240+
if a.is_ok() {
241+
return a
242+
} else {
243+
B::lookup(x)
244+
}
245+
}
246+
fn unlookup(x: Self::Target) -> Self::Source {
247+
A::unlookup(x)
248+
}
249+
}
250+
228251
/// Extensible conversion trait. Generic over both source and destination types.
229252
pub trait Convert<A, B> {
230253
/// Make conversion.

0 commit comments

Comments
 (0)