Skip to content

Commit

Permalink
Add few CLI helpers (paritytech#764)
Browse files Browse the repository at this point in the history
* Adding call encoding.

* Add message payload encoding.

* Nicer output.

* Add fee estimation.

* cargo fmt --all

* Split message payload encoding into separate command.

* Use HexBytes.

* cargo fmt --all

* Fix compilation.
  • Loading branch information
tomusdrw authored and serban300 committed Apr 9, 2024
1 parent 6824363 commit 8d2b32b
Show file tree
Hide file tree
Showing 2 changed files with 369 additions and 57 deletions.
128 changes: 128 additions & 0 deletions bridges/relays/substrate/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,21 @@ pub enum Command {
/// The message is being sent to the source chain, delivered to the target chain and dispatched
/// there.
SendMessage(SendMessage),
/// Generate SCALE-encoded `Call` for choosen network.
///
/// The call can be used either as message payload or can be wrapped into a transaction
/// and executed on the chain directly.
EncodeCall(EncodeCall),
/// Generate SCALE-encoded `MessagePayload` object that can be sent over selected bridge.
///
/// The `MessagePayload` can be then fed to `MessageLane::send_message` function and sent over
/// the bridge.
EncodeMessagePayload(EncodeMessagePayload),
/// Estimate Delivery and Dispatch Fee required for message submission to message lane.
EstimateFee(EstimateFee),
}

/// Start headers relayer process.
#[derive(StructOpt)]
pub enum RelayHeaders {
/// Relay Millau headers to Rialto.
Expand All @@ -79,6 +92,7 @@ pub enum RelayHeaders {
},
}

/// Start message relayer process.
#[derive(StructOpt)]
pub enum RelayMessages {
/// Serve given lane of Millau -> Rialto messages.
Expand Down Expand Up @@ -115,6 +129,7 @@ pub enum RelayMessages {
},
}

/// Initialize bridge pallet.
#[derive(StructOpt)]
pub enum InitBridge {
/// Initialize Millau headers bridge in Rialto.
Expand All @@ -141,6 +156,7 @@ pub enum InitBridge {
},
}

/// Send bridge message.
#[derive(StructOpt)]
pub enum SendMessage {
/// Submit message to given Millau -> Rialto lane.
Expand Down Expand Up @@ -195,9 +211,112 @@ pub enum SendMessage {
},
}

/// A call to encode.
#[derive(StructOpt)]
pub enum EncodeCall {
/// Encode Rialto's Call.
Rialto {
#[structopt(flatten)]
call: ToRialtoMessage,
},
/// Encode Millau's Call.
Millau {
#[structopt(flatten)]
call: ToMillauMessage,
},
}

/// A `MessagePayload` to encode.
#[derive(StructOpt)]
pub enum EncodeMessagePayload {
/// Message Payload of Rialto to Millau call.
RialtoToMillau {
#[structopt(flatten)]
payload: RialtoToMillauMessagePayload,
},
/// Message Payload of Millau to Rialto call.
MillauToRialto {
#[structopt(flatten)]
payload: MillauToRialtoMessagePayload,
},
}

/// Estimate Delivery & Dispatch Fee command.
#[derive(StructOpt)]
pub enum EstimateFee {
/// Estimate fee of Rialto to Millau message.
RialtoToMillau {
#[structopt(flatten)]
rialto: RialtoConnectionParams,
/// Hex-encoded id of lane that will be delivering the message.
#[structopt(long)]
lane: HexLaneId,
/// Payload to send over the bridge.
#[structopt(flatten)]
payload: RialtoToMillauMessagePayload,
},
/// Estimate fee of Rialto to Millau message.
MillauToRialto {
#[structopt(flatten)]
millau: MillauConnectionParams,
/// Hex-encoded id of lane that will be delivering the message.
#[structopt(long)]
lane: HexLaneId,
/// Payload to send over the bridge.
#[structopt(flatten)]
payload: MillauToRialtoMessagePayload,
},
}

/// MessagePayload that can be delivered to message lane pallet on Millau.
#[derive(StructOpt, Debug)]
pub enum MillauToRialtoMessagePayload {
/// Raw, SCALE-encoded `MessagePayload`.
Raw {
/// Hex-encoded SCALE data.
#[structopt(long)]
data: Bytes,
},
/// Construct message to send over the bridge.
Message {
/// Message details.
#[structopt(flatten)]
message: ToRialtoMessage,
/// SS58 encoded account that will send the payload (must have SS58Prefix = 42)
#[structopt(long)]
sender: bp_rialto::AccountId,
},
}

/// MessagePayload that can be delivered to message lane pallet on Rialto.
#[derive(StructOpt, Debug)]
pub enum RialtoToMillauMessagePayload {
/// Raw, SCALE-encoded `MessagePayload`.
Raw {
/// Hex-encoded SCALE data.
#[structopt(long)]
data: Bytes,
},
/// Construct message to send over the bridge.
Message {
/// Message details.
#[structopt(flatten)]
message: ToMillauMessage,

/// SS58 encoded account that will send the payload (must have SS58Prefix = 42)
#[structopt(long)]
sender: bp_rialto::AccountId,
},
}

/// All possible messages that may be delivered to the Rialto chain.
#[derive(StructOpt, Debug)]
pub enum ToRialtoMessage {
/// Raw bytes for the message
Raw {
/// Raw, SCALE-encoded message
data: Bytes,
},
/// Make an on-chain remark (comment).
Remark {
/// Remark size. If not passed, small UTF8-encoded string is generated by relay as remark.
Expand All @@ -206,8 +325,10 @@ pub enum ToRialtoMessage {
},
/// Transfer the specified `amount` of native tokens to a particular `recipient`.
Transfer {
/// SS58 encoded account that will receive the transfer (must have SS58Prefix = 42)
#[structopt(long)]
recipient: bp_rialto::AccountId,
/// Amount of target tokens to send.
#[structopt(long)]
amount: bp_rialto::Balance,
},
Expand All @@ -216,6 +337,11 @@ pub enum ToRialtoMessage {
/// All possible messages that may be delivered to the Millau chain.
#[derive(StructOpt, Debug)]
pub enum ToMillauMessage {
/// Raw bytes for the message
Raw {
/// Raw, SCALE-encoded message
data: Bytes,
},
/// Make an on-chain remark (comment).
Remark {
/// Size of the remark. If not passed, small UTF8-encoded string is generated by relay as remark.
Expand All @@ -224,8 +350,10 @@ pub enum ToMillauMessage {
},
/// Transfer the specified `amount` of native tokens to a particular `recipient`.
Transfer {
/// SS58 encoded account that will receive the transfer (must have SS58Prefix = 42)
#[structopt(long)]
recipient: bp_millau::AccountId,
/// Amount of target tokens to send.
#[structopt(long)]
amount: bp_millau::Balance,
},
Expand Down
Loading

0 comments on commit 8d2b32b

Please sign in to comment.