Use kebab-case for bridge arguments (#1036)

* Updates bridge CLI arguments to be kebab case

* Updates scripts to use kebab case for bridge initialisation and relaying of headers/messages

* Updates message sending subcommand to be kebab case

* Updates documentation for message sending subcommand
This commit is contained in:
halfpint104
2021-06-30 17:58:21 +01:00
committed by Bastian Köcher
parent ecd20d9d24
commit 84da766881
11 changed files with 62 additions and 59 deletions
+2 -2
View File
@@ -159,7 +159,7 @@ Then we need to initialize and run the relayer:
```bash ```bash
docker run --network=host -it \ docker run --network=host -it \
paritytech/substrate-relay init-bridge RialtoToMillau \ paritytech/substrate-relay init-bridge rialto-to-millau \
--target-host localhost \ --target-host localhost \
--target-port 9945 \ --target-port 9945 \
--source-host localhost \ --source-host localhost \
@@ -167,7 +167,7 @@ docker run --network=host -it \
--target-signer //Alice --target-signer //Alice
docker run --network=host -it \ docker run --network=host -it \
paritytech/substrate-relay relay-headers RialtoToMillau \ paritytech/substrate-relay relay-headers rialto-to-millau \
--target-host localhost \ --target-host localhost \
--target-port 9945 \ --target-port 9945 \
--source-host localhost \ --source-host localhost \
+1
View File
@@ -17,6 +17,7 @@ num-format = "0.4"
num-traits = "0.2" num-traits = "0.2"
paste = "1.0" paste = "1.0"
structopt = "0.3" structopt = "0.3"
strum = { version = "0.21.0", features = ["derive"] }
# Bridge dependencies # Bridge dependencies
@@ -14,17 +14,16 @@
// You should have received a copy of the GNU General Public License // 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/>. // along with Parity Bridges Common. If not, see <http://www.gnu.org/licenses/>.
use structopt::clap::arg_enum; use strum::{EnumString, EnumVariantNames};
arg_enum! { #[derive(Debug, PartialEq, Eq, EnumString, EnumVariantNames)]
#[derive(Debug, PartialEq, Eq)] #[strum(serialize_all = "kebab_case")]
/// Supported full bridges (headers + messages). /// Supported full bridges (headers + messages).
pub enum FullBridge { pub enum FullBridge {
MillauToRialto, MillauToRialto,
RialtoToMillau, RialtoToMillau,
RococoToWococo, RococoToWococo,
WococoToRococo, WococoToRococo,
}
} }
impl FullBridge { impl FullBridge {
@@ -18,6 +18,7 @@ use crate::cli::{bridge::FullBridge, AccountId};
use crate::select_full_bridge; use crate::select_full_bridge;
use relay_substrate_client::Chain; use relay_substrate_client::Chain;
use structopt::StructOpt; use structopt::StructOpt;
use strum::VariantNames;
/// Given a source chain `AccountId`, derive the corresponding `AccountId` for the target chain. /// Given a source chain `AccountId`, derive the corresponding `AccountId` for the target chain.
/// ///
@@ -28,7 +29,7 @@ use structopt::StructOpt;
#[derive(StructOpt)] #[derive(StructOpt)]
pub struct DeriveAccount { pub struct DeriveAccount {
/// A bridge instance to initalize. /// A bridge instance to initalize.
#[structopt(possible_values = &FullBridge::variants(), case_insensitive = true)] #[structopt(possible_values = FullBridge::VARIANTS, case_insensitive = true)]
bridge: FullBridge, bridge: FullBridge,
/// Source-chain address to derive Target-chain address from. /// Source-chain address to derive Target-chain address from.
account: AccountId, account: AccountId,
@@ -80,9 +81,9 @@ mod tests {
let millau = "752paRyW1EGfq9YLTSSqcSJ5hqnBDidBmaftGhBo8fy6ypW9"; let millau = "752paRyW1EGfq9YLTSSqcSJ5hqnBDidBmaftGhBo8fy6ypW9";
// when // when
let (rialto_parsed, rialto_derived) = derive_account_cli("RialtoToMillau", rialto); let (rialto_parsed, rialto_derived) = derive_account_cli("rialto-to-millau", rialto);
let (millau_parsed, millau_derived) = derive_account_cli("MillauToRialto", millau); let (millau_parsed, millau_derived) = derive_account_cli("millau-to-rialto", millau);
let (millau2_parsed, millau2_derived) = derive_account_cli("MillauToRialto", rialto); let (millau2_parsed, millau2_derived) = derive_account_cli("millau-to-rialto", rialto);
// then // then
assert_eq!(format!("{}", rialto_parsed), rialto); assert_eq!(format!("{}", rialto_parsed), rialto);
@@ -20,12 +20,13 @@ use crate::select_full_bridge;
use frame_support::weights::DispatchInfo; use frame_support::weights::DispatchInfo;
use relay_substrate_client::Chain; use relay_substrate_client::Chain;
use structopt::StructOpt; use structopt::StructOpt;
use strum::VariantNames;
/// Encode source chain runtime call. /// Encode source chain runtime call.
#[derive(StructOpt, Debug)] #[derive(StructOpt, Debug)]
pub struct EncodeCall { pub struct EncodeCall {
/// A bridge instance to encode call for. /// A bridge instance to encode call for.
#[structopt(possible_values = &FullBridge::variants(), case_insensitive = true)] #[structopt(possible_values = FullBridge::VARIANTS, case_insensitive = true)]
bridge: FullBridge, bridge: FullBridge,
#[structopt(flatten)] #[structopt(flatten)]
call: Call, call: Call,
@@ -194,7 +195,7 @@ mod tests {
// given // given
let mut encode_call = EncodeCall::from_iter(vec![ let mut encode_call = EncodeCall::from_iter(vec![
"encode-call", "encode-call",
"RialtoToMillau", "rialto-to-millau",
"transfer", "transfer",
"--amount", "--amount",
"12345", "12345",
@@ -215,7 +216,7 @@ mod tests {
#[test] #[test]
fn should_encode_remark_with_default_payload() { fn should_encode_remark_with_default_payload() {
// given // given
let mut encode_call = EncodeCall::from_iter(vec!["encode-call", "RialtoToMillau", "remark"]); let mut encode_call = EncodeCall::from_iter(vec!["encode-call", "rialto-to-millau", "remark"]);
// when // when
let hex = encode_call.encode().unwrap(); let hex = encode_call.encode().unwrap();
@@ -229,7 +230,7 @@ mod tests {
// given // given
let mut encode_call = EncodeCall::from_iter(vec![ let mut encode_call = EncodeCall::from_iter(vec![
"encode-call", "encode-call",
"RialtoToMillau", "rialto-to-millau",
"remark", "remark",
"--remark-payload", "--remark-payload",
"1234", "1234",
@@ -246,7 +247,7 @@ mod tests {
fn should_encode_remark_with_size() { fn should_encode_remark_with_size() {
// given // given
let mut encode_call = let mut encode_call =
EncodeCall::from_iter(vec!["encode-call", "RialtoToMillau", "remark", "--remark-size", "12"]); EncodeCall::from_iter(vec!["encode-call", "rialto-to-millau", "remark", "--remark-size", "12"]);
// when // when
let hex = encode_call.encode().unwrap(); let hex = encode_call.encode().unwrap();
@@ -260,7 +261,7 @@ mod tests {
// when // when
let err = EncodeCall::from_iter_safe(vec![ let err = EncodeCall::from_iter_safe(vec![
"encode-call", "encode-call",
"RialtoToMillau", "rialto-to-millau",
"remark", "remark",
"--remark-payload", "--remark-payload",
"1234", "1234",
@@ -17,6 +17,7 @@
use crate::cli::{bridge::FullBridge, AccountId, CliChain, HexBytes}; use crate::cli::{bridge::FullBridge, AccountId, CliChain, HexBytes};
use crate::select_full_bridge; use crate::select_full_bridge;
use structopt::StructOpt; use structopt::StructOpt;
use strum::VariantNames;
/// Generic message payload. /// Generic message payload.
#[derive(StructOpt, Debug, PartialEq, Eq)] #[derive(StructOpt, Debug, PartialEq, Eq)]
@@ -41,7 +42,7 @@ pub enum MessagePayload {
#[derive(StructOpt)] #[derive(StructOpt)]
pub struct EncodeMessage { pub struct EncodeMessage {
/// A bridge instance to initalize. /// A bridge instance to initalize.
#[structopt(possible_values = &FullBridge::variants(), case_insensitive = true)] #[structopt(possible_values = FullBridge::VARIANTS, case_insensitive = true)]
bridge: FullBridge, bridge: FullBridge,
#[structopt(flatten)] #[structopt(flatten)]
payload: MessagePayload, payload: MessagePayload,
@@ -73,7 +74,7 @@ mod tests {
fn should_encode_raw_message() { fn should_encode_raw_message() {
// given // given
let msg = "01000000e88514000000000002d43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d003c040130000000000000000000000000"; let msg = "01000000e88514000000000002d43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d003c040130000000000000000000000000";
let encode_message = EncodeMessage::from_iter(vec!["encode-message", "MillauToRialto", "raw", msg]); let encode_message = EncodeMessage::from_iter(vec!["encode-message", "rialto-to-millau", "raw", msg]);
// when // when
let hex = encode_message.encode().unwrap(); let hex = encode_message.encode().unwrap();
@@ -88,7 +89,7 @@ mod tests {
let sender = sp_keyring::AccountKeyring::Alice.to_account_id().to_ss58check(); let sender = sp_keyring::AccountKeyring::Alice.to_account_id().to_ss58check();
let encode_message = EncodeMessage::from_iter(vec![ let encode_message = EncodeMessage::from_iter(vec![
"encode-message", "encode-message",
"RialtoToMillau", "rialto-to-millau",
"call", "call",
"--sender", "--sender",
&sender, &sender,
@@ -20,12 +20,13 @@ use crate::select_full_bridge;
use codec::{Decode, Encode}; use codec::{Decode, Encode};
use relay_substrate_client::Chain; use relay_substrate_client::Chain;
use structopt::StructOpt; use structopt::StructOpt;
use strum::VariantNames;
/// Estimate Delivery & Dispatch Fee command. /// Estimate Delivery & Dispatch Fee command.
#[derive(StructOpt, Debug, PartialEq, Eq)] #[derive(StructOpt, Debug, PartialEq, Eq)]
pub struct EstimateFee { pub struct EstimateFee {
/// A bridge instance to encode call for. /// A bridge instance to encode call for.
#[structopt(possible_values = &FullBridge::variants(), case_insensitive = true)] #[structopt(possible_values = FullBridge::VARIANTS, case_insensitive = true)]
bridge: FullBridge, bridge: FullBridge,
#[structopt(flatten)] #[structopt(flatten)]
source: SourceConnectionParams, source: SourceConnectionParams,
@@ -93,7 +94,7 @@ mod tests {
// when // when
let res = EstimateFee::from_iter(vec![ let res = EstimateFee::from_iter(vec![
"estimate_fee", "estimate_fee",
"RialtoToMillau", "rialto-to-millau",
"--source-port", "--source-port",
"1234", "1234",
"call", "call",
@@ -20,13 +20,14 @@ use bp_runtime::Chain as ChainBase;
use codec::Encode; use codec::Encode;
use relay_substrate_client::{Chain, TransactionSignScheme}; use relay_substrate_client::{Chain, TransactionSignScheme};
use sp_core::{Bytes, Pair}; use sp_core::{Bytes, Pair};
use structopt::{clap::arg_enum, StructOpt}; use structopt::StructOpt;
use strum::{EnumString, EnumVariantNames, VariantNames};
/// Initialize bridge pallet. /// Initialize bridge pallet.
#[derive(StructOpt)] #[derive(StructOpt)]
pub struct InitBridge { pub struct InitBridge {
/// A bridge instance to initalize. /// A bridge instance to initalize.
#[structopt(possible_values = &InitBridgeName::variants(), case_insensitive = true)] #[structopt(possible_values = InitBridgeName::VARIANTS, case_insensitive = true)]
bridge: InitBridgeName, bridge: InitBridgeName,
#[structopt(flatten)] #[structopt(flatten)]
source: SourceConnectionParams, source: SourceConnectionParams,
@@ -36,17 +37,15 @@ pub struct InitBridge {
target_sign: TargetSigningParams, target_sign: TargetSigningParams,
} }
// TODO [#851] Use kebab-case. #[derive(Debug, EnumString, EnumVariantNames)]
arg_enum! { #[strum(serialize_all = "kebab_case")]
#[derive(Debug)] /// Bridge to initialize.
/// Bridge to initialize. pub enum InitBridgeName {
pub enum InitBridgeName {
MillauToRialto, MillauToRialto,
RialtoToMillau, RialtoToMillau,
WestendToMillau, WestendToMillau,
RococoToWococo, RococoToWococo,
WococoToRococo, WococoToRococo,
}
} }
macro_rules! select_bridge { macro_rules! select_bridge {
@@ -16,13 +16,14 @@
use crate::cli::{PrometheusParams, SourceConnectionParams, TargetConnectionParams, TargetSigningParams}; use crate::cli::{PrometheusParams, SourceConnectionParams, TargetConnectionParams, TargetSigningParams};
use crate::finality_pipeline::SubstrateFinalitySyncPipeline; use crate::finality_pipeline::SubstrateFinalitySyncPipeline;
use structopt::{clap::arg_enum, StructOpt}; use structopt::StructOpt;
use strum::{EnumString, EnumVariantNames, VariantNames};
/// Start headers relayer process. /// Start headers relayer process.
#[derive(StructOpt)] #[derive(StructOpt)]
pub struct RelayHeaders { pub struct RelayHeaders {
/// A bridge instance to relay headers for. /// A bridge instance to relay headers for.
#[structopt(possible_values = &RelayHeadersBridge::variants(), case_insensitive = true)] #[structopt(possible_values = RelayHeadersBridge::VARIANTS, case_insensitive = true)]
bridge: RelayHeadersBridge, bridge: RelayHeadersBridge,
/// If passed, only mandatory headers (headers that are changing the GRANDPA authorities set) are relayed. /// If passed, only mandatory headers (headers that are changing the GRANDPA authorities set) are relayed.
#[structopt(long)] #[structopt(long)]
@@ -37,17 +38,15 @@ pub struct RelayHeaders {
prometheus_params: PrometheusParams, prometheus_params: PrometheusParams,
} }
// TODO [#851] Use kebab-case. #[derive(Debug, EnumString, EnumVariantNames)]
arg_enum! { #[strum(serialize_all = "kebab_case")]
#[derive(Debug)] /// Headers relay bridge.
/// Headers relay bridge. pub enum RelayHeadersBridge {
pub enum RelayHeadersBridge {
MillauToRialto, MillauToRialto,
RialtoToMillau, RialtoToMillau,
WestendToMillau, WestendToMillau,
RococoToWococo, RococoToWococo,
WococoToRococo, WococoToRococo,
}
} }
macro_rules! select_bridge { macro_rules! select_bridge {
@@ -21,14 +21,14 @@ use crate::cli::{
}; };
use crate::messages_lane::MessagesRelayParams; use crate::messages_lane::MessagesRelayParams;
use crate::select_full_bridge; use crate::select_full_bridge;
use structopt::StructOpt; use structopt::StructOpt;
use strum::VariantNames;
/// Start messages relayer process. /// Start messages relayer process.
#[derive(StructOpt)] #[derive(StructOpt)]
pub struct RelayMessages { pub struct RelayMessages {
/// A bridge instance to relay messages for. /// A bridge instance to relay messages for.
#[structopt(possible_values = &FullBridge::variants(), case_insensitive = true)] #[structopt(possible_values = FullBridge::VARIANTS, case_insensitive = true)]
bridge: FullBridge, bridge: FullBridge,
/// Hex-encoded lane id that should be served by the relay. Defaults to `00000000`. /// Hex-encoded lane id that should be served by the relay. Defaults to `00000000`.
#[structopt(long, default_value = "00000000")] #[structopt(long, default_value = "00000000")]
@@ -30,12 +30,13 @@ use sp_core::{Bytes, Pair};
use sp_runtime::{traits::IdentifyAccount, AccountId32, MultiSignature, MultiSigner}; use sp_runtime::{traits::IdentifyAccount, AccountId32, MultiSignature, MultiSigner};
use std::fmt::Debug; use std::fmt::Debug;
use structopt::StructOpt; use structopt::StructOpt;
use strum::VariantNames;
/// Send bridge message. /// Send bridge message.
#[derive(StructOpt)] #[derive(StructOpt)]
pub struct SendMessage { pub struct SendMessage {
/// A bridge instance to encode call for. /// A bridge instance to encode call for.
#[structopt(possible_values = &FullBridge::variants(), case_insensitive = true)] #[structopt(possible_values = FullBridge::VARIANTS, case_insensitive = true)]
bridge: FullBridge, bridge: FullBridge,
#[structopt(flatten)] #[structopt(flatten)]
source: SourceConnectionParams, source: SourceConnectionParams,
@@ -260,7 +261,7 @@ mod tests {
// given // given
let mut send_message = SendMessage::from_iter(vec![ let mut send_message = SendMessage::from_iter(vec![
"send-message", "send-message",
"RialtoToMillau", "rialto-to-millau",
"--source-port", "--source-port",
"1234", "1234",
"--source-signer", "--source-signer",
@@ -291,7 +292,7 @@ mod tests {
// given // given
let mut send_message = SendMessage::from_iter(vec![ let mut send_message = SendMessage::from_iter(vec![
"send-message", "send-message",
"MillauToRialto", "millau-to-rialto",
"--source-port", "--source-port",
"1234", "1234",
"--source-signer", "--source-signer",
@@ -335,7 +336,7 @@ mod tests {
// given // given
let send_message = SendMessage::from_iter_safe(vec![ let send_message = SendMessage::from_iter_safe(vec![
"send-message", "send-message",
"MillauToRialto", "rialto-to-millau",
"--source-port", "--source-port",
"1234", "1234",
"--source-signer", "--source-signer",