mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 11:41:02 +00:00
Integrate a governance XCM origin (#407)
* Introduce the converter into the hub * Parachain recognises Rococo governance body as admin * Whitespace * Use UsingComponents for fee payment in XCM * Fixes * Fixes for XCM permissions * Remove encode_call test * Fixes * Fixes * Fixes
This commit is contained in:
+59
-3
@@ -20,13 +20,17 @@
|
||||
|
||||
#![cfg_attr(not(feature = "std"), no_std)]
|
||||
|
||||
use cumulus_primitives_core::ParaId;
|
||||
use sp_std::convert::TryFrom;
|
||||
use cumulus_primitives_core::{ParaId, DownwardMessageHandler, InboundDownwardMessage};
|
||||
use codec::{Encode, Decode};
|
||||
use sp_runtime::traits::BadOrigin;
|
||||
use xcm::{VersionedXcm, v0::{Xcm, Junction, Outcome, ExecuteXcm}};
|
||||
use frame_support::{traits::Get, dispatch::Weight};
|
||||
pub use pallet::*;
|
||||
|
||||
#[frame_support::pallet]
|
||||
pub mod pallet {
|
||||
use super::*;
|
||||
use frame_support::pallet_prelude::*;
|
||||
use frame_system::pallet_prelude::*;
|
||||
|
||||
@@ -36,16 +40,68 @@ pub mod pallet {
|
||||
|
||||
/// The module configuration trait.
|
||||
#[pallet::config]
|
||||
pub trait Config: frame_system::Config {}
|
||||
pub trait Config: frame_system::Config {
|
||||
/// The overarching event type.
|
||||
type Event: From<Event<Self>> + IsType<<Self as frame_system::Config>::Event>;
|
||||
|
||||
type XcmExecutor: ExecuteXcm<Self::Call>;
|
||||
|
||||
#[pallet::constant]
|
||||
type MaxWeight: Get<Weight>;
|
||||
}
|
||||
|
||||
#[pallet::error]
|
||||
pub enum Error<T> {}
|
||||
pub enum Error<T> {
|
||||
}
|
||||
|
||||
#[pallet::hooks]
|
||||
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {}
|
||||
|
||||
#[pallet::call]
|
||||
impl<T: Config> Pallet<T> {}
|
||||
|
||||
#[pallet::event]
|
||||
#[pallet::generate_deposit(pub(super) fn deposit_event)]
|
||||
#[pallet::metadata(T::BlockNumber = "BlockNumber")]
|
||||
pub enum Event<T: Config> {
|
||||
/// Downward message is invalid XCM.
|
||||
/// \[ id \]
|
||||
InvalidFormat([u8; 8]),
|
||||
/// Downward message is unsupported version of XCM.
|
||||
/// \[ id \]
|
||||
UnsupportedVersion([u8; 8]),
|
||||
/// Downward message executed with the given outcome.
|
||||
/// \[ id, outcome \]
|
||||
ExecutedDownward([u8; 8], Outcome),
|
||||
}
|
||||
|
||||
/// For an incoming downward message, this just adapts an XCM executor and executes DMP messages
|
||||
/// immediately up until some `MaxWeight` at which point it errors. Their origin is asserted to be
|
||||
/// the Parent location.
|
||||
impl<T: Config> DownwardMessageHandler for Pallet<T> {
|
||||
fn handle_downward_message(msg: InboundDownwardMessage) -> Weight {
|
||||
let id = sp_io::hashing::twox_64(&msg.msg[..]);
|
||||
let msg = VersionedXcm::<T::Call>::decode(&mut &msg.msg[..])
|
||||
.map(Xcm::<T::Call>::try_from);
|
||||
match msg {
|
||||
Ok(Ok(x)) => {
|
||||
let weight_limit = T::MaxWeight::get();
|
||||
let outcome = T::XcmExecutor::execute_xcm(Junction::Parent.into(), x, weight_limit);
|
||||
let weight_used = outcome.weight_used();
|
||||
Self::deposit_event(Event::ExecutedDownward(id, outcome));
|
||||
weight_used
|
||||
}
|
||||
Ok(Err(())) => {
|
||||
Self::deposit_event(Event::UnsupportedVersion(id));
|
||||
0
|
||||
},
|
||||
Err(_) => {
|
||||
Self::deposit_event(Event::InvalidFormat(id));
|
||||
0
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Origin for the parachains module.
|
||||
|
||||
Reference in New Issue
Block a user