use alloc::boxed::Box;
use pezframe_support::{
dispatch::{DispatchErrorWithPostInfo, WithPostDispatchInfo},
pezpallet_prelude::DispatchError,
};
use xcm::prelude::*;
pub use xcm_executor::traits::QueryHandler;
pub trait Controller<Origin, RuntimeCall, Timeout>:
ExecuteController<Origin, RuntimeCall> + SendController<Origin> + QueryController<Origin, Timeout>
{
}
impl<T, Origin, RuntimeCall, Timeout> Controller<Origin, RuntimeCall, Timeout> for T where
T: ExecuteController<Origin, RuntimeCall>
+ SendController<Origin>
+ QueryController<Origin, Timeout>
{
}
pub trait ExecuteControllerWeightInfo {
fn execute() -> Weight;
}
pub trait ExecuteController<Origin, RuntimeCall> {
type WeightInfo: ExecuteControllerWeightInfo;
fn execute(
origin: Origin,
message: Box<VersionedXcm<RuntimeCall>>,
max_weight: Weight,
) -> Result<Weight, DispatchErrorWithPostInfo>;
}
pub trait SendControllerWeightInfo {
fn send() -> Weight;
}
pub trait SendController<Origin> {
type WeightInfo: SendControllerWeightInfo;
fn send(
origin: Origin,
dest: Box<VersionedLocation>,
message: Box<VersionedXcm<()>>,
) -> Result<XcmHash, DispatchError>;
}
pub trait QueryControllerWeightInfo {
fn query() -> Weight;
fn take_response() -> Weight;
}
pub trait QueryController<Origin, Timeout>: QueryHandler {
type WeightInfo: QueryControllerWeightInfo;
fn query(
origin: Origin,
timeout: Timeout,
match_querier: VersionedLocation,
) -> Result<QueryId, DispatchError>;
}
impl<Origin, RuntimeCall> ExecuteController<Origin, RuntimeCall> for () {
type WeightInfo = ();
fn execute(
_origin: Origin,
_message: Box<VersionedXcm<RuntimeCall>>,
_max_weight: Weight,
) -> Result<Weight, DispatchErrorWithPostInfo> {
Err(DispatchError::Other("ExecuteController::execute not implemented")
.with_weight(Weight::zero()))
}
}
impl ExecuteControllerWeightInfo for () {
fn execute() -> Weight {
Weight::zero()
}
}
impl<Origin> SendController<Origin> for () {
type WeightInfo = ();
fn send(
_origin: Origin,
_dest: Box<VersionedLocation>,
_message: Box<VersionedXcm<()>>,
) -> Result<XcmHash, DispatchError> {
Ok(Default::default())
}
}
impl SendControllerWeightInfo for () {
fn send() -> Weight {
Weight::zero()
}
}
impl QueryControllerWeightInfo for () {
fn query() -> Weight {
Weight::zero()
}
fn take_response() -> Weight {
Weight::zero()
}
}
impl<Origin, Timeout> QueryController<Origin, Timeout> for () {
type WeightInfo = ();
fn query(
_origin: Origin,
_timeout: Timeout,
_match_querier: VersionedLocation,
) -> Result<QueryId, DispatchError> {
Ok(Default::default())
}
}