Newer
Older
// Copyright 2020-2021 Parity Technologies (UK) Ltd.
// This file is part of Polkadot.
// Polkadot is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Polkadot is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.
//! Pallet to handle XCM messages.
#![cfg_attr(not(feature = "std"), no_std)]
#[cfg(test)]
mod mock;
#[cfg(test)]
mod tests;
use codec::{Decode, Encode, EncodeLike, MaxEncodedLen};
use frame_support::traits::{
Contains, ContainsPair, Currency, Defensive, EnsureOrigin, Get, LockableCurrency, OriginTrait,
};
use scale_info::TypeInfo;
traits::{
AccountIdConversion, BadOrigin, BlakeTwo256, BlockNumberProvider, Hash, Saturating, Zero,
},
use sp_std::{boxed::Box, marker::PhantomData, prelude::*, result::Result, vec};
use xcm::{latest::QueryResponseInfo, prelude::*};
use xcm_executor::traits::{Convert, ConvertOrigin};
use frame_support::{
dispatch::{Dispatchable, GetDispatchInfo},
pallet_prelude::*,
traits::WithdrawReasons,
PalletId,
};
use frame_system::pallet_prelude::*;
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
use xcm_executor::{
traits::{
ClaimAssets, DropAssets, MatchesFungible, OnResponse, VersionChangeNotifier, WeightBounds,
},
Assets,
};
pub trait WeightInfo {
fn send() -> Weight;
fn teleport_assets() -> Weight;
fn reserve_transfer_assets() -> Weight;
fn execute() -> Weight;
fn force_xcm_version() -> Weight;
fn force_default_xcm_version() -> Weight;
fn force_subscribe_version_notify() -> Weight;
fn force_unsubscribe_version_notify() -> Weight;
fn migrate_supported_version() -> Weight;
fn migrate_version_notifiers() -> Weight;
fn already_notified_target() -> Weight;
fn notify_current_targets() -> Weight;
fn notify_target_migration_fail() -> Weight;
fn migrate_version_notify_targets() -> Weight;
fn migrate_and_notify_old_targets() -> Weight;
}
/// fallback implementation
pub struct TestWeightInfo;
impl WeightInfo for TestWeightInfo {
fn send() -> Weight {
Weight::from_ref_time(100_000_000)
}
fn teleport_assets() -> Weight {
Weight::from_ref_time(100_000_000)
}
fn reserve_transfer_assets() -> Weight {
Weight::from_ref_time(100_000_000)
}
fn execute() -> Weight {
Weight::from_ref_time(100_000_000)
}
fn force_xcm_version() -> Weight {
Weight::from_ref_time(100_000_000)
}
fn force_default_xcm_version() -> Weight {
Weight::from_ref_time(100_000_000)
}
fn force_subscribe_version_notify() -> Weight {
Weight::from_ref_time(100_000_000)
}
fn force_unsubscribe_version_notify() -> Weight {
Weight::from_ref_time(100_000_000)
}
fn migrate_supported_version() -> Weight {
Weight::from_ref_time(100_000_000)
}
fn migrate_version_notifiers() -> Weight {
Weight::from_ref_time(100_000_000)
}
fn already_notified_target() -> Weight {
Weight::from_ref_time(100_000_000)
}
fn notify_current_targets() -> Weight {
Weight::from_ref_time(100_000_000)
}
fn notify_target_migration_fail() -> Weight {
Weight::from_ref_time(100_000_000)
}
fn migrate_version_notify_targets() -> Weight {
Weight::from_ref_time(100_000_000)
}
fn migrate_and_notify_old_targets() -> Weight {
Weight::from_ref_time(100_000_000)
}
}
#[frame_support::pallet]
pub mod pallet {
use super::*;
Gavin Wood
committed
use frame_support::{
dispatch::{Dispatchable, GetDispatchInfo, PostDispatchInfo},
Gavin Wood
committed
};
use sp_core::H256;
parameter_types! {
/// An implementation of `Get<u32>` which just returns the latest XCM version which we can
/// support.
pub const CurrentXcmVersion: u32 = XCM_VERSION;
}
#[pallet::pallet]
#[pallet::generate_store(pub(super) trait Store)]
#[pallet::without_storage_info]
pub type BalanceOf<T> =
<<T as Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::Balance;
#[pallet::config]
/// The module configuration trait.
pub trait Config: frame_system::Config {
/// The overarching event type.
type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;
/// A lockable currency.
// TODO: We should really use a trait which can handle multiple currencies.
type Currency: LockableCurrency<Self::AccountId, Moment = Self::BlockNumber>;
/// The `MultiAsset` matcher for `Currency`.
type CurrencyMatcher: MatchesFungible<BalanceOf<Self>>;
/// Required origin for sending XCM messages. If successful, it resolves to `MultiLocation`
/// which exists as an interior location within this chain's XCM context.
type SendXcmOrigin: EnsureOrigin<
<Self as SysConfig>::RuntimeOrigin,
Success = MultiLocation,
>;
/// The type used to actually dispatch an XCM to its destination.
type XcmRouter: SendXcm;
/// Required origin for executing XCM messages, including the teleport functionality. If successful,
/// then it resolves to `MultiLocation` which exists as an interior location within this chain's XCM
type ExecuteXcmOrigin: EnsureOrigin<
<Self as SysConfig>::RuntimeOrigin,
Success = MultiLocation,
>;
/// Our XCM filter which messages to be executed using `XcmExecutor` must pass.
type XcmExecuteFilter: Contains<(MultiLocation, Xcm<<Self as SysConfig>::RuntimeCall>)>;
Loading full blame...