Make relay CLI generic (#849)

* Start generalizing rialto-millau commands.

* cargo fmt --all

* Introduce generic balance.

* Unify message payloads.

* cargo fmt --all

* init - generic

* Attempt to unify send message.

* Start moving things around.

* cargo fmt --all

* Move init-bridge.

* cargo fmt --all

* Improve UX of bridge argument.

* Fix clippy.

* Fix docs and scripts.

* Add docs.

* Apply suggestions from code review

Co-authored-by: Hernando Castano <HCastano@users.noreply.github.com>

* Fix copyright.

* Add issue numbers.

* More todos.

* Update comments.

Co-authored-by: Hernando Castano <HCastano@users.noreply.github.com>
This commit is contained in:
Tomasz Drwięga
2021-04-01 12:49:49 +02:00
committed by Bastian Köcher
parent b6d034afaf
commit 904b9f4da5
22 changed files with 896 additions and 879 deletions
@@ -56,7 +56,6 @@ pub enum ExchangeRelayMode {
}
/// PoA exchange transaction relay params.
#[derive(Debug)]
pub struct EthereumExchangeParams {
/// Ethereum connection params.
pub eth_params: EthereumConnectionParams,
@@ -72,6 +71,19 @@ pub struct EthereumExchangeParams {
pub instance: Arc<dyn BridgeInstance>,
}
impl std::fmt::Debug for EthereumExchangeParams {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
f.debug_struct("EthereumExchangeParams")
.field("eth_params", &self.eth_params)
.field("sub_params", &self.sub_params)
.field("sub_sign", &sp_core::Pair::public(&self.sub_sign))
.field("mode", &self.mode)
.field("metrics_params", &self.metrics_params)
.field("instance", &self.instance)
.finish()
}
}
/// Ethereum to Substrate exchange pipeline.
struct EthereumToSubstrateExchange;
@@ -62,7 +62,6 @@ pub mod consts {
}
/// Ethereum synchronization parameters.
#[derive(Debug)]
pub struct EthereumSyncParams {
/// Ethereum connection params.
pub eth_params: EthereumConnectionParams,
@@ -78,6 +77,19 @@ pub struct EthereumSyncParams {
pub instance: Arc<dyn BridgeInstance>,
}
impl Debug for EthereumSyncParams {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
f.debug_struct("EthereumSyncParams")
.field("eth_params", &self.eth_params)
.field("sub_params", &self.sub_params)
.field("sub_sign", &sp_core::Pair::public(&self.sub_sign))
.field("sync_params", &self.sync_params)
.field("metrics_params", &self.metrics_params)
.field("instance", &self.instance)
.finish()
}
}
/// Ethereum synchronization pipeline.
#[derive(Clone, Copy, Debug)]
#[cfg_attr(test, derive(PartialEq))]
+3 -2
View File
@@ -167,10 +167,11 @@ fn substrate_connection_params(matches: &clap::ArgMatches) -> Result<SubstrateCo
}
fn rialto_signing_params(matches: &clap::ArgMatches) -> Result<RialtoSigningParams, String> {
let mut params = RialtoSigningParams::default();
let mut params = sp_keyring::AccountKeyring::Alice.pair();
if let Some(sub_signer) = matches.value_of("sub-signer") {
let sub_signer_password = matches.value_of("sub-signer-password");
params.signer = sp_core::sr25519::Pair::from_string(sub_signer, sub_signer_password)
params = sp_core::sr25519::Pair::from_string(sub_signer, sub_signer_password)
.map_err(|e| format!("Failed to parse sub-signer: {:?}", e))?;
}
Ok(params)
@@ -156,20 +156,17 @@ impl SubmitEthereumHeaders for SubstrateClient<Rialto> {
) -> SubmittedHeaders<EthereumHeaderId, RpcError> {
let ids = headers.iter().map(|header| header.id()).collect();
let submission_result = async {
self.submit_signed_extrinsic(
params.signer.public().as_array_ref().clone().into(),
|transaction_nonce| {
Bytes(
Rialto::sign_transaction(
*self.genesis_hash(),
&params.signer,
transaction_nonce,
instance.build_signed_header_call(headers),
)
.encode(),
self.submit_signed_extrinsic(params.public().as_array_ref().clone().into(), |transaction_nonce| {
Bytes(
Rialto::sign_transaction(
*self.genesis_hash(),
&params,
transaction_nonce,
instance.build_signed_header_call(headers),
)
},
)
.encode(),
)
})
.await?;
Ok(())
}
@@ -260,20 +257,17 @@ impl SubmitEthereumExchangeTransactionProof for SubstrateClient<Rialto> {
instance: Arc<dyn BridgeInstance>,
proof: rialto_runtime::exchange::EthereumTransactionInclusionProof,
) -> RpcResult<()> {
self.submit_signed_extrinsic(
params.signer.public().as_array_ref().clone().into(),
|transaction_nonce| {
Bytes(
Rialto::sign_transaction(
*self.genesis_hash(),
&params.signer,
transaction_nonce,
instance.build_currency_exchange_call(proof),
)
.encode(),
self.submit_signed_extrinsic(params.public().as_array_ref().clone().into(), |transaction_nonce| {
Bytes(
Rialto::sign_transaction(
*self.genesis_hash(),
&params,
transaction_nonce,
instance.build_currency_exchange_call(proof),
)
},
)
.encode(),
)
})
.await?;
Ok(())
}