From f6762b0ae8284dd36394137dd59bee3190a9660d Mon Sep 17 00:00:00 2001 From: Shawn Tabrizi Date: Tue, 17 Nov 2020 15:34:05 +0100 Subject: [PATCH] patches --- parachain/src/primitives.rs | 39 +++++++++++++++++++++++++ runtime/parachains/src/origin.rs | 6 ++++ xcm/xcm-builder/src/currency_adapter.rs | 4 +-- 3 files changed, 47 insertions(+), 2 deletions(-) diff --git a/parachain/src/primitives.rs b/parachain/src/primitives.rs index f90dfaa5d651..e3c97620bfd6 100644 --- a/parachain/src/primitives.rs +++ b/parachain/src/primitives.rs @@ -135,6 +135,45 @@ impl sp_std::ops::Add for Id { } } +#[derive(Clone, Copy, Default, Encode, Decode, Eq, PartialEq, Ord, PartialOrd, RuntimeDebug)] +pub struct Sibling(pub Id); + +impl From for Sibling { + fn from(i: Id) -> Self { + Self(i) + } +} + +impl From for Id { + fn from(i: Sibling) -> Self { + i.0 + } +} + +impl AsRef for Sibling { + fn as_ref(&self) -> &Id { + &self.0 + } +} + +impl TypeId for Sibling { + const TYPE_ID: [u8; 4] = *b"sibl"; +} + +impl From for u32 { + fn from(x: Sibling) -> Self { x.0.into() } +} + +impl From for Sibling { + fn from(x: u32) -> Self { Sibling(x.into()) } +} + +impl IsSystem for Sibling { + fn is_system(&self) -> bool { + IsSystem::is_system(&self.0) + } +} + /// This type can be converted into and possibly from an AccountId (which itself is generic). pub trait AccountIdConversion: Sized { /// Convert into an account ID. This is infallible. diff --git a/runtime/parachains/src/origin.rs b/runtime/parachains/src/origin.rs index 95204e40a7cc..b8444181de58 100644 --- a/runtime/parachains/src/origin.rs +++ b/runtime/parachains/src/origin.rs @@ -51,3 +51,9 @@ frame_support::decl_module! { // ideally, though, the `construct_runtime` should support a free-standing origin. pub struct Module for enum Call where origin: ::Origin {} } + +impl From for Origin { + fn from(id: u32) -> Origin { + Origin::Parachain(id.into()) + } +} diff --git a/xcm/xcm-builder/src/currency_adapter.rs b/xcm/xcm-builder/src/currency_adapter.rs index d7f6b4d4c274..09b61ab6bb57 100644 --- a/xcm/xcm-builder/src/currency_adapter.rs +++ b/xcm/xcm-builder/src/currency_adapter.rs @@ -36,7 +36,7 @@ impl< fn deposit_asset(what: &MultiAsset, who: &MultiLocation) -> Result { // Check we handle this asset. - let amount = Matcher::matches_fungible(&what).ok_or(())?.saturated_into(); + let amount: u128 = Matcher::matches_fungible(&what).ok_or(())?.saturated_into(); let who = AccountIdConverter::from_location(who).ok_or(())?; let balance_amount = amount.try_into().map_err(|_| ())?; let _imbalance = Currency::deposit_creating(&who, balance_amount); @@ -45,7 +45,7 @@ impl< fn withdraw_asset(what: &MultiAsset, who: &MultiLocation) -> result::Result { // Check we handle this asset. - let amount = Matcher::matches_fungible(&what).ok_or(())?.saturated_into(); + let amount: u128 = Matcher::matches_fungible(&what).ok_or(())?.saturated_into(); let who = AccountIdConverter::from_location(who).ok_or(())?; let balance_amount = amount.try_into().map_err(|_| ())?; Currency::withdraw(&who, balance_amount, WithdrawReasons::TRANSFER, AllowDeath).map_err(|_| ())?;