From 03de598b9a1537ea7a7ac87b404a12a3ddaec10a Mon Sep 17 00:00:00 2001 From: Serban Iorga Date: Fri, 30 Dec 2022 13:48:29 +0200 Subject: [PATCH] Remove CliChain::KeyPair (#1741) --- bridges/relays/bin-substrate/src/chains/millau.rs | 2 -- bridges/relays/bin-substrate/src/chains/rialto.rs | 2 -- .../bin-substrate/src/chains/rialto_parachain.rs | 2 -- bridges/relays/bin-substrate/src/chains/rococo.rs | 4 ---- .../relays/bin-substrate/src/chains/westend.rs | 4 ---- bridges/relays/bin-substrate/src/chains/wococo.rs | 4 ---- bridges/relays/bin-substrate/src/cli/bridge.rs | 6 ++---- .../relays/bin-substrate/src/cli/chain_schema.rs | 15 ++++++++------- bridges/relays/bin-substrate/src/cli/mod.rs | 5 ----- .../src/cli/relay_headers_and_messages/mod.rs | 12 ++++-------- .../parachain_to_parachain.rs | 14 ++++---------- .../relay_to_parachain.rs | 11 ++++------- .../relay_headers_and_messages/relay_to_relay.rs | 8 ++++---- .../bin-substrate/src/cli/relay_messages.rs | 2 +- .../relays/bin-substrate/src/cli/send_message.rs | 5 +---- 15 files changed, 28 insertions(+), 68 deletions(-) diff --git a/bridges/relays/bin-substrate/src/chains/millau.rs b/bridges/relays/bin-substrate/src/chains/millau.rs index aa56d113e14ed..f318274750df9 100644 --- a/bridges/relays/bin-substrate/src/chains/millau.rs +++ b/bridges/relays/bin-substrate/src/chains/millau.rs @@ -54,6 +54,4 @@ impl CliEncodeMessage for Millau { impl CliChain for Millau { const RUNTIME_VERSION: Option = Some(millau_runtime::VERSION); - - type KeyPair = sp_core::sr25519::Pair; } diff --git a/bridges/relays/bin-substrate/src/chains/rialto.rs b/bridges/relays/bin-substrate/src/chains/rialto.rs index a8e8143632e16..8a473dc303c4c 100644 --- a/bridges/relays/bin-substrate/src/chains/rialto.rs +++ b/bridges/relays/bin-substrate/src/chains/rialto.rs @@ -46,6 +46,4 @@ impl CliEncodeMessage for Rialto { impl CliChain for Rialto { const RUNTIME_VERSION: Option = Some(rialto_runtime::VERSION); - - type KeyPair = sp_core::sr25519::Pair; } diff --git a/bridges/relays/bin-substrate/src/chains/rialto_parachain.rs b/bridges/relays/bin-substrate/src/chains/rialto_parachain.rs index 66d03f212ce76..7105dc2b7d7c8 100644 --- a/bridges/relays/bin-substrate/src/chains/rialto_parachain.rs +++ b/bridges/relays/bin-substrate/src/chains/rialto_parachain.rs @@ -48,6 +48,4 @@ impl CliEncodeMessage for RialtoParachain { impl CliChain for RialtoParachain { const RUNTIME_VERSION: Option = Some(rialto_parachain_runtime::VERSION); - - type KeyPair = sp_core::sr25519::Pair; } diff --git a/bridges/relays/bin-substrate/src/chains/rococo.rs b/bridges/relays/bin-substrate/src/chains/rococo.rs index 68a6b3e7b1db7..6805c021a213e 100644 --- a/bridges/relays/bin-substrate/src/chains/rococo.rs +++ b/bridges/relays/bin-substrate/src/chains/rococo.rs @@ -23,12 +23,8 @@ use sp_version::RuntimeVersion; impl CliChain for Rococo { const RUNTIME_VERSION: Option = None; - - type KeyPair = sp_core::sr25519::Pair; } impl CliChain for BridgeHubRococo { const RUNTIME_VERSION: Option = None; - - type KeyPair = sp_core::sr25519::Pair; } diff --git a/bridges/relays/bin-substrate/src/chains/westend.rs b/bridges/relays/bin-substrate/src/chains/westend.rs index 075f22b698fdf..50ae034957619 100644 --- a/bridges/relays/bin-substrate/src/chains/westend.rs +++ b/bridges/relays/bin-substrate/src/chains/westend.rs @@ -22,12 +22,8 @@ use sp_version::RuntimeVersion; impl CliChain for Westend { const RUNTIME_VERSION: Option = None; - - type KeyPair = sp_core::sr25519::Pair; } impl CliChain for Westmint { const RUNTIME_VERSION: Option = None; - - type KeyPair = sp_core::sr25519::Pair; } diff --git a/bridges/relays/bin-substrate/src/chains/wococo.rs b/bridges/relays/bin-substrate/src/chains/wococo.rs index 2edd3dcf606e9..0bbfa676fe996 100644 --- a/bridges/relays/bin-substrate/src/chains/wococo.rs +++ b/bridges/relays/bin-substrate/src/chains/wococo.rs @@ -23,12 +23,8 @@ use sp_version::RuntimeVersion; impl CliChain for Wococo { const RUNTIME_VERSION: Option = None; - - type KeyPair = sp_core::sr25519::Pair; } impl CliChain for BridgeHubWococo { const RUNTIME_VERSION: Option = None; - - type KeyPair = sp_core::sr25519::Pair; } diff --git a/bridges/relays/bin-substrate/src/cli/bridge.rs b/bridges/relays/bin-substrate/src/cli/bridge.rs index 0f0c11f39098d..330b498f19c03 100644 --- a/bridges/relays/bin-substrate/src/cli/bridge.rs +++ b/bridges/relays/bin-substrate/src/cli/bridge.rs @@ -17,9 +17,7 @@ use crate::cli::CliChain; use pallet_bridge_parachains::{RelayBlockHash, RelayBlockHasher, RelayBlockNumber}; use parachains_relay::ParachainsPipeline; -use relay_substrate_client::{ - AccountKeyPairOf, Chain, ChainWithTransactions, Parachain, RelayChain, -}; +use relay_substrate_client::{Chain, ChainWithTransactions, Parachain, RelayChain}; use strum::{EnumString, EnumVariantNames}; use substrate_relay_helper::{ finality::SubstrateFinalitySyncPipeline, messages_lane::SubstrateMessageLane, @@ -63,7 +61,7 @@ pub trait CliBridgeBase: Sized { /// The source chain. type Source: Chain + CliChain; /// The target chain. - type Target: ChainWithTransactions + CliChain>; + type Target: ChainWithTransactions + CliChain; } /// Bridge representation that can be used from the CLI for relaying headers diff --git a/bridges/relays/bin-substrate/src/cli/chain_schema.rs b/bridges/relays/bin-substrate/src/cli/chain_schema.rs index 6fc0fac18b230..3993b74250df6 100644 --- a/bridges/relays/bin-substrate/src/cli/chain_schema.rs +++ b/bridges/relays/bin-substrate/src/cli/chain_schema.rs @@ -15,6 +15,7 @@ // along with Parity Bridges Common. If not, see . +use relay_substrate_client::{AccountKeyPairOf, ChainWithTransactions}; use structopt::StructOpt; use strum::{EnumString, EnumVariantNames}; @@ -134,16 +135,16 @@ pub trait TransactionParamsProvider { /// Returns `true` if transaction parameters are defined by this provider. fn is_defined(&self) -> bool; /// Returns transaction parameters. - fn transaction_params( + fn transaction_params( &self, - ) -> anyhow::Result>; + ) -> anyhow::Result>>; /// Returns transaction parameters, defined by `self` provider or, if they're not defined, /// defined by `other` provider. - fn transaction_params_or( + fn transaction_params_or( &self, other: &T, - ) -> anyhow::Result> { + ) -> anyhow::Result>> { if self.is_defined() { self.transaction_params::() } else { @@ -201,7 +202,7 @@ macro_rules! declare_chain_signing_params_cli_schema { /// Parse signing params into chain-specific KeyPair. #[allow(dead_code)] - pub fn to_keypair(&self) -> anyhow::Result { + pub fn to_keypair(&self) -> anyhow::Result> { let suri = match (self.[<$chain_prefix _signer>].as_ref(), self.[<$chain_prefix _signer_file>].as_ref()) { (Some(suri), _) => suri.to_owned(), (None, Some(suri_file)) => std::fs::read_to_string(suri_file) @@ -234,7 +235,7 @@ macro_rules! declare_chain_signing_params_cli_schema { use sp_core::crypto::Pair; - Chain::KeyPair::from_string( + AccountKeyPairOf::::from_string( &suri, suri_password.as_deref() ).map_err(|e| anyhow::format_err!("{:?}", e)) @@ -247,7 +248,7 @@ macro_rules! declare_chain_signing_params_cli_schema { self.[<$chain_prefix _signer>].is_some() || self.[<$chain_prefix _signer_file>].is_some() } - fn transaction_params(&self) -> anyhow::Result> { + fn transaction_params(&self) -> anyhow::Result>> { Ok(TransactionParams { mortality: self.transactions_mortality()?, signer: self.to_keypair::()?, diff --git a/bridges/relays/bin-substrate/src/cli/mod.rs b/bridges/relays/bin-substrate/src/cli/mod.rs index 6784f1a606593..e049a050c4772 100644 --- a/bridges/relays/bin-substrate/src/cli/mod.rs +++ b/bridges/relays/bin-substrate/src/cli/mod.rs @@ -194,11 +194,6 @@ pub trait CliChain: relay_substrate_client::Chain { /// /// can be `None` if relay is not going to submit transactions to that chain. const RUNTIME_VERSION: Option; - - /// Crypto KeyPair type used to send messages. - /// - /// In case of chains supporting multiple cryptos, pick one used by the CLI. - type KeyPair: sp_core::crypto::Pair; } /// Lane id. diff --git a/bridges/relays/bin-substrate/src/cli/relay_headers_and_messages/mod.rs b/bridges/relays/bin-substrate/src/cli/relay_headers_and_messages/mod.rs index 1a809a1f483c3..fd8a032066d69 100644 --- a/bridges/relays/bin-substrate/src/cli/relay_headers_and_messages/mod.rs +++ b/bridges/relays/bin-substrate/src/cli/relay_headers_and_messages/mod.rs @@ -227,9 +227,9 @@ trait Full2WayBridgeBase: Sized + Send + Sync { /// The CLI params for the bridge. type Params; /// The left relay chain. - type Left: ChainWithTransactions + CliChain>; + type Left: ChainWithTransactions + CliChain; /// The right destination chain (it can be a relay or a parachain). - type Right: ChainWithTransactions + CliChain>; + type Right: ChainWithTransactions + CliChain; /// Reference to common relay parameters. fn common(&self) -> &Full2WayBridgeCommonParams; @@ -259,13 +259,9 @@ where type Base: Full2WayBridgeBase; /// The left relay chain. - type Left: ChainWithTransactions - + ChainWithBalances - + CliChain>; + type Left: ChainWithTransactions + ChainWithBalances + CliChain; /// The right relay chain. - type Right: ChainWithTransactions - + ChainWithBalances - + CliChain>; + type Right: ChainWithTransactions + ChainWithBalances + CliChain; /// Left to Right bridge. type L2R: MessagesCliBridge; diff --git a/bridges/relays/bin-substrate/src/cli/relay_headers_and_messages/parachain_to_parachain.rs b/bridges/relays/bin-substrate/src/cli/relay_headers_and_messages/parachain_to_parachain.rs index 3be07404ebe36..b4c858e566b2e 100644 --- a/bridges/relays/bin-substrate/src/cli/relay_headers_and_messages/parachain_to_parachain.rs +++ b/bridges/relays/bin-substrate/src/cli/relay_headers_and_messages/parachain_to_parachain.rs @@ -116,9 +116,9 @@ macro_rules! declare_parachain_to_parachain_bridge_schema { impl [<$left_parachain $right_parachain HeadersAndMessages>] { async fn into_bridge< - Left: ChainWithTransactions + CliChain> + Parachain, + Left: ChainWithTransactions + CliChain + Parachain, LeftRelay: CliChain, - Right: ChainWithTransactions + CliChain> + Parachain, + Right: ChainWithTransactions + CliChain + Parachain, RightRelay: CliChain, L2R: CliBridgeBase + MessagesCliBridge @@ -168,14 +168,8 @@ macro_rules! declare_parachain_to_parachain_bridge_schema { #[async_trait] impl< - Left: Chain - + ChainWithTransactions - + CliChain> - + Parachain, - Right: Chain - + ChainWithTransactions - + CliChain> - + Parachain, + Left: Chain + ChainWithTransactions + CliChain + Parachain, + Right: Chain + ChainWithTransactions + CliChain + Parachain, LeftRelay: Chain + CliChain, RightRelay: Chain diff --git a/bridges/relays/bin-substrate/src/cli/relay_headers_and_messages/relay_to_parachain.rs b/bridges/relays/bin-substrate/src/cli/relay_headers_and_messages/relay_to_parachain.rs index babd39e558bb1..d632cce08e9c7 100644 --- a/bridges/relays/bin-substrate/src/cli/relay_headers_and_messages/relay_to_parachain.rs +++ b/bridges/relays/bin-substrate/src/cli/relay_headers_and_messages/relay_to_parachain.rs @@ -107,8 +107,8 @@ macro_rules! declare_relay_to_parachain_bridge_schema { impl [<$left_chain $right_parachain HeadersAndMessages>] { async fn into_bridge< - Left: ChainWithTransactions + CliChain>, - Right: ChainWithTransactions + CliChain> + Parachain, + Left: ChainWithTransactions + CliChain, + Right: ChainWithTransactions + CliChain + Parachain, RightRelay: CliChain, L2R: CliBridgeBase + MessagesCliBridge + RelayToRelayHeadersCliBridge, R2L: CliBridgeBase @@ -156,11 +156,8 @@ macro_rules! declare_relay_to_parachain_bridge_schema { #[async_trait] impl< - Left: ChainWithTransactions + CliChain>, - Right: Chain - + ChainWithTransactions - + CliChain> - + Parachain, + Left: ChainWithTransactions + CliChain, + Right: Chain + ChainWithTransactions + CliChain + Parachain, RightRelay: Chain + CliChain, L2R: CliBridgeBase diff --git a/bridges/relays/bin-substrate/src/cli/relay_headers_and_messages/relay_to_relay.rs b/bridges/relays/bin-substrate/src/cli/relay_headers_and_messages/relay_to_relay.rs index 071716dedb859..fce80492fc071 100644 --- a/bridges/relays/bin-substrate/src/cli/relay_headers_and_messages/relay_to_relay.rs +++ b/bridges/relays/bin-substrate/src/cli/relay_headers_and_messages/relay_to_relay.rs @@ -76,8 +76,8 @@ macro_rules! declare_relay_to_relay_bridge_schema { impl [<$left_chain $right_chain HeadersAndMessages>] { async fn into_bridge< - Left: ChainWithTransactions + CliChain>, - Right: ChainWithTransactions + CliChain>, + Left: ChainWithTransactions + CliChain, + Right: ChainWithTransactions + CliChain, L2R: CliBridgeBase + MessagesCliBridge + RelayToRelayHeadersCliBridge, R2L: CliBridgeBase + MessagesCliBridge + RelayToRelayHeadersCliBridge, >( @@ -114,8 +114,8 @@ macro_rules! declare_relay_to_relay_bridge_schema { #[async_trait] impl< - Left: ChainWithTransactions + CliChain>, - Right: ChainWithTransactions + CliChain>, + Left: ChainWithTransactions + CliChain, + Right: ChainWithTransactions + CliChain, L2R: CliBridgeBase + MessagesCliBridge + RelayToRelayHeadersCliBridge, diff --git a/bridges/relays/bin-substrate/src/cli/relay_messages.rs b/bridges/relays/bin-substrate/src/cli/relay_messages.rs index 7f4dc34ac8bff..6af042670e74d 100644 --- a/bridges/relays/bin-substrate/src/cli/relay_messages.rs +++ b/bridges/relays/bin-substrate/src/cli/relay_messages.rs @@ -56,7 +56,7 @@ pub struct RelayMessages { #[async_trait] trait MessagesRelayer: MessagesCliBridge where - Self::Source: ChainWithTransactions + CliChain>, + Self::Source: ChainWithTransactions + CliChain, AccountIdOf: From< as Pair>::Public>, AccountIdOf: From< as Pair>::Public>, BalanceOf: TryFrom>, diff --git a/bridges/relays/bin-substrate/src/cli/send_message.rs b/bridges/relays/bin-substrate/src/cli/send_message.rs index 59a36566c0c6e..9f14028c4aee4 100644 --- a/bridges/relays/bin-substrate/src/cli/send_message.rs +++ b/bridges/relays/bin-substrate/src/cli/send_message.rs @@ -57,10 +57,7 @@ pub struct SendMessage { #[async_trait] trait MessageSender: MessagesCliBridge where - Self::Source: ChainBase - + ChainWithTransactions - + CliChain> - + CliEncodeMessage, + Self::Source: ChainBase + ChainWithTransactions + CliChain + CliEncodeMessage, ::Balance: Display + From + Into, ::Call: Sync, ::SignedTransaction: Sync,