Trait xcm_builder::test_utils::ConvertOrigin
source · pub trait ConvertOrigin<Origin> {
fn convert_origin(
origin: impl Into<MultiLocation>,
kind: OriginKind
) -> Result<Origin, MultiLocation>;
}
Expand description
A converter trait
for origin types.
Can be amalgamated into tuples. If any of the tuple elements returns Ok(_)
, it short circuits. Else, the Err(_)
of the last tuple item is returned. Each intermediate Err(_)
might return a different origin
of type Origin
which is passed to the next convert item.
// A convertor that will bump the para id and pass it to the next one.
struct BumpParaId;
impl ConvertOrigin<u32> for BumpParaId {
fn convert_origin(origin: impl Into<MultiLocation>, _: OriginKind) -> Result<u32, MultiLocation> {
match origin.into() {
MultiLocation { parents: 0, interior: Junctions::X1(Junction::Parachain(id)) } => {
Err(Junctions::X1(Junction::Parachain(id + 1)).into())
}
_ => unreachable!()
}
}
}
struct AcceptPara7;
impl ConvertOrigin<u32> for AcceptPara7 {
fn convert_origin(origin: impl Into<MultiLocation>, _: OriginKind) -> Result<u32, MultiLocation> {
match origin.into() {
MultiLocation { parents: 0, interior: Junctions::X1(Junction::Parachain(id)) } if id == 7 => {
Ok(7)
}
o => Err(o)
}
}
}
let origin: MultiLocation = Junctions::X1(Junction::Parachain(6)).into();
assert!(
<(BumpParaId, AcceptPara7) as ConvertOrigin<u32>>::convert_origin(origin, OriginKind::Native)
.is_ok()
);
Required Methods§
sourcefn convert_origin(
origin: impl Into<MultiLocation>,
kind: OriginKind
) -> Result<Origin, MultiLocation>
fn convert_origin(
origin: impl Into<MultiLocation>,
kind: OriginKind
) -> Result<Origin, MultiLocation>
Attempt to convert origin
to the generic Origin
whilst consuming it.