Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove CliChain::KeyPair #1741

Merged
merged 1 commit into from
Dec 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions relays/bin-substrate/src/chains/millau.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,4 @@ impl CliEncodeMessage for Millau {

impl CliChain for Millau {
const RUNTIME_VERSION: Option<RuntimeVersion> = Some(millau_runtime::VERSION);

type KeyPair = sp_core::sr25519::Pair;
}
2 changes: 0 additions & 2 deletions relays/bin-substrate/src/chains/rialto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,4 @@ impl CliEncodeMessage for Rialto {

impl CliChain for Rialto {
const RUNTIME_VERSION: Option<RuntimeVersion> = Some(rialto_runtime::VERSION);

type KeyPair = sp_core::sr25519::Pair;
}
2 changes: 0 additions & 2 deletions relays/bin-substrate/src/chains/rialto_parachain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,4 @@ impl CliEncodeMessage for RialtoParachain {

impl CliChain for RialtoParachain {
const RUNTIME_VERSION: Option<RuntimeVersion> = Some(rialto_parachain_runtime::VERSION);

type KeyPair = sp_core::sr25519::Pair;
}
4 changes: 0 additions & 4 deletions relays/bin-substrate/src/chains/rococo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,8 @@ use sp_version::RuntimeVersion;

impl CliChain for Rococo {
const RUNTIME_VERSION: Option<RuntimeVersion> = None;

type KeyPair = sp_core::sr25519::Pair;
}

impl CliChain for BridgeHubRococo {
const RUNTIME_VERSION: Option<RuntimeVersion> = None;

type KeyPair = sp_core::sr25519::Pair;
}
4 changes: 0 additions & 4 deletions relays/bin-substrate/src/chains/westend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,8 @@ use sp_version::RuntimeVersion;

impl CliChain for Westend {
const RUNTIME_VERSION: Option<RuntimeVersion> = None;

type KeyPair = sp_core::sr25519::Pair;
}

impl CliChain for Westmint {
const RUNTIME_VERSION: Option<RuntimeVersion> = None;

type KeyPair = sp_core::sr25519::Pair;
}
4 changes: 0 additions & 4 deletions relays/bin-substrate/src/chains/wococo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,8 @@ use sp_version::RuntimeVersion;

impl CliChain for Wococo {
const RUNTIME_VERSION: Option<RuntimeVersion> = None;

type KeyPair = sp_core::sr25519::Pair;
}

impl CliChain for BridgeHubWococo {
const RUNTIME_VERSION: Option<RuntimeVersion> = None;

type KeyPair = sp_core::sr25519::Pair;
}
6 changes: 2 additions & 4 deletions relays/bin-substrate/src/cli/bridge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -63,7 +61,7 @@ pub trait CliBridgeBase: Sized {
/// The source chain.
type Source: Chain + CliChain;
/// The target chain.
type Target: ChainWithTransactions + CliChain<KeyPair = AccountKeyPairOf<Self::Target>>;
type Target: ChainWithTransactions + CliChain;
}

/// Bridge representation that can be used from the CLI for relaying headers
Expand Down
15 changes: 8 additions & 7 deletions relays/bin-substrate/src/cli/chain_schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

// along with Parity Bridges Common. If not, see <http://www.gnu.org/licenses/>.

use relay_substrate_client::{AccountKeyPairOf, ChainWithTransactions};
use structopt::StructOpt;
use strum::{EnumString, EnumVariantNames};

Expand Down Expand Up @@ -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<Chain: CliChain>(
fn transaction_params<Chain: ChainWithTransactions>(
&self,
) -> anyhow::Result<TransactionParams<Chain::KeyPair>>;
) -> anyhow::Result<TransactionParams<AccountKeyPairOf<Chain>>>;

/// Returns transaction parameters, defined by `self` provider or, if they're not defined,
/// defined by `other` provider.
fn transaction_params_or<Chain: CliChain, T: TransactionParamsProvider>(
fn transaction_params_or<Chain: ChainWithTransactions, T: TransactionParamsProvider>(
&self,
other: &T,
) -> anyhow::Result<TransactionParams<Chain::KeyPair>> {
) -> anyhow::Result<TransactionParams<AccountKeyPairOf<Chain>>> {
if self.is_defined() {
self.transaction_params::<Chain>()
} else {
Expand Down Expand Up @@ -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<Chain: CliChain>(&self) -> anyhow::Result<Chain::KeyPair> {
pub fn to_keypair<Chain: ChainWithTransactions>(&self) -> anyhow::Result<AccountKeyPairOf<Chain>> {
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)
Expand Down Expand Up @@ -234,7 +235,7 @@ macro_rules! declare_chain_signing_params_cli_schema {

use sp_core::crypto::Pair;

Chain::KeyPair::from_string(
AccountKeyPairOf::<Chain>::from_string(
&suri,
suri_password.as_deref()
).map_err(|e| anyhow::format_err!("{:?}", e))
Expand All @@ -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<Chain: CliChain>(&self) -> anyhow::Result<TransactionParams<Chain::KeyPair>> {
fn transaction_params<Chain: ChainWithTransactions>(&self) -> anyhow::Result<TransactionParams<AccountKeyPairOf<Chain>>> {
Ok(TransactionParams {
mortality: self.transactions_mortality()?,
signer: self.to_keypair::<Chain>()?,
Expand Down
5 changes: 0 additions & 5 deletions relays/bin-substrate/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<sp_version::RuntimeVersion>;

/// 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.
Expand Down
12 changes: 4 additions & 8 deletions relays/bin-substrate/src/cli/relay_headers_and_messages/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<KeyPair = AccountKeyPairOf<Self::Left>>;
type Left: ChainWithTransactions + CliChain;
/// The right destination chain (it can be a relay or a parachain).
type Right: ChainWithTransactions + CliChain<KeyPair = AccountKeyPairOf<Self::Right>>;
type Right: ChainWithTransactions + CliChain;

/// Reference to common relay parameters.
fn common(&self) -> &Full2WayBridgeCommonParams<Self::Left, Self::Right>;
Expand Down Expand Up @@ -259,13 +259,9 @@ where
type Base: Full2WayBridgeBase<Left = Self::Left, Right = Self::Right>;

/// The left relay chain.
type Left: ChainWithTransactions
+ ChainWithBalances
+ CliChain<KeyPair = AccountKeyPairOf<Self::Left>>;
type Left: ChainWithTransactions + ChainWithBalances + CliChain;
/// The right relay chain.
type Right: ChainWithTransactions
+ ChainWithBalances
+ CliChain<KeyPair = AccountKeyPairOf<Self::Right>>;
type Right: ChainWithTransactions + ChainWithBalances + CliChain;

/// Left to Right bridge.
type L2R: MessagesCliBridge<Source = Self::Left, Target = Self::Right>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<KeyPair = AccountKeyPairOf<Left>> + Parachain,
Left: ChainWithTransactions + CliChain + Parachain,
LeftRelay: CliChain,
Right: ChainWithTransactions + CliChain<KeyPair = AccountKeyPairOf<Right>> + Parachain,
Right: ChainWithTransactions + CliChain + Parachain,
RightRelay: CliChain,
L2R: CliBridgeBase<Source = Left, Target = Right>
+ MessagesCliBridge
Expand Down Expand Up @@ -168,14 +168,8 @@ macro_rules! declare_parachain_to_parachain_bridge_schema {

#[async_trait]
impl<
Left: Chain<Hash = ParaHash>
+ ChainWithTransactions
+ CliChain<KeyPair = AccountKeyPairOf<Left>>
+ Parachain,
Right: Chain<Hash = ParaHash>
+ ChainWithTransactions
+ CliChain<KeyPair = AccountKeyPairOf<Right>>
+ Parachain,
Left: Chain<Hash = ParaHash> + ChainWithTransactions + CliChain + Parachain,
Right: Chain<Hash = ParaHash> + ChainWithTransactions + CliChain + Parachain,
LeftRelay: Chain<BlockNumber = RelayBlockNumber, Hash = RelayBlockHash, Hasher = RelayBlockHasher>
+ CliChain,
RightRelay: Chain<BlockNumber = RelayBlockNumber, Hash = RelayBlockHash, Hasher = RelayBlockHasher>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<KeyPair = AccountKeyPairOf<Left>>,
Right: ChainWithTransactions + CliChain<KeyPair = AccountKeyPairOf<Right>> + Parachain,
Left: ChainWithTransactions + CliChain,
Right: ChainWithTransactions + CliChain + Parachain,
RightRelay: CliChain,
L2R: CliBridgeBase<Source = Left, Target = Right> + MessagesCliBridge + RelayToRelayHeadersCliBridge,
R2L: CliBridgeBase<Source = Right, Target = Left>
Expand Down Expand Up @@ -156,11 +156,8 @@ macro_rules! declare_relay_to_parachain_bridge_schema {

#[async_trait]
impl<
Left: ChainWithTransactions + CliChain<KeyPair = AccountKeyPairOf<Left>>,
Right: Chain<Hash = ParaHash>
+ ChainWithTransactions
+ CliChain<KeyPair = AccountKeyPairOf<Right>>
+ Parachain,
Left: ChainWithTransactions + CliChain,
Right: Chain<Hash = ParaHash> + ChainWithTransactions + CliChain + Parachain,
RightRelay: Chain<BlockNumber = RelayBlockNumber, Hash = RelayBlockHash, Hasher = RelayBlockHasher>
+ CliChain,
L2R: CliBridgeBase<Source = Left, Target = Right>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<KeyPair = AccountKeyPairOf<Left>>,
Right: ChainWithTransactions + CliChain<KeyPair = AccountKeyPairOf<Right>>,
Left: ChainWithTransactions + CliChain,
Right: ChainWithTransactions + CliChain,
L2R: CliBridgeBase<Source = Left, Target = Right> + MessagesCliBridge + RelayToRelayHeadersCliBridge,
R2L: CliBridgeBase<Source = Right, Target = Left> + MessagesCliBridge + RelayToRelayHeadersCliBridge,
>(
Expand Down Expand Up @@ -114,8 +114,8 @@ macro_rules! declare_relay_to_relay_bridge_schema {

#[async_trait]
impl<
Left: ChainWithTransactions + CliChain<KeyPair = AccountKeyPairOf<Left>>,
Right: ChainWithTransactions + CliChain<KeyPair = AccountKeyPairOf<Right>>,
Left: ChainWithTransactions + CliChain,
Right: ChainWithTransactions + CliChain,
L2R: CliBridgeBase<Source = Left, Target = Right>
+ MessagesCliBridge
+ RelayToRelayHeadersCliBridge,
Expand Down
2 changes: 1 addition & 1 deletion relays/bin-substrate/src/cli/relay_messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ pub struct RelayMessages {
#[async_trait]
trait MessagesRelayer: MessagesCliBridge
where
Self::Source: ChainWithTransactions + CliChain<KeyPair = AccountKeyPairOf<Self::Source>>,
Self::Source: ChainWithTransactions + CliChain,
AccountIdOf<Self::Source>: From<<AccountKeyPairOf<Self::Source> as Pair>::Public>,
AccountIdOf<Self::Target>: From<<AccountKeyPairOf<Self::Target> as Pair>::Public>,
BalanceOf<Self::Source>: TryFrom<BalanceOf<Self::Target>>,
Expand Down
5 changes: 1 addition & 4 deletions relays/bin-substrate/src/cli/send_message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,7 @@ pub struct SendMessage {
#[async_trait]
trait MessageSender: MessagesCliBridge
where
Self::Source: ChainBase<Index = u32>
+ ChainWithTransactions
+ CliChain<KeyPair = AccountKeyPairOf<Self::Source>>
+ CliEncodeMessage,
Self::Source: ChainBase<Index = u32> + ChainWithTransactions + CliChain + CliEncodeMessage,
<Self::Source as ChainBase>::Balance: Display + From<u64> + Into<u128>,
<Self::Source as Chain>::Call: Sync,
<Self::Source as ChainWithTransactions>::SignedTransaction: Sync,
Expand Down