mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 10:31:03 +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:
@@ -0,0 +1,39 @@
|
||||
[package]
|
||||
name = "cumulus-upward-message"
|
||||
version = "0.1.0"
|
||||
authors = ["Parity Technologies <admin@parity.io>"]
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
# Substrate dependencies
|
||||
sp-std = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch", default-features = false }
|
||||
|
||||
# Polkadot deps
|
||||
polkadot-core-primitives = { git = "https://github.com/paritytech/polkadot", branch = "cumulus-branch", default-features = false }
|
||||
polkadot-parachain = { git = "https://github.com/paritytech/polkadot", branch = "cumulus-branch", default-features = false }
|
||||
|
||||
# All these should be optional dependenices, but given the perfect Cargo, it is not possible.
|
||||
polkadot-runtime = { git = "https://github.com/paritytech/polkadot", branch = "cumulus-branch", default-features = false }
|
||||
kusama-runtime = { git = "https://github.com/paritytech/polkadot", branch = "cumulus-branch", default-features = false }
|
||||
westend-runtime = { git = "https://github.com/paritytech/polkadot", branch = "cumulus-branch", default-features = false }
|
||||
|
||||
[features]
|
||||
default = [ "std" ]
|
||||
std = [
|
||||
"sp-std/std",
|
||||
"polkadot-runtime/std",
|
||||
"kusama-runtime/std",
|
||||
"westend-runtime/std",
|
||||
"polkadot-core-primitives/std",
|
||||
"polkadot-parachain/std",
|
||||
]
|
||||
# Should be enabled by when compiling the runtime for WASM.
|
||||
#
|
||||
# This disables the runtime api of the Polkadot/Kusama/Westend
|
||||
# runtimes to not clash with the runtime api of the Parachain when building
|
||||
# for WASM.
|
||||
runtime-wasm = [
|
||||
"polkadot-runtime/disable-runtime-api",
|
||||
"westend-runtime/disable-runtime-api",
|
||||
"kusama-runtime/disable-runtime-api",
|
||||
]
|
||||
@@ -0,0 +1,37 @@
|
||||
// Copyright 2020 Parity Technologies (UK) Ltd.
|
||||
// This file is part of Cumulus.
|
||||
|
||||
// Substrate is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// Substrate is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Cumulus. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
//! Kusama upward message
|
||||
|
||||
use crate::*;
|
||||
use polkadot_core_primitives::{Balance, AccountId};
|
||||
use kusama_runtime::{BalancesCall, ParachainsCall};
|
||||
use sp_std::vec::Vec;
|
||||
|
||||
/// The Kusama upward message.
|
||||
pub type UpwardMessage = kusama_runtime::Call;
|
||||
|
||||
impl BalancesMessage<AccountId, Balance> for UpwardMessage {
|
||||
fn transfer(dest: AccountId, amount: Balance) -> Self {
|
||||
BalancesCall::transfer(dest, amount).into()
|
||||
}
|
||||
}
|
||||
|
||||
impl XCMPMessage for UpwardMessage {
|
||||
fn send_message(dest: ParaId, msg: Vec<u8>) -> Self {
|
||||
ParachainsCall::send_xcmp_message(dest, msg).into()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
// Copyright 2020 Parity Technologies (UK) Ltd.
|
||||
// This file is part of Cumulus.
|
||||
|
||||
// Substrate is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// Substrate is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Cumulus. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
//! Upward messages types and traits for Polkadot, Kusama and Westend.
|
||||
//!
|
||||
//! As Cumulus needs to suits multiple Polkadot-like runtimes the upward message
|
||||
//! type is different for each of them. To support all of them, Cumulus provides
|
||||
//! traits to write upward message generic code.
|
||||
|
||||
#![cfg_attr(not(feature = "std"), no_std)]
|
||||
|
||||
use polkadot_parachain::primitives::Id as ParaId;
|
||||
use sp_std::vec::Vec;
|
||||
|
||||
mod polkadot;
|
||||
mod kusama;
|
||||
mod westend;
|
||||
|
||||
pub use polkadot::UpwardMessage as PolkadotUpwardMessage;
|
||||
pub use kusama::UpwardMessage as KusamaUpwardMessage;
|
||||
pub use westend::UpwardMessage as WestendUpwardMessage;
|
||||
|
||||
/// A `Balances` related upward message.
|
||||
pub trait BalancesMessage<AccountId, Balance>: Sized {
|
||||
/// Transfer the given `amount` from the parachain account to the given
|
||||
/// `dest` account.
|
||||
fn transfer(dest: AccountId, amount: Balance) -> Self;
|
||||
}
|
||||
|
||||
/// A `XCMP` related upward message.
|
||||
pub trait XCMPMessage: Sized {
|
||||
/// Send the given XCMP message to given parachain.
|
||||
fn send_message(dest: ParaId, msg: Vec<u8>) -> Self;
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
// Copyright 2020 Parity Technologies (UK) Ltd.
|
||||
// This file is part of Cumulus.
|
||||
|
||||
// Substrate is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// Substrate is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Cumulus. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
//! Polkadot upward message
|
||||
|
||||
use crate::*;
|
||||
use polkadot_core_primitives::{Balance, AccountId};
|
||||
use polkadot_runtime::{BalancesCall, ParachainsCall};
|
||||
use sp_std::vec::Vec;
|
||||
|
||||
/// The Polkadot upward message.
|
||||
pub type UpwardMessage = polkadot_runtime::Call;
|
||||
|
||||
impl BalancesMessage<AccountId, Balance> for UpwardMessage {
|
||||
fn transfer(dest: AccountId, amount: Balance) -> Self {
|
||||
BalancesCall::transfer(dest, amount).into()
|
||||
}
|
||||
}
|
||||
|
||||
impl XCMPMessage for UpwardMessage {
|
||||
fn send_message(dest: ParaId, msg: Vec<u8>) -> Self {
|
||||
ParachainsCall::send_xcmp_message(dest, msg).into()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
// Copyright 2020 Parity Technologies (UK) Ltd.
|
||||
// This file is part of Cumulus.
|
||||
|
||||
// Substrate is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// Substrate is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Cumulus. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
//! Westend upward message
|
||||
|
||||
use crate::*;
|
||||
use polkadot_core_primitives::{Balance, AccountId};
|
||||
use westend_runtime::{BalancesCall, ParachainsCall};
|
||||
use sp_std::vec::Vec;
|
||||
|
||||
/// The Westend upward message.
|
||||
pub type UpwardMessage = westend_runtime::Call;
|
||||
|
||||
impl BalancesMessage<AccountId, Balance> for UpwardMessage {
|
||||
fn transfer(dest: AccountId, amount: Balance) -> Self {
|
||||
BalancesCall::transfer(dest, amount).into()
|
||||
}
|
||||
}
|
||||
|
||||
impl XCMPMessage for UpwardMessage {
|
||||
fn send_message(dest: ParaId, msg: Vec<u8>) -> Self {
|
||||
ParachainsCall::send_xcmp_message(dest, msg).into()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user