I was making a new way to add sovereign accounts for a particular Network ID. Like in this https://github.com/paritytech/polkadot/blob/HEAD/xcm/xcm-builder/src/location_conversion.rs
pub struct ChildParachainConvertsVia<ParaId, AccountId>(PhantomData<(ParaId, AccountId)>);
impl<ParaId: From<u32> + Into<u32> + AccountIdConversion<AccountId>, AccountId: Clone>
Convert<MultiLocation, AccountId> for ChildParachainConvertsVia<ParaId, AccountId>
{
fn convert_ref(location: impl Borrow<MultiLocation>) -> Result<AccountId, ()> {
match location.borrow() {
MultiLocation { parents: 0, interior: X1(Parachain(id)) } =>
Ok(ParaId::from(*id).into_account_truncating()),
_ => Err(()),
}
}
fn reverse_ref(who: impl Borrow<AccountId>) -> Result<MultiLocation, ()> {
if let Some(id) = ParaId::try_from_account(who.borrow()) {
Ok(Parachain(id.into()).into())
} else {
Err(())
}
}
}
It is a way to add sovereign account of Parachain in the Relay chain. There are also other examples where we can add sibling sovereign account also. I was making a new way to add sovereign account of particular NetworkId.
pub struct NetworkIdConvertsVia<Network, AccountId>(PhantomData<(Network, AccountId)>);
impl<Network: Get<NetworkId>, AccountId: From<[u8; 32]> + Into<[u8; 32]> + Clone >
Convert<MultiLocation, AccountId> for NetworkIdConvertsVia<Network, AccountId> where xcm::v3::NetworkId: From<AccountId>
{
fn convert(location: MultiLocation) -> Result<AccountId, MultiLocation> {
let id = match location {
MultiLocation { parents: 0, interior: X1(GlobalConsensus(network)) } => network,
_=>return Err(location)
};
Ok(id.into())
}
// fn reverse(who: AccountId) -> Result<MultiLocation, AccountId> {
// //Ok(GlobalConsensus(NetworkId()).into())
// )
// }
But I'm getting error "the trait From<xcm::v3::NetworkId>
is not implemented for AccountId
">please check