mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-27 22:07:58 +00:00
sudo_queue_downward_message (#1941)
* Add a sudo wrapper for Dmp::queue_downward_message * Apply suggestions from code review Co-authored-by: Peter Goodspeed-Niklaus <coriolinus@users.noreply.github.com> * Stylistic changes * Remove trailing whitespaces Co-authored-by: Peter Goodspeed-Niklaus <coriolinus@users.noreply.github.com>
This commit is contained in:
@@ -16,22 +16,32 @@
|
||||
|
||||
//! A simple wrapper allowing `Sudo` to call into `paras` routines.
|
||||
|
||||
use sp_std::prelude::*;
|
||||
use frame_support::{
|
||||
decl_error, decl_module,
|
||||
decl_error, decl_module, ensure,
|
||||
dispatch::DispatchResult,
|
||||
weights::DispatchClass,
|
||||
};
|
||||
use frame_system::ensure_root;
|
||||
use runtime_parachains::{
|
||||
dmp, ump, hrmp, paras::{self, ParaGenesisArgs},
|
||||
configuration, dmp, ump, hrmp, paras::{self, ParaGenesisArgs},
|
||||
};
|
||||
use primitives::v1::Id as ParaId;
|
||||
|
||||
/// The module's configuration trait.
|
||||
pub trait Trait: paras::Trait + dmp::Trait + ump::Trait + hrmp::Trait { }
|
||||
pub trait Trait:
|
||||
configuration::Trait + paras::Trait + dmp::Trait + ump::Trait + hrmp::Trait
|
||||
{
|
||||
}
|
||||
|
||||
decl_error! {
|
||||
pub enum Error for Module<T: Trait> { }
|
||||
pub enum Error for Module<T: Trait> {
|
||||
/// The specified parachain or parathread is not registered.
|
||||
ParaDoesntExist,
|
||||
/// A DMP message couldn't be sent because it exceeds the maximum size allowed for a downward
|
||||
/// message.
|
||||
ExceedsMaxMessageSize,
|
||||
}
|
||||
}
|
||||
|
||||
decl_module! {
|
||||
@@ -58,5 +68,21 @@ decl_module! {
|
||||
runtime_parachains::schedule_para_cleanup::<T>(id);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Send a downward message to the given para.
|
||||
///
|
||||
/// The given parachain should exist and the payload should not exceed the preconfigured size
|
||||
/// `config.max_downward_message_size`.
|
||||
#[weight = (1_000, DispatchClass::Operational)]
|
||||
pub fn sudo_queue_downward_message(origin, id: ParaId, payload: Vec<u8>) -> DispatchResult {
|
||||
ensure_root(origin)?;
|
||||
ensure!(<paras::Module<T>>::is_valid_para(id), Error::<T>::ParaDoesntExist);
|
||||
let config = <configuration::Module<T>>::config();
|
||||
<dmp::Module<T>>::queue_downward_message(&config, id, payload)
|
||||
.map_err(|e| match e {
|
||||
dmp::QueueDownwardMessageError::ExceedsMaxMessageSize =>
|
||||
Error::<T>::ExceedsMaxMessageSize.into(),
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user