mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 10:31:03 +00:00
add accountkey20 conversion impls (#2576)
This commit is contained in:
@@ -18,13 +18,13 @@
|
|||||||
|
|
||||||
mod location_conversion;
|
mod location_conversion;
|
||||||
pub use location_conversion::{
|
pub use location_conversion::{
|
||||||
Account32Hash, ParentIsDefault, ChildParachainConvertsVia, SiblingParachainConvertsVia, AccountId32Aliases
|
Account32Hash, ParentIsDefault, ChildParachainConvertsVia, SiblingParachainConvertsVia, AccountId32Aliases, AccountKey20Aliases,
|
||||||
};
|
};
|
||||||
|
|
||||||
mod origin_conversion;
|
mod origin_conversion;
|
||||||
pub use origin_conversion::{
|
pub use origin_conversion::{
|
||||||
SovereignSignedViaLocation, ParentAsSuperuser, ChildSystemParachainAsSuperuser, SiblingSystemParachainAsSuperuser,
|
SovereignSignedViaLocation, ParentAsSuperuser, ChildSystemParachainAsSuperuser, SiblingSystemParachainAsSuperuser,
|
||||||
ChildParachainAsNative, SiblingParachainAsNative, RelayChainAsNative, SignedAccountId32AsNative
|
ChildParachainAsNative, SiblingParachainAsNative, RelayChainAsNative, SignedAccountId32AsNative, SignedAccountKey20AsNative,
|
||||||
};
|
};
|
||||||
|
|
||||||
mod currency_adapter;
|
mod currency_adapter;
|
||||||
|
|||||||
@@ -124,3 +124,27 @@ impl<
|
|||||||
Ok(Junction::AccountId32 { id: who.into(), network: Network::get() }.into())
|
Ok(Junction::AccountId32 { id: who.into(), network: Network::get() }.into())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub struct AccountKey20Aliases<Network, AccountId>(PhantomData<(Network, AccountId)>);
|
||||||
|
|
||||||
|
impl<
|
||||||
|
Network: Get<NetworkId>,
|
||||||
|
AccountId: From<[u8; 20]> + Into<[u8; 20]>
|
||||||
|
> LocationConversion<AccountId> for AccountKey20Aliases<Network, AccountId> {
|
||||||
|
fn from_location(location: &MultiLocation) -> Option<AccountId> {
|
||||||
|
if let MultiLocation::X1(Junction::AccountKey20 { key, network }) = location {
|
||||||
|
if matches!(network, NetworkId::Any) || network == &Network::get() {
|
||||||
|
return Some((*key).into());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None
|
||||||
|
}
|
||||||
|
|
||||||
|
fn try_into_location(who: AccountId) -> Result<MultiLocation, AccountId> {
|
||||||
|
Ok(Junction::AccountKey20 {
|
||||||
|
key: who.into(),
|
||||||
|
network: Network::get(),
|
||||||
|
}
|
||||||
|
.into())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -148,3 +148,24 @@ impl<
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub struct SignedAccountKey20AsNative<Network, Origin>(
|
||||||
|
PhantomData<(Network, Origin)>
|
||||||
|
);
|
||||||
|
impl<
|
||||||
|
Network: Get<NetworkId>,
|
||||||
|
Origin: OriginTrait
|
||||||
|
> ConvertOrigin<Origin> for SignedAccountKey20AsNative<Network, Origin> where
|
||||||
|
Origin::AccountId: From<[u8; 20]>,
|
||||||
|
{
|
||||||
|
fn convert_origin(origin: MultiLocation, kind: OriginKind) -> Result<Origin, MultiLocation> {
|
||||||
|
match (kind, origin) {
|
||||||
|
(OriginKind::Native, MultiLocation::X1(Junction::AccountKey20 { key, network }))
|
||||||
|
if matches!(network, NetworkId::Any) || network == Network::get() =>
|
||||||
|
{
|
||||||
|
Ok(Origin::signed(key.into()))
|
||||||
|
}
|
||||||
|
(_, origin) => Err(origin),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user