mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 09:21:04 +00:00
Make most XCM APIs accept an Into<MultiLocation> where MultiLocation is accepted (#3627)
* Change send_xcm MultiLocation argument to be generic * Change pallet_xcm::send_xcm MultiLocation and Junctions argument to be generic * Change convert_origin MultiLocation argument to be generic * Change OnResponse MultiLocation arguments to be generic * Change UniversalWeigher MultiLocation argumente to be generic * Change ExecuteXcm MultiLocation argument to be generic * Remove usages of into for the MultiLocation argument in execute_xcm * Make use of generic MultiLocation arguments in rustdocs * Cargo fmt * Remove unused import in tests * Resolve conflicts * cargo fmt * Appease spellcheck * impl Into<MultiLocation> in more places
This commit is contained in:
@@ -109,8 +109,8 @@ pub fn sent_xcm() -> Vec<(MultiLocation, opaque::Xcm)> {
|
||||
}
|
||||
pub struct TestSendXcm;
|
||||
impl SendXcm for TestSendXcm {
|
||||
fn send_xcm(dest: MultiLocation, msg: opaque::Xcm) -> SendResult {
|
||||
SENT_XCM.with(|q| q.borrow_mut().push((dest, msg)));
|
||||
fn send_xcm(dest: impl Into<MultiLocation>, msg: opaque::Xcm) -> SendResult {
|
||||
SENT_XCM.with(|q| q.borrow_mut().push((dest.into(), msg)));
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
@@ -164,11 +164,11 @@ pub fn to_account(l: MultiLocation) -> Result<u64, MultiLocation> {
|
||||
pub struct TestOriginConverter;
|
||||
impl ConvertOrigin<TestOrigin> for TestOriginConverter {
|
||||
fn convert_origin(
|
||||
origin: MultiLocation,
|
||||
origin: impl Into<MultiLocation>,
|
||||
kind: OriginKind,
|
||||
) -> Result<TestOrigin, MultiLocation> {
|
||||
use OriginKind::*;
|
||||
match (kind, origin) {
|
||||
match (kind, origin.into()) {
|
||||
(Superuser, _) => Ok(TestOrigin::Root),
|
||||
(SovereignAccount, l) => Ok(TestOrigin::Signed(to_account(l)?)),
|
||||
(Native, MultiLocation { parents: 0, interior: X1(Parachain(id)) }) =>
|
||||
|
||||
@@ -32,7 +32,11 @@ impl<LocationConverter: Convert<MultiLocation, Origin::AccountId>, Origin: Origi
|
||||
where
|
||||
Origin::AccountId: Clone,
|
||||
{
|
||||
fn convert_origin(origin: MultiLocation, kind: OriginKind) -> Result<Origin, MultiLocation> {
|
||||
fn convert_origin(
|
||||
origin: impl Into<MultiLocation>,
|
||||
kind: OriginKind,
|
||||
) -> Result<Origin, MultiLocation> {
|
||||
let origin = origin.into();
|
||||
if let OriginKind::SovereignAccount = kind {
|
||||
let location = LocationConverter::convert(origin)?;
|
||||
Ok(Origin::signed(location).into())
|
||||
@@ -44,7 +48,11 @@ where
|
||||
|
||||
pub struct ParentAsSuperuser<Origin>(PhantomData<Origin>);
|
||||
impl<Origin: OriginTrait> ConvertOrigin<Origin> for ParentAsSuperuser<Origin> {
|
||||
fn convert_origin(origin: MultiLocation, kind: OriginKind) -> Result<Origin, MultiLocation> {
|
||||
fn convert_origin(
|
||||
origin: impl Into<MultiLocation>,
|
||||
kind: OriginKind,
|
||||
) -> Result<Origin, MultiLocation> {
|
||||
let origin = origin.into();
|
||||
if kind == OriginKind::Superuser && origin.contains_parents_only(1) {
|
||||
Ok(Origin::root())
|
||||
} else {
|
||||
@@ -57,8 +65,11 @@ pub struct ChildSystemParachainAsSuperuser<ParaId, Origin>(PhantomData<(ParaId,
|
||||
impl<ParaId: IsSystem + From<u32>, Origin: OriginTrait> ConvertOrigin<Origin>
|
||||
for ChildSystemParachainAsSuperuser<ParaId, Origin>
|
||||
{
|
||||
fn convert_origin(origin: MultiLocation, kind: OriginKind) -> Result<Origin, MultiLocation> {
|
||||
match (kind, origin) {
|
||||
fn convert_origin(
|
||||
origin: impl Into<MultiLocation>,
|
||||
kind: OriginKind,
|
||||
) -> Result<Origin, MultiLocation> {
|
||||
match (kind, origin.into()) {
|
||||
(
|
||||
OriginKind::Superuser,
|
||||
MultiLocation { parents: 0, interior: X1(Junction::Parachain(id)) },
|
||||
@@ -72,8 +83,11 @@ pub struct SiblingSystemParachainAsSuperuser<ParaId, Origin>(PhantomData<(ParaId
|
||||
impl<ParaId: IsSystem + From<u32>, Origin: OriginTrait> ConvertOrigin<Origin>
|
||||
for SiblingSystemParachainAsSuperuser<ParaId, Origin>
|
||||
{
|
||||
fn convert_origin(origin: MultiLocation, kind: OriginKind) -> Result<Origin, MultiLocation> {
|
||||
match (kind, origin) {
|
||||
fn convert_origin(
|
||||
origin: impl Into<MultiLocation>,
|
||||
kind: OriginKind,
|
||||
) -> Result<Origin, MultiLocation> {
|
||||
match (kind, origin.into()) {
|
||||
(
|
||||
OriginKind::Superuser,
|
||||
MultiLocation { parents: 1, interior: X1(Junction::Parachain(id)) },
|
||||
@@ -87,8 +101,11 @@ pub struct ChildParachainAsNative<ParachainOrigin, Origin>(PhantomData<(Parachai
|
||||
impl<ParachainOrigin: From<u32>, Origin: From<ParachainOrigin>> ConvertOrigin<Origin>
|
||||
for ChildParachainAsNative<ParachainOrigin, Origin>
|
||||
{
|
||||
fn convert_origin(origin: MultiLocation, kind: OriginKind) -> Result<Origin, MultiLocation> {
|
||||
match (kind, origin) {
|
||||
fn convert_origin(
|
||||
origin: impl Into<MultiLocation>,
|
||||
kind: OriginKind,
|
||||
) -> Result<Origin, MultiLocation> {
|
||||
match (kind, origin.into()) {
|
||||
(
|
||||
OriginKind::Native,
|
||||
MultiLocation { parents: 0, interior: X1(Junction::Parachain(id)) },
|
||||
@@ -104,8 +121,11 @@ pub struct SiblingParachainAsNative<ParachainOrigin, Origin>(
|
||||
impl<ParachainOrigin: From<u32>, Origin: From<ParachainOrigin>> ConvertOrigin<Origin>
|
||||
for SiblingParachainAsNative<ParachainOrigin, Origin>
|
||||
{
|
||||
fn convert_origin(origin: MultiLocation, kind: OriginKind) -> Result<Origin, MultiLocation> {
|
||||
match (kind, origin) {
|
||||
fn convert_origin(
|
||||
origin: impl Into<MultiLocation>,
|
||||
kind: OriginKind,
|
||||
) -> Result<Origin, MultiLocation> {
|
||||
match (kind, origin.into()) {
|
||||
(
|
||||
OriginKind::Native,
|
||||
MultiLocation { parents: 1, interior: X1(Junction::Parachain(id)) },
|
||||
@@ -120,7 +140,11 @@ pub struct RelayChainAsNative<RelayOrigin, Origin>(PhantomData<(RelayOrigin, Ori
|
||||
impl<RelayOrigin: Get<Origin>, Origin> ConvertOrigin<Origin>
|
||||
for RelayChainAsNative<RelayOrigin, Origin>
|
||||
{
|
||||
fn convert_origin(origin: MultiLocation, kind: OriginKind) -> Result<Origin, MultiLocation> {
|
||||
fn convert_origin(
|
||||
origin: impl Into<MultiLocation>,
|
||||
kind: OriginKind,
|
||||
) -> Result<Origin, MultiLocation> {
|
||||
let origin = origin.into();
|
||||
if kind == OriginKind::Native && origin.contains_parents_only(1) {
|
||||
Ok(RelayOrigin::get())
|
||||
} else {
|
||||
@@ -135,8 +159,11 @@ impl<Network: Get<NetworkId>, Origin: OriginTrait> ConvertOrigin<Origin>
|
||||
where
|
||||
Origin::AccountId: From<[u8; 32]>,
|
||||
{
|
||||
fn convert_origin(origin: MultiLocation, kind: OriginKind) -> Result<Origin, MultiLocation> {
|
||||
match (kind, origin) {
|
||||
fn convert_origin(
|
||||
origin: impl Into<MultiLocation>,
|
||||
kind: OriginKind,
|
||||
) -> Result<Origin, MultiLocation> {
|
||||
match (kind, origin.into()) {
|
||||
(
|
||||
OriginKind::Native,
|
||||
MultiLocation { parents: 0, interior: X1(Junction::AccountId32 { id, network }) },
|
||||
@@ -153,8 +180,11 @@ impl<Network: Get<NetworkId>, Origin: OriginTrait> ConvertOrigin<Origin>
|
||||
where
|
||||
Origin::AccountId: From<[u8; 20]>,
|
||||
{
|
||||
fn convert_origin(origin: MultiLocation, kind: OriginKind) -> Result<Origin, MultiLocation> {
|
||||
match (kind, origin) {
|
||||
fn convert_origin(
|
||||
origin: impl Into<MultiLocation>,
|
||||
kind: OriginKind,
|
||||
) -> Result<Origin, MultiLocation> {
|
||||
match (kind, origin.into()) {
|
||||
(
|
||||
OriginKind::Native,
|
||||
MultiLocation { parents: 0, interior: X1(Junction::AccountKey20 { key, network }) },
|
||||
|
||||
@@ -150,7 +150,6 @@ fn paying_reserve_deposit_should_work() {
|
||||
add_reserve(Parent.into(), (Parent, WildFungible).into());
|
||||
WeightPrice::set((Parent.into(), 1_000_000_000_000));
|
||||
|
||||
let origin = Parent.into();
|
||||
let fees = (Parent, 30).into();
|
||||
let message = Xcm(vec![
|
||||
ReserveAssetDeposited((Parent, 100).into()),
|
||||
@@ -158,7 +157,7 @@ fn paying_reserve_deposit_should_work() {
|
||||
DepositAsset { assets: All.into(), max_assets: 1, beneficiary: Here.into() },
|
||||
]);
|
||||
let weight_limit = 50;
|
||||
let r = XcmExecutor::<TestConfig>::execute_xcm(origin, message, weight_limit);
|
||||
let r = XcmExecutor::<TestConfig>::execute_xcm(Parent, message, weight_limit);
|
||||
assert_eq!(r, Outcome::Complete(30));
|
||||
assert_eq!(assets(3000), vec![(Parent, 70).into()]);
|
||||
}
|
||||
@@ -171,7 +170,7 @@ fn transfer_should_work() {
|
||||
add_asset(1001, (Here, 1000));
|
||||
// They want to transfer 100 of them to their sibling parachain #2
|
||||
let r = XcmExecutor::<TestConfig>::execute_xcm(
|
||||
Parachain(1).into(),
|
||||
Parachain(1),
|
||||
Xcm(vec![TransferAsset {
|
||||
assets: (Here, 100).into(),
|
||||
beneficiary: X1(AccountIndex64 { index: 3, network: Any }).into(),
|
||||
@@ -434,7 +433,7 @@ fn reserve_transfer_should_work() {
|
||||
// They want to transfer 100 of our native asset from sovereign account of parachain #1 into #2
|
||||
// and let them know to hand it to account #3.
|
||||
let r = XcmExecutor::<TestConfig>::execute_xcm(
|
||||
Parachain(1).into(),
|
||||
Parachain(1),
|
||||
Xcm(vec![TransferReserveAsset {
|
||||
assets: (Here, 100).into(),
|
||||
dest: Parachain(2).into(),
|
||||
@@ -482,8 +481,7 @@ fn simple_version_subscriptions_should_work() {
|
||||
let r = XcmExecutor::<TestConfig>::execute_xcm(origin, message.clone(), weight_limit);
|
||||
assert_eq!(r, Outcome::Error(XcmError::Barrier));
|
||||
|
||||
let origin = Parent.into();
|
||||
let r = XcmExecutor::<TestConfig>::execute_xcm(origin, message, weight_limit);
|
||||
let r = XcmExecutor::<TestConfig>::execute_xcm(Parent, message, weight_limit);
|
||||
assert_eq!(r, Outcome::Complete(10));
|
||||
|
||||
assert_eq!(SubscriptionRequests::get(), vec![(Parent.into(), Some((42, 5000)))]);
|
||||
@@ -536,8 +534,7 @@ fn simple_version_unsubscriptions_should_work() {
|
||||
let r = XcmExecutor::<TestConfig>::execute_xcm(origin, message.clone(), weight_limit);
|
||||
assert_eq!(r, Outcome::Error(XcmError::Barrier));
|
||||
|
||||
let origin = Parent.into();
|
||||
let r = XcmExecutor::<TestConfig>::execute_xcm(origin, message, weight_limit);
|
||||
let r = XcmExecutor::<TestConfig>::execute_xcm(Parent, message, weight_limit);
|
||||
assert_eq!(r, Outcome::Complete(10));
|
||||
|
||||
assert_eq!(SubscriptionRequests::get(), vec![(Parent.into(), None)]);
|
||||
@@ -580,14 +577,13 @@ fn version_unsubscription_instruction_should_work() {
|
||||
fn transacting_should_work() {
|
||||
AllowUnpaidFrom::set(vec![Parent.into()]);
|
||||
|
||||
let origin = Parent.into();
|
||||
let message = Xcm::<TestCall>(vec![Transact {
|
||||
origin_type: OriginKind::Native,
|
||||
require_weight_at_most: 50,
|
||||
call: TestCall::Any(50, None).encode().into(),
|
||||
}]);
|
||||
let weight_limit = 60;
|
||||
let r = XcmExecutor::<TestConfig>::execute_xcm(origin, message, weight_limit);
|
||||
let r = XcmExecutor::<TestConfig>::execute_xcm(Parent, message, weight_limit);
|
||||
assert_eq!(r, Outcome::Complete(60));
|
||||
}
|
||||
|
||||
@@ -595,14 +591,13 @@ fn transacting_should_work() {
|
||||
fn transacting_should_respect_max_weight_requirement() {
|
||||
AllowUnpaidFrom::set(vec![Parent.into()]);
|
||||
|
||||
let origin = Parent.into();
|
||||
let message = Xcm::<TestCall>(vec![Transact {
|
||||
origin_type: OriginKind::Native,
|
||||
require_weight_at_most: 40,
|
||||
call: TestCall::Any(50, None).encode().into(),
|
||||
}]);
|
||||
let weight_limit = 60;
|
||||
let r = XcmExecutor::<TestConfig>::execute_xcm(origin, message, weight_limit);
|
||||
let r = XcmExecutor::<TestConfig>::execute_xcm(Parent, message, weight_limit);
|
||||
assert_eq!(r, Outcome::Incomplete(50, XcmError::TooMuchWeightRequired));
|
||||
}
|
||||
|
||||
@@ -610,14 +605,13 @@ fn transacting_should_respect_max_weight_requirement() {
|
||||
fn transacting_should_refund_weight() {
|
||||
AllowUnpaidFrom::set(vec![Parent.into()]);
|
||||
|
||||
let origin = Parent.into();
|
||||
let message = Xcm::<TestCall>(vec![Transact {
|
||||
origin_type: OriginKind::Native,
|
||||
require_weight_at_most: 50,
|
||||
call: TestCall::Any(50, Some(30)).encode().into(),
|
||||
}]);
|
||||
let weight_limit = 60;
|
||||
let r = XcmExecutor::<TestConfig>::execute_xcm(origin, message, weight_limit);
|
||||
let r = XcmExecutor::<TestConfig>::execute_xcm(Parent, message, weight_limit);
|
||||
assert_eq!(r, Outcome::Complete(40));
|
||||
}
|
||||
|
||||
@@ -651,9 +645,8 @@ fn paid_transacting_should_refund_payment_for_unused_weight() {
|
||||
#[test]
|
||||
fn prepaid_result_of_query_should_get_free_execution() {
|
||||
let query_id = 33;
|
||||
let origin: MultiLocation = Parent.into();
|
||||
// We put this in manually here, but normally this would be done at the point of crafting the message.
|
||||
expect_response(query_id, origin.clone());
|
||||
expect_response(query_id, Parent.into());
|
||||
|
||||
let the_response = Response::Assets((Parent, 100).into());
|
||||
let message = Xcm::<TestCall>(vec![QueryResponse {
|
||||
@@ -664,12 +657,12 @@ fn prepaid_result_of_query_should_get_free_execution() {
|
||||
let weight_limit = 10;
|
||||
|
||||
// First time the response gets through since we're expecting it...
|
||||
let r = XcmExecutor::<TestConfig>::execute_xcm(origin.clone(), message.clone(), weight_limit);
|
||||
let r = XcmExecutor::<TestConfig>::execute_xcm(Parent, message.clone(), weight_limit);
|
||||
assert_eq!(r, Outcome::Complete(10));
|
||||
assert_eq!(response(query_id).unwrap(), the_response);
|
||||
|
||||
// Second time it doesn't, since we're not.
|
||||
let r = XcmExecutor::<TestConfig>::execute_xcm(origin.clone(), message.clone(), weight_limit);
|
||||
let r = XcmExecutor::<TestConfig>::execute_xcm(Parent, message.clone(), weight_limit);
|
||||
assert_eq!(r, Outcome::Error(XcmError::Barrier));
|
||||
}
|
||||
|
||||
|
||||
@@ -47,8 +47,8 @@ pub fn sent_xcm() -> Vec<(MultiLocation, opaque::Xcm)> {
|
||||
}
|
||||
pub struct TestSendXcm;
|
||||
impl SendXcm for TestSendXcm {
|
||||
fn send_xcm(dest: MultiLocation, msg: opaque::Xcm) -> SendResult {
|
||||
SENT_XCM.with(|q| q.borrow_mut().push((dest, msg)));
|
||||
fn send_xcm(dest: impl Into<MultiLocation>, msg: opaque::Xcm) -> SendResult {
|
||||
SENT_XCM.with(|q| q.borrow_mut().push((dest.into(), msg)));
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user