Remove CliChain::KeyPair (#1741)

This commit is contained in:
Serban Iorga
2022-12-30 13:48:29 +02:00
committed by Bastian Köcher
parent 03425b33ae
commit 4a10ccb118
15 changed files with 28 additions and 68 deletions
@@ -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;
}
@@ -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;
}
@@ -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;
}
@@ -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;
}
@@ -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;
}
@@ -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;
}
@@ -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<KeyPair = AccountKeyPairOf<Self::Target>>;
type Target: ChainWithTransactions + CliChain;
}
/// Bridge representation that can be used from the CLI for relaying headers
@@ -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};
@@ -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 {
@@ -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)
@@ -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))
@@ -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>()?,
@@ -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.
@@ -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>;
@@ -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>;
@@ -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
@@ -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>
@@ -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>
@@ -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>
@@ -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,
>(
@@ -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,
@@ -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>>,
@@ -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,