mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-16 16:41:10 +00:00
Implement basic upward & downward messages (#118)
* Start by replacing branch names and set `DownwardMessage` * Add the upward-message crate * Add Kusama & Polkadot * More work on getting the upward messages working * Fix build * Begin to integrate it into the test Parachain * Update * Make everything compile again * Switch to westend and print parachain account on startup * Use MultiSignature etc * Fix validate block * Some downward messages work * Update git reference * More downward messages integration * Update test runtime for downward messages * Enable downward message handler and withdraw send tokens * Add some docs * Begin to implement simple XCMP * More work * Fixes and make parachain id configurable * Make parachain ID be part of the genesis * Finishing the XCMP message demo * Update and fixes tests * Update branch
This commit is contained in:
+23
-7
@@ -18,7 +18,18 @@
|
||||
|
||||
#![cfg_attr(not(feature = "std"), no_std)]
|
||||
|
||||
pub use polkadot_core_primitives as relay_chain;
|
||||
pub use polkadot_core_primitives::DownwardMessage;
|
||||
/// A generic upward message from a Parachain to the Relay Chain.
|
||||
///
|
||||
/// It is "generic" in such a way, that the actual message is encoded in the `data` field.
|
||||
/// Besides the `data` it also holds the `origin` of the message.
|
||||
pub use polkadot_parachain::primitives::UpwardMessage as GenericUpwardMessage;
|
||||
pub use polkadot_parachain::primitives::ParachainDispatchOrigin as UpwardMessageOrigin;
|
||||
pub use polkadot_parachain::primitives::Id as ParaId;
|
||||
|
||||
pub mod validation_function_params;
|
||||
pub mod xcmp;
|
||||
|
||||
use codec::{Decode, Encode};
|
||||
use sp_runtime::traits::Block as BlockT;
|
||||
@@ -31,7 +42,7 @@ pub mod inherents {
|
||||
pub const DOWNWARD_MESSAGES_IDENTIFIER: InherentIdentifier = *b"cumdownm";
|
||||
|
||||
/// The type of the inherent downward messages.
|
||||
pub type DownwardMessagesType = sp_std::vec::Vec<()>;
|
||||
pub type DownwardMessagesType = sp_std::vec::Vec<crate::DownwardMessage>;
|
||||
|
||||
/// The identifier for the `validation_function_params` inherent.
|
||||
pub const VALIDATION_FUNCTION_PARAMS_IDENTIFIER: InherentIdentifier = *b"valfunp0";
|
||||
@@ -43,29 +54,34 @@ pub mod inherents {
|
||||
pub mod well_known_keys {
|
||||
/// The storage key for the upward messages.
|
||||
///
|
||||
/// The upward messages are stored as SCALE encoded `Vec<()>`.
|
||||
/// The upward messages are stored as SCALE encoded `Vec<GenericUpwardMessage>`.
|
||||
pub const UPWARD_MESSAGES: &'static [u8] = b":cumulus_upward_messages:";
|
||||
|
||||
/// Current validation function parameters.
|
||||
pub const VALIDATION_FUNCTION_PARAMS: &'static [u8] = b":validation_function_params";
|
||||
pub const VALIDATION_FUNCTION_PARAMS: &'static [u8] = b":cumulus_validation_function_params";
|
||||
|
||||
/// Code upgarde (set as appropriate by a pallet).
|
||||
pub const NEW_VALIDATION_CODE: &'static [u8] = b":new_validation_code";
|
||||
pub const NEW_VALIDATION_CODE: &'static [u8] = b":cumulus_new_validation_code";
|
||||
|
||||
/// The storage key for the processed downward messages.
|
||||
///
|
||||
/// The value is stored as SCALE encoded `u32`.
|
||||
pub const PROCESSED_DOWNWARD_MESSAGES: &'static [u8] = b":cumulus_processed_downward_messages:";
|
||||
}
|
||||
|
||||
/// Something that should be called when a downward message is received.
|
||||
#[impl_trait_for_tuples::impl_for_tuples(30)]
|
||||
pub trait DownwardMessageHandler {
|
||||
/// Handle the given downward message.
|
||||
fn handle_downward_message(msg: &());
|
||||
fn handle_downward_message(msg: &DownwardMessage);
|
||||
}
|
||||
|
||||
/// Something that can send upward messages.
|
||||
pub trait UpwardMessageSender {
|
||||
pub trait UpwardMessageSender<UpwardMessage> {
|
||||
/// Send an upward message to the relay chain.
|
||||
///
|
||||
/// Returns an error if sending failed.
|
||||
fn send_upward_message(msg: &()) -> Result<(), ()>;
|
||||
fn send_upward_message(msg: &UpwardMessage, origin: UpwardMessageOrigin) -> Result<(), ()>;
|
||||
}
|
||||
|
||||
/// The head data of the parachain, stored in the relay chain.
|
||||
|
||||
Reference in New Issue
Block a user