Skip to content

Commit

Permalink
add DryRunApi and LocationToAccountApi
Browse files Browse the repository at this point in the history
  • Loading branch information
Agusrodri committed Sep 25, 2024
1 parent e473197 commit abd48b3
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 3 deletions.
1 change: 1 addition & 0 deletions runtime/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ runtime-benchmarks = [
"pallet-xcm/runtime-benchmarks",
"pallet-moonbeam-lazy-migrations/runtime-benchmarks",
"moonbeam-xcm-benchmarks/runtime-benchmarks",
"xcm-runtime-apis/runtime-benchmarks",
]
try-runtime = [
"cumulus-pallet-parachain-system/try-runtime",
Expand Down
36 changes: 36 additions & 0 deletions runtime/common/src/apis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -765,6 +765,42 @@ macro_rules! impl_runtime_apis_plus_common {
}
}

impl xcm_runtime_apis::dry_run::DryRunApi<Block, RuntimeCall, RuntimeEvent, OriginCaller> for Runtime {
fn dry_run_call(
origin: OriginCaller,
call: RuntimeCall
) -> Result<CallDryRunEffects<RuntimeEvent>, XcmDryRunApiError> {
PolkadotXcm::dry_run_call::<
Runtime,
xcm_config::XcmRouter,
OriginCaller,
RuntimeCall>(origin, call)
}

fn dry_run_xcm(
origin_location: VersionedLocation,
xcm: VersionedXcm<RuntimeCall>
) -> Result<XcmDryRunEffects<RuntimeEvent>, XcmDryRunApiError> {
PolkadotXcm::dry_run_xcm::<
Runtime,
xcm_config::XcmRouter,
RuntimeCall,
xcm_config::XcmExecutorConfig>(origin_location, xcm)
}
}

impl xcm_runtime_apis::conversions::LocationToAccountApi<Block, AccountId> for Runtime {
fn convert_location(location: VersionedLocation) -> Result<
AccountId,
xcm_runtime_apis::conversions::Error
> {
xcm_runtime_apis::conversions::LocationToAccountHelper::<
AccountId,
xcm_config::LocationToAccountId,
>::convert_location(location)
}
}

#[cfg(feature = "runtime-benchmarks")]
impl frame_benchmarking::Benchmark<Block> for Runtime {

Expand Down
1 change: 1 addition & 0 deletions runtime/moonbase/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,7 @@ runtime-benchmarks = [
"session-keys-primitives/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
"xcm-builder/runtime-benchmarks",
"xcm-runtime-apis/runtime-benchmarks",
]

try-runtime = [
Expand Down
8 changes: 7 additions & 1 deletion runtime/moonbase/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,13 @@ use sp_std::{
use sp_version::NativeVersion;
use sp_version::RuntimeVersion;
use xcm::{VersionedAssetId, VersionedAssets, VersionedLocation, VersionedXcm};
use xcm_runtime_apis::fees::Error as XcmPaymentApiError;
//use xcm_runtime_apis::fees::Error as XcmPaymentApiError;

//use xcm_fee_payment_runtime_api::Error as XcmPaymentApiError;
use xcm_runtime_apis::{
dry_run::{CallDryRunEffects, Error as XcmDryRunApiError, XcmDryRunEffects},
fees::Error as XcmPaymentApiError,
};

use smallvec::smallvec;
use sp_runtime::serde::{Deserialize, Serialize};
Expand Down
1 change: 1 addition & 0 deletions runtime/moonbeam/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,7 @@ runtime-benchmarks = [
"session-keys-primitives/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
"xcm-builder/runtime-benchmarks",
"xcm-runtime-apis/runtime-benchmarks",
]

try-runtime = [
Expand Down
8 changes: 7 additions & 1 deletion runtime/moonbeam/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,13 @@ use sp_runtime::{
};
use sp_std::{convert::TryFrom, prelude::*};
use xcm::{VersionedAssetId, VersionedAssets, VersionedLocation, VersionedXcm};
use xcm_runtime_apis::fees::Error as XcmPaymentApiError;
//use xcm_runtime_apis::fees::Error as XcmPaymentApiError;

//use xcm_fee_payment_runtime_api::Error as XcmPaymentApiError;
use xcm_runtime_apis::{
dry_run::{CallDryRunEffects, Error as XcmDryRunApiError, XcmDryRunEffects},
fees::Error as XcmPaymentApiError,
};

#[cfg(feature = "std")]
use sp_version::NativeVersion;
Expand Down
1 change: 1 addition & 0 deletions runtime/moonriver/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,7 @@ runtime-benchmarks = [
"session-keys-primitives/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
"xcm-builder/runtime-benchmarks",
"xcm-runtime-apis/runtime-benchmarks",
]
try-runtime = [
"cumulus-pallet-parachain-system/try-runtime",
Expand Down
8 changes: 7 additions & 1 deletion runtime/moonriver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,13 @@ use sp_runtime::{
};
use sp_std::{convert::TryFrom, prelude::*};
use xcm::{VersionedAssetId, VersionedAssets, VersionedLocation, VersionedXcm};
use xcm_runtime_apis::fees::Error as XcmPaymentApiError;
//use xcm_runtime_apis::fees::Error as XcmPaymentApiError;

//use xcm_fee_payment_runtime_api::Error as XcmPaymentApiError;
use xcm_runtime_apis::{
dry_run::{CallDryRunEffects, Error as XcmDryRunApiError, XcmDryRunEffects},
fees::Error as XcmPaymentApiError,
};

use smallvec::smallvec;
#[cfg(feature = "std")]
Expand Down

0 comments on commit abd48b3

Please sign in to comment.