From 3e00c5c02203d94472aab752628fed5d07c5e102 Mon Sep 17 00:00:00 2001 From: Svyatoslav Nikolsky <svyatonik@gmail.com> Date: Tue, 8 Nov 2022 17:43:29 +0300 Subject: [PATCH] Statemine primitives (#1625) * Statemine primitives * ref issue in TODO * fix TODO --- bridges/primitives/chain-kusama/src/lib.rs | 7 -- bridges/primitives/chain-polkadot/Cargo.toml | 2 - bridges/primitives/chain-polkadot/src/lib.rs | 7 -- bridges/primitives/chain-rococo/src/lib.rs | 7 -- bridges/primitives/chain-statemine/Cargo.toml | 24 ++++ bridges/primitives/chain-statemine/src/lib.rs | 38 ++++++ bridges/primitives/chain-westend/Cargo.toml | 6 - bridges/primitives/chain-westend/src/lib.rs | 29 ----- bridges/primitives/chain-wococo/src/lib.rs | 7 -- bridges/relays/bin-substrate/Cargo.toml | 2 + .../relays/bin-substrate/src/chains/millau.rs | 1 - .../relays/bin-substrate/src/chains/mod.rs | 1 + .../relays/bin-substrate/src/chains/rialto.rs | 1 - .../src/chains/rialto_parachain.rs | 1 - .../bin-substrate/src/chains/statemine.rs | 34 ++++++ .../bin-substrate/src/chains/westend.rs | 2 - bridges/relays/bin-substrate/src/cli/mod.rs | 5 - bridges/relays/client-statemine/Cargo.toml | 24 ++++ bridges/relays/client-statemine/src/lib.rs | 112 ++++++++++++++++++ .../relays/client-statemine/src/runtime.rs | 68 +++++++++++ bridges/relays/client-westend/src/lib.rs | 4 +- 21 files changed, 305 insertions(+), 77 deletions(-) create mode 100644 bridges/primitives/chain-statemine/Cargo.toml create mode 100644 bridges/primitives/chain-statemine/src/lib.rs create mode 100644 bridges/relays/bin-substrate/src/chains/statemine.rs create mode 100644 bridges/relays/client-statemine/Cargo.toml create mode 100644 bridges/relays/client-statemine/src/lib.rs create mode 100644 bridges/relays/client-statemine/src/runtime.rs diff --git a/bridges/primitives/chain-kusama/src/lib.rs b/bridges/primitives/chain-kusama/src/lib.rs index 7837afe690e..27d5f125ee2 100644 --- a/bridges/primitives/chain-kusama/src/lib.rs +++ b/bridges/primitives/chain-kusama/src/lib.rs @@ -24,13 +24,6 @@ use bp_runtime::decl_bridge_finality_runtime_apis; /// Kusama Chain pub type Kusama = PolkadotLike; -/// The target length of a session (how often authorities change) on Kusama measured in of number of -/// blocks. -/// -/// Note that since this is a target sessions may change before/after this time depending on network -/// conditions. -pub const SESSION_LENGTH: BlockNumber = time_units::HOURS; - /// Name of the With-Kusama GRANDPA pallet instance that is deployed at bridged chains. pub const WITH_KUSAMA_GRANDPA_PALLET_NAME: &str = "BridgeKusamaGrandpa"; diff --git a/bridges/primitives/chain-polkadot/Cargo.toml b/bridges/primitives/chain-polkadot/Cargo.toml index 8be9b25c77f..b26093a0570 100644 --- a/bridges/primitives/chain-polkadot/Cargo.toml +++ b/bridges/primitives/chain-polkadot/Cargo.toml @@ -7,8 +7,6 @@ edition = "2021" license = "GPL-3.0-or-later WITH Classpath-exception-2.0" [dependencies] -smallvec = "1.7" - # Bridge Dependencies bp-polkadot-core = { path = "../polkadot-core", default-features = false } diff --git a/bridges/primitives/chain-polkadot/src/lib.rs b/bridges/primitives/chain-polkadot/src/lib.rs index cfcbacb0d1a..0cada4e49a9 100644 --- a/bridges/primitives/chain-polkadot/src/lib.rs +++ b/bridges/primitives/chain-polkadot/src/lib.rs @@ -24,13 +24,6 @@ use bp_runtime::decl_bridge_finality_runtime_apis; /// Polkadot Chain pub type Polkadot = PolkadotLike; -/// The target length of a session (how often authorities change) on Polkadot measured in of number -/// of blocks. -/// -/// Note that since this is a target sessions may change before/after this time depending on network -/// conditions. -pub const SESSION_LENGTH: BlockNumber = 4 * time_units::HOURS; - /// Name of the With-Polkadot GRANDPA pallet instance that is deployed at bridged chains. pub const WITH_POLKADOT_GRANDPA_PALLET_NAME: &str = "BridgePolkadotGrandpa"; diff --git a/bridges/primitives/chain-rococo/src/lib.rs b/bridges/primitives/chain-rococo/src/lib.rs index 39188066dca..dd5be65dd86 100644 --- a/bridges/primitives/chain-rococo/src/lib.rs +++ b/bridges/primitives/chain-rococo/src/lib.rs @@ -24,13 +24,6 @@ use bp_runtime::decl_bridge_finality_runtime_apis; /// Rococo Chain pub type Rococo = PolkadotLike; -/// The target length of a session (how often authorities change) on Rococo measured in of number -/// of blocks. -/// -/// Note that since this is a target sessions may change before/after this time depending on network -/// conditions. -pub const SESSION_LENGTH: BlockNumber = time_units::HOURS; - /// Name of the With-Rococo GRANDPA pallet instance that is deployed at bridged chains. pub const WITH_ROCOCO_GRANDPA_PALLET_NAME: &str = "BridgeRococoGrandpa"; diff --git a/bridges/primitives/chain-statemine/Cargo.toml b/bridges/primitives/chain-statemine/Cargo.toml new file mode 100644 index 00000000000..18d186ba41e --- /dev/null +++ b/bridges/primitives/chain-statemine/Cargo.toml @@ -0,0 +1,24 @@ +[package] +name = "bp-statemine" +description = "Primitives of Statemine runtime." +version = "0.1.0" +authors = ["Parity Technologies <admin@parity.io>"] +edition = "2021" +license = "GPL-3.0-or-later WITH Classpath-exception-2.0" + +[dependencies] + +# Bridge Dependencies + +bp-polkadot-core = { path = "../polkadot-core", default-features = false } + +# Substrate Based Dependencies + +sp-version = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } + +[features] +default = ["std"] +std = [ + "bp-polkadot-core/std", + "sp-version/std", +] diff --git a/bridges/primitives/chain-statemine/src/lib.rs b/bridges/primitives/chain-statemine/src/lib.rs new file mode 100644 index 00000000000..613e4a4f450 --- /dev/null +++ b/bridges/primitives/chain-statemine/src/lib.rs @@ -0,0 +1,38 @@ +// Copyright 2019-2021 Parity Technologies (UK) Ltd. +// This file is part of Parity Bridges Common. + +// Parity Bridges Common 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. + +// Parity Bridges Common 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 Parity Bridges Common. If not, see <http://www.gnu.org/licenses/>. + +#![cfg_attr(not(feature = "std"), no_std)] +// RuntimeApi generated functions +#![allow(clippy::too_many_arguments)] + +pub use bp_polkadot_core::*; + +use sp_version::RuntimeVersion; + +/// Statemine Chain. +pub type Statemine = PolkadotLike; + +/// Known Statemine runtime version. +pub const VERSION: RuntimeVersion = RuntimeVersion { + spec_name: sp_version::create_runtime_str!("statemine"), + impl_name: sp_version::create_runtime_str!("statemine"), + authoring_version: 1, + spec_version: 9300, + impl_version: 0, + apis: sp_version::create_apis_vec![[]], + transaction_version: 8, + state_version: 1, +}; diff --git a/bridges/primitives/chain-westend/Cargo.toml b/bridges/primitives/chain-westend/Cargo.toml index e5f7bf89565..7d74362b09a 100644 --- a/bridges/primitives/chain-westend/Cargo.toml +++ b/bridges/primitives/chain-westend/Cargo.toml @@ -7,8 +7,6 @@ edition = "2021" license = "GPL-3.0-or-later WITH Classpath-exception-2.0" [dependencies] -codec = { package = "parity-scale-codec", version = "3.1.5", default-features = false, features = ["derive"] } -scale-info = { version = "2.1.1", default-features = false, features = ["derive"] } # Bridge Dependencies @@ -18,15 +16,11 @@ bp-runtime = { path = "../runtime", default-features = false } # Substrate Based Dependencies sp-api = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } -sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } [features] default = ["std"] std = [ "bp-polkadot-core/std", "bp-runtime/std", - "codec/std", - "scale-info/std", "sp-api/std", - "sp-runtime/std", ] diff --git a/bridges/primitives/chain-westend/src/lib.rs b/bridges/primitives/chain-westend/src/lib.rs index 8d5d8d9a924..9f4a98baedc 100644 --- a/bridges/primitives/chain-westend/src/lib.rs +++ b/bridges/primitives/chain-westend/src/lib.rs @@ -18,34 +18,12 @@ // RuntimeApi generated functions #![allow(clippy::too_many_arguments)] -use scale_info::TypeInfo; - pub use bp_polkadot_core::*; use bp_runtime::decl_bridge_finality_runtime_apis; /// Westend Chain pub type Westend = PolkadotLike; -/// Westend Runtime `Call` enum. -/// -/// We are not currently submitting any Westend transactions => it is empty. -#[derive(codec::Encode, codec::Decode, Debug, PartialEq, Eq, Clone, TypeInfo)] -pub enum Call {} - -impl sp_runtime::traits::Dispatchable for Call { - type RuntimeOrigin = (); - type Config = (); - type Info = (); - type PostInfo = (); - - fn dispatch( - self, - _origin: Self::RuntimeOrigin, - ) -> sp_runtime::DispatchResultWithInfo<Self::PostInfo> { - unimplemented!("The Call is not expected to be dispatched.") - } -} - /// Name of the parachains pallet at the Westend runtime. pub const PARAS_PALLET_NAME: &str = "Paras"; @@ -54,13 +32,6 @@ pub const WITH_WESTEND_GRANDPA_PALLET_NAME: &str = "BridgeWestendGrandpa"; /// Name of the With-Westend parachains bridge pallet instance that is deployed at bridged chains. pub const WITH_WESTEND_BRIDGE_PARAS_PALLET_NAME: &str = "BridgeWestendParachains"; -/// The target length of a session (how often authorities change) on Westend measured in of number -/// of blocks. -/// -/// Note that since this is a target sessions may change before/after this time depending on network -/// conditions. -pub const SESSION_LENGTH: BlockNumber = 10 * time_units::MINUTES; - /// Maximal number of GRANDPA authorities at Westend. /// /// Corresponds to the `MaxAuthorities` constant value from the Westend runtime configuration. diff --git a/bridges/primitives/chain-wococo/src/lib.rs b/bridges/primitives/chain-wococo/src/lib.rs index 2a417479d3b..f3fe0196dc5 100644 --- a/bridges/primitives/chain-wococo/src/lib.rs +++ b/bridges/primitives/chain-wococo/src/lib.rs @@ -24,13 +24,6 @@ use bp_runtime::decl_bridge_finality_runtime_apis; /// Wococo Chain pub type Wococo = PolkadotLike; -/// The target length of a session (how often authorities change) on Wococo measured in of number -/// of blocks. -/// -/// Note that since this is a target sessions may change before/after this time depending on network -/// conditions. -pub const SESSION_LENGTH: BlockNumber = time_units::MINUTES; - /// Name of the With-Wococo GRANDPA pallet instance that is deployed at bridged chains. pub const WITH_WOCOCO_GRANDPA_PALLET_NAME: &str = "BridgeWococoGrandpa"; diff --git a/bridges/relays/bin-substrate/Cargo.toml b/bridges/relays/bin-substrate/Cargo.toml index a3b5ef9213c..90adaf7e652 100644 --- a/bridges/relays/bin-substrate/Cargo.toml +++ b/bridges/relays/bin-substrate/Cargo.toml @@ -26,6 +26,7 @@ bp-polkadot-core = { path = "../../primitives/polkadot-core" } bp-rialto = { path = "../../primitives/chain-rialto" } bp-rialto-parachain = { path = "../../primitives/chain-rialto-parachain" } bp-runtime = { path = "../../primitives/runtime" } +bp-statemine = { path = "../../primitives/chain-statemine" } bp-westend = { path = "../../primitives/chain-westend" } bridge-runtime-common = { path = "../../bin/runtime-common" } messages-relay = { path = "../messages" } @@ -36,6 +37,7 @@ parachains-relay = { path = "../parachains" } relay-millau-client = { path = "../client-millau" } relay-rialto-client = { path = "../client-rialto" } relay-rialto-parachain-client = { path = "../client-rialto-parachain" } +relay-statemine-client = { path = "../client-statemine" } relay-substrate-client = { path = "../client-substrate" } relay-utils = { path = "../utils" } relay-westend-client = { path = "../client-westend" } diff --git a/bridges/relays/bin-substrate/src/chains/millau.rs b/bridges/relays/bin-substrate/src/chains/millau.rs index 55c48bee3ef..92fc43fbe36 100644 --- a/bridges/relays/bin-substrate/src/chains/millau.rs +++ b/bridges/relays/bin-substrate/src/chains/millau.rs @@ -93,7 +93,6 @@ impl CliChain for Millau { const RUNTIME_VERSION: Option<RuntimeVersion> = Some(millau_runtime::VERSION); type KeyPair = sp_core::sr25519::Pair; - type MessagePayload = Vec<u8>; fn ss58_format() -> u16 { millau_runtime::SS58Prefix::get() as u16 diff --git a/bridges/relays/bin-substrate/src/chains/mod.rs b/bridges/relays/bin-substrate/src/chains/mod.rs index 13aca0651ae..5d7171691bf 100644 --- a/bridges/relays/bin-substrate/src/chains/mod.rs +++ b/bridges/relays/bin-substrate/src/chains/mod.rs @@ -30,6 +30,7 @@ pub mod westend_parachains_to_millau; mod millau; mod rialto; mod rialto_parachain; +mod statemine; mod westend; #[cfg(test)] diff --git a/bridges/relays/bin-substrate/src/chains/rialto.rs b/bridges/relays/bin-substrate/src/chains/rialto.rs index 6a322d889cb..43ec9dbd224 100644 --- a/bridges/relays/bin-substrate/src/chains/rialto.rs +++ b/bridges/relays/bin-substrate/src/chains/rialto.rs @@ -76,7 +76,6 @@ impl CliChain for Rialto { const RUNTIME_VERSION: Option<RuntimeVersion> = Some(rialto_runtime::VERSION); type KeyPair = sp_core::sr25519::Pair; - type MessagePayload = Vec<u8>; fn ss58_format() -> u16 { rialto_runtime::SS58Prefix::get() as u16 diff --git a/bridges/relays/bin-substrate/src/chains/rialto_parachain.rs b/bridges/relays/bin-substrate/src/chains/rialto_parachain.rs index 08cc38d90d7..546cd04bdde 100644 --- a/bridges/relays/bin-substrate/src/chains/rialto_parachain.rs +++ b/bridges/relays/bin-substrate/src/chains/rialto_parachain.rs @@ -79,7 +79,6 @@ impl CliChain for RialtoParachain { const RUNTIME_VERSION: Option<RuntimeVersion> = Some(rialto_parachain_runtime::VERSION); type KeyPair = sp_core::sr25519::Pair; - type MessagePayload = Vec<u8>; fn ss58_format() -> u16 { rialto_parachain_runtime::SS58Prefix::get() as u16 diff --git a/bridges/relays/bin-substrate/src/chains/statemine.rs b/bridges/relays/bin-substrate/src/chains/statemine.rs new file mode 100644 index 00000000000..0c0edd2f3e4 --- /dev/null +++ b/bridges/relays/bin-substrate/src/chains/statemine.rs @@ -0,0 +1,34 @@ +// Copyright 2019-2021 Parity Technologies (UK) Ltd. +// This file is part of Parity Bridges Common. + +// Parity Bridges Common 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. + +// Parity Bridges Common 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 Parity Bridges Common. If not, see <http://www.gnu.org/licenses/>. + +//! Statemine chain specification for CLI. + +use crate::cli::CliChain; +use relay_statemine_client::Statemine; +use sp_version::RuntimeVersion; + +impl CliChain for Statemine { + const RUNTIME_VERSION: Option<RuntimeVersion> = Some(bp_statemine::VERSION); + + type KeyPair = sp_core::sr25519::Pair; + + fn ss58_format() -> u16 { + sp_core::crypto::Ss58AddressFormat::from( + sp_core::crypto::Ss58AddressFormatRegistry::KusamaAccount, + ) + .into() + } +} diff --git a/bridges/relays/bin-substrate/src/chains/westend.rs b/bridges/relays/bin-substrate/src/chains/westend.rs index 8d43d6a5ab7..1627bc015d3 100644 --- a/bridges/relays/bin-substrate/src/chains/westend.rs +++ b/bridges/relays/bin-substrate/src/chains/westend.rs @@ -24,7 +24,6 @@ impl CliChain for Westend { const RUNTIME_VERSION: Option<RuntimeVersion> = None; type KeyPair = sp_core::sr25519::Pair; - type MessagePayload = Vec<u8>; fn ss58_format() -> u16 { sp_core::crypto::Ss58AddressFormat::from( @@ -38,7 +37,6 @@ impl CliChain for Westmint { const RUNTIME_VERSION: Option<RuntimeVersion> = None; type KeyPair = sp_core::sr25519::Pair; - type MessagePayload = Vec<u8>; fn ss58_format() -> u16 { sp_core::crypto::Ss58AddressFormat::from( diff --git a/bridges/relays/bin-substrate/src/cli/mod.rs b/bridges/relays/bin-substrate/src/cli/mod.rs index 2369bb60dda..2f2f1f227b7 100644 --- a/bridges/relays/bin-substrate/src/cli/mod.rs +++ b/bridges/relays/bin-substrate/src/cli/mod.rs @@ -172,11 +172,6 @@ pub trait CliChain: relay_substrate_client::Chain { /// In case of chains supporting multiple cryptos, pick one used by the CLI. type KeyPair: sp_core::crypto::Pair; - /// Bridge Message Payload type. - /// - /// TODO [#854] This should be removed in favor of target-specifc types. - type MessagePayload; - /// Numeric value of SS58 format. fn ss58_format() -> u16; } diff --git a/bridges/relays/client-statemine/Cargo.toml b/bridges/relays/client-statemine/Cargo.toml new file mode 100644 index 00000000000..249f9fd6f43 --- /dev/null +++ b/bridges/relays/client-statemine/Cargo.toml @@ -0,0 +1,24 @@ +[package] +name = "relay-statemine-client" +version = "0.1.0" +authors = ["Parity Technologies <admin@parity.io>"] +edition = "2021" +license = "GPL-3.0-or-later WITH Classpath-exception-2.0" + +[dependencies] +codec = { package = "parity-scale-codec", version = "3.1.5" } +relay-substrate-client = { path = "../client-substrate" } +relay-utils = { path = "../utils" } +scale-info = { version = "2.1.1", features = ["derive"] } + +# Bridge dependencies + +bp-polkadot-core = { path = "../../primitives/polkadot-core" } +bp-statemine = { path = "../../primitives/chain-statemine" } + +# Substrate Dependencies + +frame-support = { git = "https://github.com/paritytech/substrate", branch = "master" } +frame-system = { git = "https://github.com/paritytech/substrate", branch = "master" } +sp-core = { git = "https://github.com/paritytech/substrate", branch = "master" } +sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "master" } diff --git a/bridges/relays/client-statemine/src/lib.rs b/bridges/relays/client-statemine/src/lib.rs new file mode 100644 index 00000000000..a5f6fed79f4 --- /dev/null +++ b/bridges/relays/client-statemine/src/lib.rs @@ -0,0 +1,112 @@ +// Copyright 2019-2021 Parity Technologies (UK) Ltd. +// This file is part of Parity Bridges Common. + +// Parity Bridges Common 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. + +// Parity Bridges Common 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 Parity Bridges Common. If not, see <http://www.gnu.org/licenses/>. + +//! Types used to connect to the Statemine chain. + +use codec::Encode; +use frame_support::weights::Weight; +use relay_substrate_client::{ + Chain, ChainBase, ChainWithTransactions, Error as SubstrateError, SignParam, + UnsignedTransaction, +}; +use sp_core::Pair; +use sp_runtime::{generic::SignedPayload, traits::IdentifyAccount}; +use std::time::Duration; + +pub mod runtime; + +/// Statemine chain definition +#[derive(Debug, Clone, Copy)] +pub struct Statemine; + +impl ChainBase for Statemine { + type BlockNumber = bp_statemine::BlockNumber; + type Hash = bp_statemine::Hash; + type Hasher = bp_statemine::Hasher; + type Header = bp_statemine::Header; + + type AccountId = bp_statemine::AccountId; + type Balance = bp_statemine::Balance; + type Index = bp_statemine::Nonce; + type Signature = bp_statemine::Signature; + + fn max_extrinsic_size() -> u32 { + bp_statemine::Statemine::max_extrinsic_size() + } + + fn max_extrinsic_weight() -> Weight { + bp_statemine::Statemine::max_extrinsic_weight() + } +} + +impl Chain for Statemine { + const NAME: &'static str = "Statemine"; + const TOKEN_ID: Option<&'static str> = Some("kusama"); + const BEST_FINALIZED_HEADER_ID_METHOD: &'static str = "<unused>"; + const AVERAGE_BLOCK_INTERVAL: Duration = Duration::from_secs(6); + const STORAGE_PROOF_OVERHEAD: u32 = bp_statemine::EXTRA_STORAGE_PROOF_SIZE; + + type SignedBlock = bp_statemine::SignedBlock; + type Call = runtime::Call; +} + +impl ChainWithTransactions for Statemine { + type AccountKeyPair = sp_core::sr25519::Pair; + type SignedTransaction = runtime::UncheckedExtrinsic; + + fn sign_transaction( + param: SignParam<Self>, + unsigned: UnsignedTransaction<Self>, + ) -> Result<Self::SignedTransaction, SubstrateError> { + let raw_payload = SignedPayload::new( + unsigned.call.clone(), + bp_statemine::SignedExtensions::new( + param.spec_version, + param.transaction_version, + unsigned.era, + param.genesis_hash, + unsigned.nonce, + unsigned.tip, + ), + ) + .expect("SignedExtension never fails."); + let signature = raw_payload.using_encoded(|payload| param.signer.sign(payload)); + let signer: sp_runtime::MultiSigner = param.signer.public().into(); + let (call, extra, _) = raw_payload.deconstruct(); + + Ok(runtime::UncheckedExtrinsic::new_signed( + call, + signer.into_account().into(), + signature.into(), + extra, + )) + } + + fn is_signed(tx: &Self::SignedTransaction) -> bool { + tx.signature.is_some() + } + + fn is_signed_by(signer: &Self::AccountKeyPair, tx: &Self::SignedTransaction) -> bool { + tx.signature + .as_ref() + .map(|(address, _, _)| *address == bp_statemine::Address::Id(signer.public().into())) + .unwrap_or(false) + } + + fn parse_transaction(_tx: Self::SignedTransaction) -> Option<UnsignedTransaction<Self>> { + unimplemented!("not used on Statemine") + } +} diff --git a/bridges/relays/client-statemine/src/runtime.rs b/bridges/relays/client-statemine/src/runtime.rs new file mode 100644 index 00000000000..92924555769 --- /dev/null +++ b/bridges/relays/client-statemine/src/runtime.rs @@ -0,0 +1,68 @@ +// Copyright 2019-2021 Parity Technologies (UK) Ltd. +// This file is part of Parity Bridges Common. + +// Parity Bridges Common 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. + +// Parity Bridges Common 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 Parity Bridges Common. If not, see <http://www.gnu.org/licenses/>. + +//! Types that are specific to the Statemine runtime. + +use codec::{Decode, Encode}; +use scale_info::TypeInfo; +use sp_runtime::FixedU128; + +/// Unchecked Statemine extrinsic. +pub type UncheckedExtrinsic = bp_polkadot_core::UncheckedExtrinsic<Call>; + +/// Statemine Runtime `Call` enum. +/// +/// The enum represents a subset of possible `Call`s we can send to Statemine chain. +/// Ideally this code would be auto-generated from metadata, because we want to +/// avoid depending directly on the ENTIRE runtime just to get the encoding of `Dispatchable`s. +/// +/// All entries here (like pretty much in the entire file) must be kept in sync with Statemine +/// `construct_runtime`, so that we maintain SCALE-compatibility. +/// +/// See: [link](https://github.com/paritytech/cumulus/blob/master/parachains/runtimes/assets/statemine/src/lib.rs) +#[allow(clippy::large_enum_variant)] +#[derive(Encode, Decode, Debug, PartialEq, Eq, Clone, TypeInfo)] +pub enum Call { + /// With-Statemint bridge pallet. + // TODO (https://github.com/paritytech/parity-bridges-common/issues/1626): + // must be updated when we'll make appropriate changes in the Statemine runtime + #[codec(index = 42)] + WithStatemintBridgePallet(WithStatemintBridgePalletCall), +} + +/// Calls of the with-Statemint bridge pallet. +// TODO (https://github.com/paritytech/parity-bridges-common/issues/1626): +// must be updated when we'll make appropriate changes in the Statemine runtime +#[derive(Encode, Decode, Debug, PartialEq, Eq, Clone, TypeInfo)] +#[allow(non_camel_case_types)] +pub enum WithStatemintBridgePalletCall { + #[codec(index = 42)] + update_dot_to_ksm_conversion_rate(FixedU128), +} + +impl sp_runtime::traits::Dispatchable for Call { + type RuntimeOrigin = (); + type Config = (); + type Info = (); + type PostInfo = (); + + fn dispatch( + self, + _origin: Self::RuntimeOrigin, + ) -> sp_runtime::DispatchResultWithInfo<Self::PostInfo> { + unimplemented!("The Call is not expected to be dispatched.") + } +} diff --git a/bridges/relays/client-westend/src/lib.rs b/bridges/relays/client-westend/src/lib.rs index f6a4220c618..0f650e9e284 100644 --- a/bridges/relays/client-westend/src/lib.rs +++ b/bridges/relays/client-westend/src/lib.rs @@ -60,7 +60,7 @@ impl Chain for Westend { const STORAGE_PROOF_OVERHEAD: u32 = bp_westend::EXTRA_STORAGE_PROOF_SIZE; type SignedBlock = bp_westend::SignedBlock; - type Call = bp_westend::Call; + type Call = (); } impl RelayChain for Westend { @@ -117,5 +117,5 @@ impl Chain for Westmint { const STORAGE_PROOF_OVERHEAD: u32 = bp_westend::EXTRA_STORAGE_PROOF_SIZE; type SignedBlock = bp_westend::SignedBlock; - type Call = bp_westend::Call; + type Call = (); } -- GitLab