mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 22:11:02 +00:00
De-duplicate signing/connection params. (#861)
Co-authored-by: Hernando Castano <hernando@hcastano.com>
This commit is contained in:
committed by
Bastian Köcher
parent
1928e2b870
commit
1dbba1b95b
@@ -14,7 +14,7 @@
|
||||
// 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/>.
|
||||
|
||||
use crate::cli::{CliChain, SourceConnectionParams, TargetConnectionParams, TargetSigningParams};
|
||||
use crate::cli::{SourceConnectionParams, TargetConnectionParams, TargetSigningParams};
|
||||
use bp_runtime::Chain as ChainBase;
|
||||
use codec::Encode;
|
||||
use pallet_bridge_grandpa::InitializationData;
|
||||
@@ -108,10 +108,9 @@ impl InitBridge {
|
||||
/// Run the command.
|
||||
pub async fn run(self) -> anyhow::Result<()> {
|
||||
select_bridge!(self.bridge, {
|
||||
let source_client = crate::rialto_millau::source_chain_client::<Source>(self.source).await?;
|
||||
let target_client = crate::rialto_millau::target_chain_client::<Target>(self.target).await?;
|
||||
let target_sign =
|
||||
Target::target_signing_params(self.target_sign).map_err(|e| anyhow::format_err!("{}", e))?;
|
||||
let source_client = self.source.into_client::<Source>().await?;
|
||||
let target_client = self.target.into_client::<Target>().await?;
|
||||
let target_sign = self.target_sign.into_keypair::<Target>()?;
|
||||
|
||||
crate::headers_initialize::initialize(
|
||||
source_client,
|
||||
|
||||
@@ -281,20 +281,6 @@ pub trait CliChain: relay_substrate_client::Chain {
|
||||
|
||||
/// Maximal extrinsic weight (from the runtime).
|
||||
fn max_extrinsic_weight() -> Weight;
|
||||
|
||||
/// Convert CLI signing parameters of `Source` chain into a `KeyPair` instance.
|
||||
fn source_signing_params(params: SourceSigningParams) -> Result<Self::KeyPair, String> {
|
||||
use sp_core::crypto::Pair;
|
||||
Self::KeyPair::from_string(¶ms.source_signer, params.source_signer_password.as_deref())
|
||||
.map_err(|e| format!("Failed to parse source-signer: {:?}", e))
|
||||
}
|
||||
|
||||
/// Convert CLI signing parameters of `Target` chain into a `KeyPair` instance.
|
||||
fn target_signing_params(params: TargetSigningParams) -> Result<Self::KeyPair, String> {
|
||||
use sp_core::crypto::Pair;
|
||||
Self::KeyPair::from_string(¶ms.target_signer, params.target_signer_password.as_deref())
|
||||
.map_err(|e| format!("Failed to parse target-signer: {:?}", e))
|
||||
}
|
||||
}
|
||||
|
||||
/// Lane id.
|
||||
@@ -425,12 +411,36 @@ macro_rules! declare_chain_options {
|
||||
#[structopt(long)]
|
||||
pub [<$chain_prefix _signer_password>]: Option<String>,
|
||||
}
|
||||
|
||||
impl [<$chain SigningParams>] {
|
||||
/// Parse signing params into chain-specific KeyPair.
|
||||
pub fn into_keypair<Chain: CliChain>(self) -> anyhow::Result<Chain::KeyPair> {
|
||||
use sp_core::crypto::Pair;
|
||||
Chain::KeyPair::from_string(
|
||||
&self.[<$chain_prefix _signer>],
|
||||
self.[<$chain_prefix _signer_password>].as_deref()
|
||||
).map_err(|e| anyhow::format_err!("{:?}", e))
|
||||
}
|
||||
}
|
||||
|
||||
impl [<$chain ConnectionParams>] {
|
||||
/// Convert connection params into Substrate client.
|
||||
pub async fn into_client<Chain: CliChain>(
|
||||
self,
|
||||
) -> anyhow::Result<relay_substrate_client::Client<Chain>> {
|
||||
Ok(relay_substrate_client::Client::new(relay_substrate_client::ConnectionParams {
|
||||
host: self.[<$chain_prefix _host>],
|
||||
port: self.[<$chain_prefix _port>],
|
||||
secure: self.[<$chain_prefix _secure>],
|
||||
})
|
||||
.await?
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// TODO [#852] Use structop renames instead of different fields.
|
||||
// TODO [#852] Add Into<ConnectionParams>?
|
||||
declare_chain_options!(Source, source);
|
||||
declare_chain_options!(Target, target);
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
// 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/>.
|
||||
|
||||
use crate::cli::{CliChain, PrometheusParams, SourceConnectionParams, TargetConnectionParams, TargetSigningParams};
|
||||
use crate::cli::{PrometheusParams, SourceConnectionParams, TargetConnectionParams, TargetSigningParams};
|
||||
use structopt::{clap::arg_enum, StructOpt};
|
||||
|
||||
/// Start headers relayer process.
|
||||
@@ -74,10 +74,9 @@ impl RelayHeaders {
|
||||
/// Run the command.
|
||||
pub async fn run(self) -> anyhow::Result<()> {
|
||||
select_bridge!(self.bridge, {
|
||||
let source_client = crate::rialto_millau::source_chain_client::<Source>(self.source).await?;
|
||||
let target_client = crate::rialto_millau::target_chain_client::<Target>(self.target).await?;
|
||||
let target_sign =
|
||||
Target::target_signing_params(self.target_sign).map_err(|e| anyhow::format_err!("{}", e))?;
|
||||
let source_client = self.source.into_client::<Source>().await?;
|
||||
let target_client = self.target.into_client::<Target>().await?;
|
||||
let target_sign = self.target_sign.into_keypair::<Target>()?;
|
||||
|
||||
crate::finality_pipeline::run(
|
||||
Finality::new(target_client.clone(), target_sign),
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
// along with Parity Bridges Common. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use crate::cli::{
|
||||
CliChain, HexLaneId, PrometheusParams, SourceConnectionParams, SourceSigningParams, TargetConnectionParams,
|
||||
HexLaneId, PrometheusParams, SourceConnectionParams, SourceSigningParams, TargetConnectionParams,
|
||||
TargetSigningParams,
|
||||
};
|
||||
use structopt::{clap::arg_enum, StructOpt};
|
||||
@@ -75,12 +75,10 @@ impl RelayMessages {
|
||||
/// Run the command.
|
||||
pub async fn run(self) -> anyhow::Result<()> {
|
||||
select_bridge!(self.bridge, {
|
||||
let source_client = crate::rialto_millau::source_chain_client::<Source>(self.source).await?;
|
||||
let source_sign =
|
||||
Source::source_signing_params(self.source_sign).map_err(|e| anyhow::format_err!("{}", e))?;
|
||||
let target_client = crate::rialto_millau::target_chain_client::<Target>(self.target).await?;
|
||||
let target_sign =
|
||||
Target::target_signing_params(self.target_sign).map_err(|e| anyhow::format_err!("{}", e))?;
|
||||
let source_client = self.source.into_client::<Source>().await?;
|
||||
let source_sign = self.source_sign.into_keypair::<Source>()?;
|
||||
let target_client = self.target.into_client::<Target>().await?;
|
||||
let target_sign = self.target_sign.into_keypair::<Target>()?;
|
||||
|
||||
run(
|
||||
source_client,
|
||||
|
||||
@@ -28,16 +28,13 @@ pub type MillauClient = relay_substrate_client::Client<Millau>;
|
||||
/// Rialto node client.
|
||||
pub type RialtoClient = relay_substrate_client::Client<Rialto>;
|
||||
|
||||
use crate::cli::{
|
||||
CliChain, ExplicitOrMaximal, HexBytes, Origins, SourceConnectionParams, SourceSigningParams,
|
||||
TargetConnectionParams, TargetSigningParams,
|
||||
};
|
||||
use crate::cli::{CliChain, ExplicitOrMaximal, HexBytes, Origins};
|
||||
use codec::{Decode, Encode};
|
||||
use frame_support::weights::{GetDispatchInfo, Weight};
|
||||
use pallet_bridge_dispatch::{CallOrigin, MessagePayload};
|
||||
use relay_millau_client::Millau;
|
||||
use relay_rialto_client::Rialto;
|
||||
use relay_substrate_client::{Chain, ConnectionParams, TransactionSignScheme};
|
||||
use relay_substrate_client::{Chain, TransactionSignScheme};
|
||||
use relay_westend_client::Westend;
|
||||
use sp_core::{Bytes, Pair};
|
||||
use sp_runtime::{traits::IdentifyAccount, MultiSigner};
|
||||
@@ -75,9 +72,9 @@ async fn run_send_message(command: cli::SendMessage) -> Result<(), String> {
|
||||
))
|
||||
};
|
||||
|
||||
let source_client = source_chain_client::<Source>(source).await?;
|
||||
let source_sign = Source::source_signing_params(source_sign)?;
|
||||
let target_sign = Target::target_signing_params(target_sign)?;
|
||||
let source_client = source.into_client::<Source>().await.map_err(format_err)?;
|
||||
let source_sign = source_sign.into_keypair::<Source>().map_err(format_err)?;
|
||||
let target_sign = target_sign.into_keypair::<Target>().map_err(format_err)?;
|
||||
let target_call = Target::encode_call(message)?;
|
||||
|
||||
let payload = {
|
||||
@@ -181,9 +178,9 @@ async fn run_send_message(command: cli::SendMessage) -> Result<(), String> {
|
||||
))
|
||||
};
|
||||
|
||||
let source_client = source_chain_client::<Source>(source).await?;
|
||||
let source_sign = Source::source_signing_params(source_sign)?;
|
||||
let target_sign = Target::target_signing_params(target_sign)?;
|
||||
let source_client = source.into_client::<Source>().await.map_err(format_err)?;
|
||||
let source_sign = source_sign.into_keypair::<Source>().map_err(format_err)?;
|
||||
let target_sign = target_sign.into_keypair::<Target>().map_err(format_err)?;
|
||||
let target_call = Target::encode_call(message)?;
|
||||
|
||||
let payload = {
|
||||
@@ -306,7 +303,7 @@ async fn run_estimate_fee(cmd: cli::EstimateFee) -> Result<(), String> {
|
||||
|
||||
let estimate_message_fee_method = bp_millau::TO_MILLAU_ESTIMATE_MESSAGE_FEE_METHOD;
|
||||
|
||||
let source_client = source_chain_client::<Source>(source).await?;
|
||||
let source_client = source.into_client::<Source>().await.map_err(format_err)?;
|
||||
let lane = lane.into();
|
||||
let payload = Source::encode_message(payload)?;
|
||||
|
||||
@@ -322,7 +319,7 @@ async fn run_estimate_fee(cmd: cli::EstimateFee) -> Result<(), String> {
|
||||
|
||||
let estimate_message_fee_method = bp_rialto::TO_RIALTO_ESTIMATE_MESSAGE_FEE_METHOD;
|
||||
|
||||
let source_client = source_chain_client::<Source>(source).await?;
|
||||
let source_client = source.into_client::<Source>().await.map_err(format_err)?;
|
||||
let lane = lane.into();
|
||||
let payload = Source::encode_message(payload)?;
|
||||
|
||||
@@ -601,16 +598,6 @@ impl CliChain for Rialto {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn source_signing_params(params: SourceSigningParams) -> Result<Self::KeyPair, String> {
|
||||
Self::KeyPair::from_string(¶ms.source_signer, params.source_signer_password.as_deref())
|
||||
.map_err(|e| format!("Failed to parse source-signer: {:?}", e))
|
||||
}
|
||||
|
||||
fn target_signing_params(params: TargetSigningParams) -> Result<Self::KeyPair, String> {
|
||||
Self::KeyPair::from_string(¶ms.target_signer, params.target_signer_password.as_deref())
|
||||
.map_err(|e| format!("Failed to parse target-signer: {:?}", e))
|
||||
}
|
||||
}
|
||||
|
||||
impl CliChain for Westend {
|
||||
@@ -636,26 +623,8 @@ impl CliChain for Westend {
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn source_chain_client<Chain: CliChain>(
|
||||
params: SourceConnectionParams,
|
||||
) -> relay_substrate_client::Result<relay_substrate_client::Client<Chain>> {
|
||||
relay_substrate_client::Client::new(ConnectionParams {
|
||||
host: params.source_host,
|
||||
port: params.source_port,
|
||||
secure: params.source_secure,
|
||||
})
|
||||
.await
|
||||
}
|
||||
|
||||
pub async fn target_chain_client<Chain: CliChain>(
|
||||
params: TargetConnectionParams,
|
||||
) -> relay_substrate_client::Result<relay_substrate_client::Client<Chain>> {
|
||||
relay_substrate_client::Client::new(ConnectionParams {
|
||||
host: params.target_host,
|
||||
port: params.target_port,
|
||||
secure: params.target_secure,
|
||||
})
|
||||
.await
|
||||
fn format_err(e: anyhow::Error) -> String {
|
||||
e.to_string()
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
Reference in New Issue
Block a user