-
Notifications
You must be signed in to change notification settings - Fork 300
relay account and tests #651
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 4 commits
7421f97
514566b
1f7d92a
d132663
f4162e3
ced4d67
cbb4944
c3b4d7d
61d40f5
1cb1abf
23e1a9f
e1467ba
9cffcc5
631659b
b1a2a90
4177cd6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,15 +10,18 @@ | |
| #![allow(clippy::unused_unit)] | ||
|
|
||
| use frame_support::dispatch::{DispatchError, DispatchResult}; | ||
| use frame_support::{ensure, traits::Contains, weights::Weight}; | ||
|
|
||
| use sp_runtime::traits::{CheckedConversion, Convert}; | ||
| use sp_std::{convert::TryFrom, marker::PhantomData, prelude::*}; | ||
|
|
||
| use xcm::latest::prelude::*; | ||
| use xcm_executor::traits::{FilterAssetLocation, MatchesFungible}; | ||
| use xcm_executor::traits::{FilterAssetLocation, MatchesFungible, ShouldExecute}; | ||
|
|
||
| use orml_traits::location::Reserve; | ||
|
|
||
| pub use currency_adapter::MultiCurrencyAdapter; | ||
| use frame_support::pallet_prelude::Get; | ||
|
|
||
| mod currency_adapter; | ||
|
|
||
|
|
@@ -75,3 +78,75 @@ impl UnknownAsset for () { | |
| Err(DispatchError::Other(NO_UNKNOWN_ASSET_IMPL)) | ||
| } | ||
| } | ||
|
|
||
| /// Extracts the `AccountId32` from the passed `location` if the network | ||
| /// matches. | ||
| pub struct RelaychainAccountId32Aliases<Network, AccountId>(PhantomData<(Network, AccountId)>); | ||
zqhxuyuan marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| impl<Network: Get<NetworkId>, AccountId: From<[u8; 32]> + Into<[u8; 32]> + Clone> | ||
| xcm_executor::traits::Convert<MultiLocation, AccountId> for RelaychainAccountId32Aliases<Network, AccountId> | ||
| { | ||
| fn convert(location: MultiLocation) -> Result<AccountId, MultiLocation> { | ||
| let id = match location { | ||
zqhxuyuan marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| MultiLocation { | ||
| parents: 1, | ||
| interior: X1(AccountId32 { | ||
| id, | ||
| network: NetworkId::Any, | ||
zqhxuyuan marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| }), | ||
| } => id, | ||
| _ => return Err(location), | ||
| }; | ||
| Ok(id.into()) | ||
| } | ||
|
|
||
| fn reverse(who: AccountId) -> Result<MultiLocation, AccountId> { | ||
| Ok(AccountId32 { | ||
| id: who.into(), | ||
| network: Network::get(), | ||
| } | ||
| .into()) | ||
|
||
| } | ||
| } | ||
|
|
||
| pub struct AllowDescendOrigin<T>(PhantomData<T>); | ||
| impl<T: Contains<MultiLocation>> ShouldExecute for AllowDescendOrigin<T> { | ||
| fn should_execute<Call>( | ||
| origin: &MultiLocation, | ||
| message: &mut Xcm<Call>, | ||
| max_weight: Weight, | ||
| _weight_credit: &mut Weight, | ||
| ) -> Result<(), ()> { | ||
| ensure!(T::contains(origin), ()); | ||
| let mut iter = message.0.iter_mut(); | ||
zqhxuyuan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| let i = iter.next().ok_or(())?; | ||
| match i { | ||
| DescendOrigin(..) => (), | ||
zqhxuyuan marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| _ => return Err(()), | ||
| } | ||
| let i = iter.next().ok_or(())?; | ||
| match i { | ||
| ReceiveTeleportedAsset(..) | WithdrawAsset(..) | ReserveAssetDeposited(..) | ClaimAsset { .. } => (), | ||
| _ => return Err(()), | ||
| } | ||
| let mut i = iter.next().ok_or(())?; | ||
| while let ClearOrigin = i { | ||
| i = iter.next().ok_or(())?; | ||
| } | ||
| match i { | ||
| BuyExecution { | ||
| weight_limit: Limited(ref mut weight), | ||
| .. | ||
| } if *weight >= max_weight => { | ||
| *weight = max_weight; | ||
| Ok(()) | ||
| } | ||
| BuyExecution { | ||
| ref mut weight_limit, .. | ||
| } if weight_limit == &Unlimited => { | ||
| *weight_limit = Limited(max_weight); | ||
| Ok(()) | ||
| } | ||
| _ => Err(()), | ||
| } | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.