mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 16:21:02 +00:00
Kusama origins as xcm multi_location (#6273)
* Kusamsa origins as xcm multilocation * Fellows origin index * origins to xcm plurality body * cleanup * fix cargo spellcheck * Apply suggestions from code review Co-authored-by: joe petrowski <25483142+joepetrowski@users.noreply.github.com> * include Fellows into scope * include Fellows into scope Co-authored-by: joe petrowski <25483142+joepetrowski@users.noreply.github.com> Co-authored-by: Gavin Wood <gavin@parity.io>
This commit is contained in:
@@ -1527,6 +1527,19 @@ impl<Prefix: Get<MultiLocation>, Body: Get<BodyId>> Contains<MultiLocation>
|
||||
}
|
||||
}
|
||||
|
||||
/// Filter for `MultiLocation` to find those which represent a voice of an identified plurality.
|
||||
///
|
||||
/// May reasonably be used with `EnsureXcm`.
|
||||
pub struct IsVoiceOfBody<Prefix, Body>(PhantomData<(Prefix, Body)>);
|
||||
impl<Prefix: Get<MultiLocation>, Body: Get<BodyId>> Contains<MultiLocation>
|
||||
for IsVoiceOfBody<Prefix, Body>
|
||||
{
|
||||
fn contains(l: &MultiLocation) -> bool {
|
||||
let maybe_suffix = l.match_and_split(&Prefix::get());
|
||||
matches!(maybe_suffix, Some(Plurality { id, part }) if id == &Body::get() && part == &BodyPart::Voice)
|
||||
}
|
||||
}
|
||||
|
||||
/// `EnsureOrigin` implementation succeeding with a `MultiLocation` value to recognize and filter the
|
||||
/// `Origin::Xcm` item.
|
||||
pub struct EnsureXcm<F>(PhantomData<F>);
|
||||
|
||||
@@ -52,6 +52,15 @@ pub enum BodyId {
|
||||
/// The unambiguous judicial body (this doesn't exist on Polkadot, but if it were to get a "grand oracle", it
|
||||
/// may be considered as that).
|
||||
Judicial,
|
||||
/// The unambiguous defense body (for Polkadot, an opinion on the topic given via a public referendum
|
||||
/// on the `staking_admin` track).
|
||||
Defense,
|
||||
/// The unambiguous administration body (for Polkadot, an opinion on the topic given via a public referendum
|
||||
/// on the `general_admin` track).
|
||||
Administration,
|
||||
/// The unambiguous treasury body (for Polkadot, an opinion on the topic given via a public referendum
|
||||
/// on the `treasurer` track).
|
||||
Treasury,
|
||||
}
|
||||
|
||||
/// A part of a pluralistic body.
|
||||
|
||||
@@ -37,7 +37,7 @@ pub use location_conversion::{
|
||||
mod origin_conversion;
|
||||
pub use origin_conversion::{
|
||||
BackingToPlurality, ChildParachainAsNative, ChildSystemParachainAsSuperuser, EnsureXcmOrigin,
|
||||
ParentAsSuperuser, RelayChainAsNative, SiblingParachainAsNative,
|
||||
OriginToPluralityVoice, ParentAsSuperuser, RelayChainAsNative, SiblingParachainAsNative,
|
||||
SiblingSystemParachainAsSuperuser, SignedAccountId32AsNative, SignedAccountKey20AsNative,
|
||||
SignedToAccountId32, SovereignSignedViaLocation,
|
||||
};
|
||||
|
||||
@@ -321,3 +321,20 @@ where
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/// `Convert` implementation to convert from an origin which passes the check of an `EnsureOrigin`
|
||||
/// into a voice of a given pluralistic `Body`.
|
||||
pub struct OriginToPluralityVoice<RuntimeOrigin, EnsureBodyOrigin, Body>(
|
||||
PhantomData<(RuntimeOrigin, EnsureBodyOrigin, Body)>,
|
||||
);
|
||||
impl<RuntimeOrigin: Clone, EnsureBodyOrigin: EnsureOrigin<RuntimeOrigin>, Body: Get<BodyId>>
|
||||
Convert<RuntimeOrigin, MultiLocation>
|
||||
for OriginToPluralityVoice<RuntimeOrigin, EnsureBodyOrigin, Body>
|
||||
{
|
||||
fn convert(o: RuntimeOrigin) -> Result<MultiLocation, RuntimeOrigin> {
|
||||
match EnsureBodyOrigin::try_origin(o) {
|
||||
Ok(_) => Ok(Junction::Plurality { id: Body::get(), part: BodyPart::Voice }.into()),
|
||||
Err(o) => Err(o),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user