1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
use codec::{Encode, EncodeAsRef, HasCompact, Output};
use frame_support::{sp_runtime::MultiAddress, sp_std::marker::PhantomData};
pub trait EncodeWith<Input, Context> {
fn encode_to_with<T: Output + ?Sized>(input: &Input, ctx: &Context, dest: &mut T);
}
pub struct PassthroughEncoder<I, T>(PhantomData<(I, T)>);
impl<I: Encode, Context> EncodeWith<I, Context> for PassthroughEncoder<I, Context> {
fn encode_to_with<T: Output + ?Sized>(input: &I, _: &Context, dest: &mut T) {
input.encode_to(dest)
}
}
pub struct PassthroughCompactEncoder<I, T>(PhantomData<(I, T)>);
impl<I: HasCompact, Context> EncodeWith<I, Context> for PassthroughCompactEncoder<I, Context> {
fn encode_to_with<T: Output + ?Sized>(input: &I, _: &Context, dest: &mut T) {
<<I as HasCompact>::Type as EncodeAsRef<'_, I>>::RefType::from(input).encode_to(dest)
}
}
pub struct MultiAddressLookupSourceEncoder<AccountId, AccountIndex, Context>(
PhantomData<(AccountId, AccountIndex, Context)>,
);
impl<AccountId, AccountIndex, Context> EncodeWith<AccountId, Context>
for MultiAddressLookupSourceEncoder<AccountId, AccountIndex, Context>
where
AccountId: Encode + Clone,
AccountIndex: HasCompact,
{
fn encode_to_with<T: Output + ?Sized>(account: &AccountId, _: &Context, dest: &mut T) {
MultiAddress::<AccountId, AccountIndex>::from(account.clone()).encode_to(dest)
}
}