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
use super::derivers::{
ParachainPalletGeneralIndexAccountIdDeriver, TinkernetMultisigAccountIdDeriver,
};
use core::marker::PhantomData;
use xcm::v2::{Junction, Junctions, MultiLocation};
use xcm_executor::traits::Convert;
pub struct PalletInstanceGeneralIndexAsAccountId<AccountId, Deriver>(
PhantomData<(AccountId, Deriver)>,
);
impl<
AccountId: From<[u8; 32]> + Clone,
Deriver: ParachainPalletGeneralIndexAccountIdDeriver<AccountId>,
> Convert<MultiLocation, AccountId>
for PalletInstanceGeneralIndexAsAccountId<AccountId, Deriver>
{
fn convert(location: MultiLocation) -> Result<AccountId, MultiLocation> {
let id = match location.clone() {
MultiLocation {
parents: _,
interior:
Junctions::X3(
Junction::Parachain(para_id),
Junction::PalletInstance(pallet_index),
Junction::GeneralIndex(id),
),
} => Deriver::derive_account(para_id, pallet_index, id).ok_or(location)?,
_ => return Err(location),
};
Ok(id)
}
}
pub type TinkernetMultisigAsAccountId<AccountId> =
PalletInstanceGeneralIndexAsAccountId<AccountId, TinkernetMultisigAccountIdDeriver<AccountId>>;