Skip to content

Commit

Permalink
Rework relay CLI a bit (paritytech#734)
Browse files Browse the repository at this point in the history
* Change CLI UX.

* De-duplicate main.

* De-duplicate send message.

* Add more docs and extract functions.

* Fix scripts.

* cargo fmt --all

* Add missing 'u'.
  • Loading branch information
tomusdrw authored and serban300 committed Apr 10, 2024
1 parent 48bdc92 commit 3c55eb4
Show file tree
Hide file tree
Showing 2 changed files with 339 additions and 328 deletions.
123 changes: 81 additions & 42 deletions bridges/relays/substrate/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,72 +26,124 @@ pub fn parse_args() -> Command {
Command::from_args()
}

/// Substrate-to-Substrate relay CLI args.
/// Substrate-to-Substrate bridge utilities.
#[derive(StructOpt)]
#[structopt(about = "Substrate-to-Substrate relay")]
pub enum Command {
/// Initialize Millau headers bridge in Rialto.
InitializeMillauHeadersBridgeInRialto {
/// Start headers relay between two chains.
///
/// The on-chain bridge component should have been already initialized with
/// `init-bridge` sub-command.
RelayHeaders(RelayHeaders),
/// Start messages relay between two chains.
///
/// Ties up to `MessageLane` pallets on both chains and starts relaying messages.
/// Requires the header relay to be already running.
RelayMessages(RelayMessages),
/// Initialize on-chain bridge pallet with current header data.
///
/// Sends initialization transaction to bootstrap the bridge with current finalized block data.
InitBridge(InitBridge),
/// Send custom message over the bridge.
///
/// Allows interacting with the bridge by sending messages over `MessageLane` component.
/// The message is being sent to the source chain, delivered to the target chain and dispatched
/// there.
SendMessage(SendMessage),
}

#[derive(StructOpt)]
pub enum RelayHeaders {
/// Relay Millau headers to Rialto.
MillauToRialto {
#[structopt(flatten)]
millau: MillauConnectionParams,
#[structopt(flatten)]
rialto: RialtoConnectionParams,
#[structopt(flatten)]
rialto_sign: RialtoSigningParams,
#[structopt(flatten)]
millau_bridge_params: MillauBridgeInitializationParams,
prometheus_params: PrometheusParams,
},
/// Relay Millau headers to Rialto.
MillauHeadersToRialto {
#[structopt(flatten)]
millau: MillauConnectionParams,
/// Relay Rialto headers to Millau.
RialtoToMillau {
#[structopt(flatten)]
rialto: RialtoConnectionParams,
#[structopt(flatten)]
rialto_sign: RialtoSigningParams,
millau: MillauConnectionParams,
#[structopt(flatten)]
millau_sign: MillauSigningParams,
#[structopt(flatten)]
prometheus_params: PrometheusParams,
},
/// Initialize Rialto headers bridge in Millau.
InitializeRialtoHeadersBridgeInMillau {
#[structopt(flatten)]
rialto: RialtoConnectionParams,
}

#[derive(StructOpt)]
pub enum RelayMessages {
/// Serve given lane of Millau -> Rialto messages.
MillauToRialto {
#[structopt(flatten)]
millau: MillauConnectionParams,
#[structopt(flatten)]
millau_sign: MillauSigningParams,
#[structopt(flatten)]
rialto_bridge_params: RialtoBridgeInitializationParams,
rialto: RialtoConnectionParams,
#[structopt(flatten)]
rialto_sign: RialtoSigningParams,
#[structopt(flatten)]
prometheus_params: PrometheusParams,
/// Hex-encoded id of lane that should be served by relay.
#[structopt(long)]
lane: HexLaneId,
},
/// Relay Rialto headers to Millau.
RialtoHeadersToMillau {
/// Serve given lane of Rialto -> Millau messages.
RialtoToMillau {
#[structopt(flatten)]
rialto: RialtoConnectionParams,
#[structopt(flatten)]
rialto_sign: RialtoSigningParams,
#[structopt(flatten)]
millau: MillauConnectionParams,
#[structopt(flatten)]
millau_sign: MillauSigningParams,
#[structopt(flatten)]
prometheus_params: PrometheusParams,
/// Hex-encoded id of lane that should be served by relay.
#[structopt(long)]
lane: HexLaneId,
},
/// Serve given lane of Millau -> Rialto messages.
MillauMessagesToRialto {
}

#[derive(StructOpt)]
pub enum InitBridge {
/// Initialize Millau headers bridge in Rialto.
MillauToRialto {
#[structopt(flatten)]
millau: MillauConnectionParams,
#[structopt(flatten)]
millau_sign: MillauSigningParams,
#[structopt(flatten)]
rialto: RialtoConnectionParams,
#[structopt(flatten)]
rialto_sign: RialtoSigningParams,
#[structopt(flatten)]
prometheus_params: PrometheusParams,
/// Hex-encoded id of lane that should be served by relay.
#[structopt(long)]
lane: HexLaneId,
millau_bridge_params: MillauBridgeInitializationParams,
},
/// Initialize Rialto headers bridge in Millau.
RialtoToMillau {
#[structopt(flatten)]
rialto: RialtoConnectionParams,
#[structopt(flatten)]
millau: MillauConnectionParams,
#[structopt(flatten)]
millau_sign: MillauSigningParams,
#[structopt(flatten)]
rialto_bridge_params: RialtoBridgeInitializationParams,
},
}

#[derive(StructOpt)]
pub enum SendMessage {
/// Submit message to given Millau -> Rialto lane.
SubmitMillauToRialtoMessage {
MillauToRialto {
#[structopt(flatten)]
millau: MillauConnectionParams,
#[structopt(flatten)]
Expand All @@ -111,24 +163,8 @@ pub enum Command {
#[structopt(long, possible_values = &Origins::variants())]
origin: Origins,
},
/// Serve given lane of Rialto -> Millau messages.
RialtoMessagesToMillau {
#[structopt(flatten)]
rialto: RialtoConnectionParams,
#[structopt(flatten)]
rialto_sign: RialtoSigningParams,
#[structopt(flatten)]
millau: MillauConnectionParams,
#[structopt(flatten)]
millau_sign: MillauSigningParams,
#[structopt(flatten)]
prometheus_params: PrometheusParams,
/// Hex-encoded id of lane that should be served by relay.
#[structopt(long)]
lane: HexLaneId,
},
/// Submit message to given Rialto -> Millau lane.
SubmitRialtoToMillauMessage {
RialtoToMillau {
#[structopt(flatten)]
rialto: RialtoConnectionParams,
#[structopt(flatten)]
Expand Down Expand Up @@ -181,6 +217,9 @@ pub enum ToMillauMessage {
arg_enum! {
#[derive(Debug)]
/// The origin to use when dispatching the message on the target chain.
///
/// - `Target` uses account existing on the target chain (requires target private key).
/// - `Origin` uses account derived from the source-chain account.
pub enum Origins {
Target,
Source,
Expand Down
Loading

0 comments on commit 3c55eb4

Please sign in to comment.