-
Notifications
You must be signed in to change notification settings - Fork 297
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 7 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,79 @@ 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
|
||
| 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
|
||
| MultiLocation { | ||
| parents: 1, | ||
| interior: X1(AccountId32 { | ||
| id, | ||
| network: NetworkId::Any, | ||
|
zqhxuyuan marked this conversation as resolved.
Outdated
|
||
| }), | ||
| } => id, | ||
| _ => return Err(location), | ||
| }; | ||
| Ok(id.into()) | ||
| } | ||
|
|
||
| fn reverse(who: AccountId) -> Result<MultiLocation, AccountId> { | ||
| Ok(AccountId32 { | ||
| id: who.into(), | ||
| network: Network::get(), | ||
| } | ||
| .into()) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will reverse to
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's a good point, as the reverse path is not currently go through, I may miss here.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. after I change here to return
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've post an issue on polkadot: paritytech/polkadot#4296. would you mind to see if that's a potential problem? @KiChjang @apopiak |
||
| } | ||
| } | ||
|
|
||
| /// when Relay an XCM message from a given `interior` location, if the given | ||
| /// `interior` is not `Here`, the destination will receive a xcm message | ||
| /// beginning with `DescendOrigin` as the first instruction. so the xcm message | ||
| /// format must match this order: | ||
| /// `DescendOrigin`,`WithdrawAsset`,`BuyExecution`,`Transact`. | ||
|
zqhxuyuan marked this conversation as resolved.
Outdated
|
||
| pub struct AllowEquivalentAccountsFrom<T>(PhantomData<T>); | ||
|
zqhxuyuan marked this conversation as resolved.
Outdated
zqhxuyuan marked this conversation as resolved.
Outdated
|
||
| impl<T: Contains<MultiLocation>> ShouldExecute for AllowEquivalentAccountsFrom<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.
|
||
| let i = iter.next().ok_or(())?; | ||
| match i { | ||
| DescendOrigin(..) => (), | ||
|
zqhxuyuan marked this conversation as resolved.
Outdated
|
||
| _ => return Err(()), | ||
| } | ||
| let i = iter.next().ok_or(())?; | ||
| match i { | ||
| WithdrawAsset(..) => (), | ||
| _ => return Err(()), | ||
| } | ||
| let i = iter.next().ok_or(())?; | ||
| match i { | ||
| BuyExecution { | ||
| weight_limit: Limited(ref mut weight), | ||
| .. | ||
| } if *weight >= max_weight => { | ||
| *weight = max_weight; | ||
| () | ||
| } | ||
| _ => return Err(()), | ||
| } | ||
| let i = iter.next().ok_or(())?; | ||
| match i { | ||
| Transact { | ||
| origin_type: OriginKind::SovereignAccount, | ||
| .. | ||
| } => Ok(()), | ||
| _ => Err(()), | ||
| } | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.