xcm_fee_payment_runtime_api/
dry_run.rs

1// Copyright (C) Parity Technologies (UK) Ltd.
2// This file is part of Polkadot.
3
4// Substrate is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8
9// Substrate is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12// GNU General Public License for more details.
13
14// You should have received a copy of the GNU General Public License
15// along with Polkadot.  If not, see <http://www.gnu.org/licenses/>.
16
17//! Runtime API definition for dry-running XCM-related extrinsics.
18//! This API can be used to simulate XCMs and, for example, find the fees
19//! that need to be paid.
20
21use codec::{Decode, Encode};
22use frame_support::pallet_prelude::{DispatchResultWithPostInfo, TypeInfo};
23use sp_std::vec::Vec;
24use xcm::prelude::*;
25
26/// Effects of dry-running an extrinsic.
27#[derive(Encode, Decode, Debug, TypeInfo)]
28pub struct CallDryRunEffects<Event> {
29	/// The result of executing the extrinsic.
30	pub execution_result: DispatchResultWithPostInfo,
31	/// The list of events fired by the extrinsic.
32	pub emitted_events: Vec<Event>,
33	/// The local XCM that was attempted to be executed, if any.
34	pub local_xcm: Option<VersionedXcm<()>>,
35	/// The list of XCMs that were queued for sending.
36	pub forwarded_xcms: Vec<(VersionedLocation, Vec<VersionedXcm<()>>)>,
37}
38
39/// Effects of dry-running an XCM program.
40#[derive(Encode, Decode, Debug, TypeInfo)]
41pub struct XcmDryRunEffects<Event> {
42	/// The outcome of the XCM program execution.
43	pub execution_result: Outcome,
44	/// List of events fired by the XCM program execution.
45	pub emitted_events: Vec<Event>,
46	/// List of queued messages for sending.
47	pub forwarded_xcms: Vec<(VersionedLocation, Vec<VersionedXcm<()>>)>,
48}
49
50sp_api::decl_runtime_apis! {
51	/// API for dry-running extrinsics and XCM programs to get the programs that need to be passed to the fees API.
52	///
53	/// All calls return a vector of tuples (location, xcm) where each "xcm" is executed in "location".
54	/// If there's local execution, the location will be "Here".
55	/// This vector can be used to calculate both execution and delivery fees.
56	///
57	/// Calls or XCMs might fail when executed, this doesn't mean the result of these calls will be an `Err`.
58	/// In those cases, there might still be a valid result, with the execution error inside it.
59	/// The only reasons why these calls might return an error are listed in the [`Error`] enum.
60	pub trait DryRunApi<Call: Encode, Event: Decode, OriginCaller: Encode> {
61		/// Dry run call.
62		fn dry_run_call(origin: OriginCaller, call: Call) -> Result<CallDryRunEffects<Event>, Error>;
63
64		/// Dry run XCM program
65		fn dry_run_xcm(origin_location: VersionedLocation, xcm: VersionedXcm<Call>) -> Result<XcmDryRunEffects<Event>, Error>;
66	}
67}
68
69#[derive(Copy, Clone, Encode, Decode, Eq, PartialEq, Debug, TypeInfo)]
70pub enum Error {
71	/// An API call is unsupported.
72	#[codec(index = 0)]
73	Unimplemented,
74
75	/// Converting a versioned data structure from one version to another failed.
76	#[codec(index = 1)]
77	VersionedConversionFailed,
78}