mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-16 21:21:03 +00:00
Make the price of UMP/XCMP message sending configurable
This commit is contained in:
@@ -99,6 +99,9 @@ pub mod pallet {
|
||||
/// superuser origin.
|
||||
type ControllerOriginConverter: ConvertOrigin<Self::Origin>;
|
||||
|
||||
/// The price for delivering an XCM to a sibling parachain destination.
|
||||
type PriceForSiblingDelivery: PriceForSiblingDelivery;
|
||||
|
||||
/// The weight information of this pallet.
|
||||
type WeightInfo: WeightInfo;
|
||||
}
|
||||
@@ -1077,6 +1080,23 @@ impl<T: Config> XcmpMessageSource for Pallet<T> {
|
||||
}
|
||||
}
|
||||
|
||||
pub trait PriceForSiblingDelivery {
|
||||
fn price_for_sibling_delivery(id: ParaId, message: &Xcm<()>) -> MultiAssets;
|
||||
}
|
||||
|
||||
impl PriceForSiblingDelivery for () {
|
||||
fn price_for_sibling_delivery(_: ParaId, _: &Xcm<()>) -> MultiAssets {
|
||||
MultiAssets::new()
|
||||
}
|
||||
}
|
||||
|
||||
pub struct ConstantPrice<T>(sp_std::marker::PhantomData<T>);
|
||||
impl<T: Get<MultiAssets>> PriceForSiblingDelivery for ConstantPrice<T> {
|
||||
fn price_for_sibling_delivery(_: ParaId, _: &Xcm<()>) -> MultiAssets {
|
||||
T::get()
|
||||
}
|
||||
}
|
||||
|
||||
/// Xcm sender for sending to a sibling parachain.
|
||||
impl<T: Config> SendXcm for Pallet<T> {
|
||||
type Ticket = (ParaId, VersionedXcm<()>);
|
||||
@@ -1091,9 +1111,11 @@ impl<T: Config> SendXcm for Pallet<T> {
|
||||
match &d {
|
||||
// An HRMP message for a sibling parachain.
|
||||
MultiLocation { parents: 1, interior: X1(Parachain(id)) } => {
|
||||
let id = ParaId::from(*id);
|
||||
let price = T::PriceForSiblingDelivery::price_for_sibling_delivery(id, &xcm);
|
||||
let versioned_xcm = T::VersionWrapper::wrap_version(&d, xcm)
|
||||
.map_err(|()| SendError::DestinationUnsupported)?;
|
||||
Ok((((*id).into(), versioned_xcm), MultiAssets::new()))
|
||||
Ok(((id, versioned_xcm), price))
|
||||
},
|
||||
// Anything else is unhandled. This includes a message this is meant for us.
|
||||
_ => {
|
||||
|
||||
@@ -21,9 +21,27 @@
|
||||
|
||||
use codec::Encode;
|
||||
use cumulus_primitives_core::{MessageSendError, UpwardMessageSender};
|
||||
use frame_support::traits::Get;
|
||||
use sp_std::{marker::PhantomData, prelude::*};
|
||||
use xcm::{latest::prelude::*, WrapVersion};
|
||||
|
||||
pub trait PriceForParentDelivery {
|
||||
fn price_for_parent_delivery(message: &Xcm<()>) -> MultiAssets;
|
||||
}
|
||||
|
||||
impl PriceForParentDelivery for () {
|
||||
fn price_for_parent_delivery(_: &Xcm<()>) -> MultiAssets {
|
||||
MultiAssets::new()
|
||||
}
|
||||
}
|
||||
|
||||
pub struct ConstantPrice<T>(PhantomData<T>);
|
||||
impl<T: Get<MultiAssets>> PriceForParentDelivery for ConstantPrice<T> {
|
||||
fn price_for_parent_delivery(_: &Xcm<()>) -> MultiAssets {
|
||||
T::get()
|
||||
}
|
||||
}
|
||||
|
||||
/// Xcm router which recognises the `Parent` destination and handles it by sending the message into
|
||||
/// the given UMP `UpwardMessageSender` implementation. Thus this essentially adapts an
|
||||
/// `UpwardMessageSender` trait impl into a `SendXcm` trait impl.
|
||||
@@ -31,8 +49,13 @@ use xcm::{latest::prelude::*, WrapVersion};
|
||||
/// NOTE: This is a pretty dumb "just send it" router; we will probably want to introduce queuing
|
||||
/// to UMP eventually and when we do, the pallet which implements the queuing will be responsible
|
||||
/// for the `SendXcm` implementation.
|
||||
pub struct ParentAsUmp<T, W>(PhantomData<(T, W)>);
|
||||
impl<T: UpwardMessageSender, W: WrapVersion> SendXcm for ParentAsUmp<T, W> {
|
||||
pub struct ParentAsUmp<T, W, P>(PhantomData<(T, W, P)>);
|
||||
impl<T, W, P> SendXcm for ParentAsUmp<T, W, P>
|
||||
where
|
||||
T: UpwardMessageSender,
|
||||
W: WrapVersion,
|
||||
P: PriceForParentDelivery,
|
||||
{
|
||||
type Ticket = Vec<u8>;
|
||||
|
||||
fn validate(
|
||||
@@ -44,11 +67,12 @@ impl<T: UpwardMessageSender, W: WrapVersion> SendXcm for ParentAsUmp<T, W> {
|
||||
|
||||
if d.contains_parents_only(1) {
|
||||
// An upward message for the relay chain.
|
||||
let price = P::price_for_parent_delivery(&xcm);
|
||||
let versioned_xcm =
|
||||
W::wrap_version(&d, xcm).map_err(|()| SendError::DestinationUnsupported)?;
|
||||
let data = versioned_xcm.encode();
|
||||
|
||||
Ok((data, MultiAssets::new()))
|
||||
Ok((data, price))
|
||||
} else {
|
||||
*dest = Some(d);
|
||||
// Anything else is unhandled. This includes a message this is meant for us.
|
||||
|
||||
Reference in New Issue
Block a user