From a28223f2e68a22ce67e576d98b21e7ba3ccd551e Mon Sep 17 00:00:00 2001 From: Filip Dulic Date: Tue, 13 Apr 2021 12:16:58 -0500 Subject: [PATCH 01/25] Add new jcli-lib crate to workspace This is the beginning step for refactoring the jcli-lib crate from the jcli binary crate. This is the starting commit for #3172 --- Cargo.lock | 4 ++++ Cargo.toml | 1 + jcli-lib/Cargo.toml | 14 ++++++++++++++ jcli-lib/src/lib.rs | 7 +++++++ 4 files changed, 26 insertions(+) create mode 100644 jcli-lib/Cargo.toml create mode 100644 jcli-lib/src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index 60b8fd6661..7cef180b0f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1945,6 +1945,10 @@ dependencies = [ "versionisator", ] +[[package]] +name = "jcli-lib" +version = "0.11.1" + [[package]] name = "jormungandr" version = "0.11.1" diff --git a/Cargo.toml b/Cargo.toml index 4f74e2a3d5..295180d22f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,6 +3,7 @@ members = [ "jormungandr-lib", "jormungandr", "jcli", + "jcli-lib", "modules/settings", "modules/blockchain", "testing/jormungandr-testing-utils", diff --git a/jcli-lib/Cargo.toml b/jcli-lib/Cargo.toml new file mode 100644 index 0000000000..87868aefdc --- /dev/null +++ b/jcli-lib/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "jcli-lib" +version = "0.11.1" +authors = [ "dev@iohk.io" ] +license = "MIT OR Apache-2.0" +repository = "https://github.com/input-output-hk/jormungandr" +homepage = "https://github.com/input-output-hk/jormungandr#README.md" +documentation = "https://github.com/input-output-hk/jormungandr#USAGE.md" +description = """ +Midgard Serpent +""" +edition = "2018" + +[dependencies] diff --git a/jcli-lib/src/lib.rs b/jcli-lib/src/lib.rs new file mode 100644 index 0000000000..31e1bb209f --- /dev/null +++ b/jcli-lib/src/lib.rs @@ -0,0 +1,7 @@ +#[cfg(test)] +mod tests { + #[test] + fn it_works() { + assert_eq!(2 + 2, 4); + } +} From d002b33f0d0543397aa9d20551fe6a15b03d32f0 Mon Sep 17 00:00:00 2001 From: Filip Dulic Date: Tue, 13 Apr 2021 14:37:52 -0500 Subject: [PATCH 02/25] transfer the same dependencies from jcli to jcli-lib --- Cargo.lock | 32 ++++++++++++++++++++++++++++++++ jcli-lib/Cargo.toml | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index 7cef180b0f..28dde11af6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1948,6 +1948,38 @@ dependencies = [ [[package]] name = "jcli-lib" version = "0.11.1" +dependencies = [ + "assert_fs", + "base64 0.13.0", + "bech32", + "bincode", + "bytes 1.0.1", + "chain-addr", + "chain-core", + "chain-crypto", + "chain-impl-mockchain", + "chain-time", + "chain-vote", + "clap", + "ed25519-bip32", + "gtmpl", + "hex", + "jormungandr-lib", + "mime", + "predicates", + "rand 0.8.3", + "rand_chacha 0.3.0", + "rayon", + "reqwest", + "serde", + "serde_derive", + "serde_json", + "serde_yaml", + "structopt", + "thiserror", + "valico", + "versionisator", +] [[package]] name = "jormungandr" diff --git a/jcli-lib/Cargo.toml b/jcli-lib/Cargo.toml index 87868aefdc..53e34c2fa2 100644 --- a/jcli-lib/Cargo.toml +++ b/jcli-lib/Cargo.toml @@ -12,3 +12,45 @@ Midgard Serpent edition = "2018" [dependencies] +rand = "0.8" +rand_chacha = "0.3" +serde = "1.0" +serde_derive = "1.0" +serde_json = "1.0.59" +serde_yaml = "0.8" +bincode = "1.3.3" +mime = "^0.3.7" +structopt = "^0.3" +bech32 = "0.7" +hex = "0.4.2" +rayon = "1.5" +base64 = "0.13.0" +chain-core = { git = "https://github.com/input-output-hk/chain-libs.git", branch = "master" } +chain-impl-mockchain = { git = "https://github.com/input-output-hk/chain-libs.git", branch = "master" } +chain-addr = { git = "https://github.com/input-output-hk/chain-libs.git", branch = "master" } +chain-crypto = { git = "https://github.com/input-output-hk/chain-libs.git", branch = "master" } +chain-time = { git = "https://github.com/input-output-hk/chain-libs.git", branch = "master" } +chain-vote = { git = "https://github.com/input-output-hk/chain-libs.git", branch = "master", features = ["p256k1"] } +jormungandr-lib = { path = "../jormungandr-lib" } +gtmpl = "0.6.0" +valico = "3.5.0" +ed25519-bip32 = "0.3" +thiserror = "1.0" +bytes = "1.0" + +[dependencies.clap] +version = "2.33" +default-features = false +features = [ "suggestions", "color", "wrap_help" ] + +[dependencies.reqwest] +version = "0.11" +default-features = false +features = ["blocking", "rustls-tls", "json"] + +[dev-dependencies] +assert_fs = "1.0" +predicates = "1.0" + +[build-dependencies] +versionisator = "1.0.2" From 232d99fad721596ca35f3430daa597821ac4bd1e Mon Sep 17 00:00:00 2001 From: Filip Dulic Date: Tue, 13 Apr 2021 14:44:58 -0500 Subject: [PATCH 03/25] bulk transfer of jcli_lib code into jcli-lib crate --- {jcli/src/jcli_lib => jcli-lib/src}/address.rs | 0 {jcli/src/jcli_lib => jcli-lib/src}/auto_completion.rs | 0 {jcli/src/jcli_lib => jcli-lib/src}/block/mod.rs | 0 {jcli/src/jcli_lib => jcli-lib/src}/certificate/mod.rs | 0 .../src}/certificate/new_encrypted_vote_tally.rs | 0 .../src}/certificate/new_owner_stake_delegation.rs | 0 .../jcli_lib => jcli-lib/src}/certificate/new_stake_delegation.rs | 0 .../src}/certificate/new_stake_pool_registration.rs | 0 .../src}/certificate/new_stake_pool_retirement.rs | 0 {jcli/src/jcli_lib => jcli-lib/src}/certificate/new_vote_cast.rs | 0 {jcli/src/jcli_lib => jcli-lib/src}/certificate/new_vote_plan.rs | 0 {jcli/src/jcli_lib => jcli-lib/src}/certificate/new_vote_tally.rs | 0 {jcli/src/jcli_lib => jcli-lib/src}/certificate/show.rs | 0 .../jcli_lib => jcli-lib/src}/certificate/show/stake_pool_id.rs | 0 .../jcli_lib => jcli-lib/src}/certificate/show/vote_plan_id.rs | 0 {jcli/src/jcli_lib => jcli-lib/src}/certificate/sign.rs | 0 .../jcli_lib => jcli-lib/src}/certificate/weighted_pool_ids.rs | 0 {jcli/src/jcli_lib => jcli-lib/src}/debug/block.rs | 0 {jcli/src/jcli_lib => jcli-lib/src}/debug/message.rs | 0 {jcli/src/jcli_lib => jcli-lib/src}/debug/mod.rs | 0 {jcli/src/jcli_lib => jcli-lib/src}/key.rs | 0 {jcli/src/jcli_lib => jcli-lib/src}/mod.rs | 0 {jcli/src/jcli_lib => jcli-lib/src}/rest/config.rs | 0 {jcli/src/jcli_lib => jcli-lib/src}/rest/mod.rs | 0 {jcli/src/jcli_lib => jcli-lib/src}/rest/v0/account/mod.rs | 0 {jcli/src/jcli_lib => jcli-lib/src}/rest/v0/block/mod.rs | 0 {jcli/src/jcli_lib => jcli-lib/src}/rest/v0/block/next_id.rs | 0 {jcli/src/jcli_lib => jcli-lib/src}/rest/v0/block/subcommand.rs | 0 {jcli/src/jcli_lib => jcli-lib/src}/rest/v0/diagnostic/mod.rs | 0 {jcli/src/jcli_lib => jcli-lib/src}/rest/v0/leaders/mod.rs | 0 {jcli/src/jcli_lib => jcli-lib/src}/rest/v0/message/mod.rs | 0 {jcli/src/jcli_lib => jcli-lib/src}/rest/v0/mod.rs | 0 {jcli/src/jcli_lib => jcli-lib/src}/rest/v0/network/mod.rs | 0 {jcli/src/jcli_lib => jcli-lib/src}/rest/v0/network/stats.rs | 0 {jcli/src/jcli_lib => jcli-lib/src}/rest/v0/node/mod.rs | 0 {jcli/src/jcli_lib => jcli-lib/src}/rest/v0/node/stats.rs | 0 {jcli/src/jcli_lib => jcli-lib/src}/rest/v0/rewards/epoch.rs | 0 {jcli/src/jcli_lib => jcli-lib/src}/rest/v0/rewards/history.rs | 0 {jcli/src/jcli_lib => jcli-lib/src}/rest/v0/rewards/mod.rs | 0 {jcli/src/jcli_lib => jcli-lib/src}/rest/v0/settings/mod.rs | 0 {jcli/src/jcli_lib => jcli-lib/src}/rest/v0/shutdown/mod.rs | 0 {jcli/src/jcli_lib => jcli-lib/src}/rest/v0/stake/mod.rs | 0 {jcli/src/jcli_lib => jcli-lib/src}/rest/v0/stake_pool/mod.rs | 0 {jcli/src/jcli_lib => jcli-lib/src}/rest/v0/stake_pools/mod.rs | 0 {jcli/src/jcli_lib => jcli-lib/src}/rest/v0/tip/mod.rs | 0 {jcli/src/jcli_lib => jcli-lib/src}/rest/v0/utxo/mod.rs | 0 {jcli/src/jcli_lib => jcli-lib/src}/rest/v0/vote/active.rs | 0 {jcli/src/jcli_lib => jcli-lib/src}/rest/v0/vote/committees.rs | 0 {jcli/src/jcli_lib => jcli-lib/src}/rest/v0/vote/mod.rs | 0 {jcli/src/jcli_lib => jcli-lib/src}/rest/v0/vote/plans.rs | 0 {jcli/src/jcli_lib => jcli-lib/src}/transaction/add_account.rs | 0 .../src/jcli_lib => jcli-lib/src}/transaction/add_certificate.rs | 0 {jcli/src/jcli_lib => jcli-lib/src}/transaction/add_input.rs | 0 {jcli/src/jcli_lib => jcli-lib/src}/transaction/add_output.rs | 0 {jcli/src/jcli_lib => jcli-lib/src}/transaction/add_witness.rs | 0 {jcli/src/jcli_lib => jcli-lib/src}/transaction/auth.rs | 0 {jcli/src/jcli_lib => jcli-lib/src}/transaction/common.rs | 0 {jcli/src/jcli_lib => jcli-lib/src}/transaction/finalize.rs | 0 {jcli/src/jcli_lib => jcli-lib/src}/transaction/info.rs | 0 {jcli/src/jcli_lib => jcli-lib/src}/transaction/mk_witness.rs | 0 {jcli/src/jcli_lib => jcli-lib/src}/transaction/mod.rs | 0 {jcli/src/jcli_lib => jcli-lib/src}/transaction/new.rs | 0 {jcli/src/jcli_lib => jcli-lib/src}/transaction/seal.rs | 0 {jcli/src/jcli_lib => jcli-lib/src}/transaction/staging.rs | 0 {jcli/src/jcli_lib => jcli-lib/src}/utils/account_id.rs | 0 {jcli/src/jcli_lib => jcli-lib/src}/utils/io.rs | 0 {jcli/src/jcli_lib => jcli-lib/src}/utils/key_parser.rs | 0 {jcli/src/jcli_lib => jcli-lib/src}/utils/mod.rs | 0 {jcli/src/jcli_lib => jcli-lib/src}/utils/output_file.rs | 0 {jcli/src/jcli_lib => jcli-lib/src}/utils/output_format.rs | 0 {jcli/src/jcli_lib => jcli-lib/src}/utils/vote.rs | 0 {jcli/src/jcli_lib => jcli-lib/src}/vote/bech32_constants.rs | 0 .../jcli_lib => jcli-lib/src}/vote/committee/communication_key.rs | 0 {jcli/src/jcli_lib => jcli-lib/src}/vote/committee/member_key.rs | 0 {jcli/src/jcli_lib => jcli-lib/src}/vote/committee/mod.rs | 0 .../src/jcli_lib => jcli-lib/src}/vote/common_reference_string.rs | 0 {jcli/src/jcli_lib => jcli-lib/src}/vote/encrypting_vote_key.rs | 0 {jcli/src/jcli_lib => jcli-lib/src}/vote/mod.rs | 0 {jcli/src/jcli_lib => jcli-lib/src}/vote/tally/decrypt_shares.rs | 0 .../src/jcli_lib => jcli-lib/src}/vote/tally/decryption_tally.rs | 0 {jcli/src/jcli_lib => jcli-lib/src}/vote/tally/mod.rs | 0 81 files changed, 0 insertions(+), 0 deletions(-) rename {jcli/src/jcli_lib => jcli-lib/src}/address.rs (100%) rename {jcli/src/jcli_lib => jcli-lib/src}/auto_completion.rs (100%) rename {jcli/src/jcli_lib => jcli-lib/src}/block/mod.rs (100%) rename {jcli/src/jcli_lib => jcli-lib/src}/certificate/mod.rs (100%) rename {jcli/src/jcli_lib => jcli-lib/src}/certificate/new_encrypted_vote_tally.rs (100%) rename {jcli/src/jcli_lib => jcli-lib/src}/certificate/new_owner_stake_delegation.rs (100%) rename {jcli/src/jcli_lib => jcli-lib/src}/certificate/new_stake_delegation.rs (100%) rename {jcli/src/jcli_lib => jcli-lib/src}/certificate/new_stake_pool_registration.rs (100%) rename {jcli/src/jcli_lib => jcli-lib/src}/certificate/new_stake_pool_retirement.rs (100%) rename {jcli/src/jcli_lib => jcli-lib/src}/certificate/new_vote_cast.rs (100%) rename {jcli/src/jcli_lib => jcli-lib/src}/certificate/new_vote_plan.rs (100%) rename {jcli/src/jcli_lib => jcli-lib/src}/certificate/new_vote_tally.rs (100%) rename {jcli/src/jcli_lib => jcli-lib/src}/certificate/show.rs (100%) rename {jcli/src/jcli_lib => jcli-lib/src}/certificate/show/stake_pool_id.rs (100%) rename {jcli/src/jcli_lib => jcli-lib/src}/certificate/show/vote_plan_id.rs (100%) rename {jcli/src/jcli_lib => jcli-lib/src}/certificate/sign.rs (100%) rename {jcli/src/jcli_lib => jcli-lib/src}/certificate/weighted_pool_ids.rs (100%) rename {jcli/src/jcli_lib => jcli-lib/src}/debug/block.rs (100%) rename {jcli/src/jcli_lib => jcli-lib/src}/debug/message.rs (100%) rename {jcli/src/jcli_lib => jcli-lib/src}/debug/mod.rs (100%) rename {jcli/src/jcli_lib => jcli-lib/src}/key.rs (100%) rename {jcli/src/jcli_lib => jcli-lib/src}/mod.rs (100%) rename {jcli/src/jcli_lib => jcli-lib/src}/rest/config.rs (100%) rename {jcli/src/jcli_lib => jcli-lib/src}/rest/mod.rs (100%) rename {jcli/src/jcli_lib => jcli-lib/src}/rest/v0/account/mod.rs (100%) rename {jcli/src/jcli_lib => jcli-lib/src}/rest/v0/block/mod.rs (100%) rename {jcli/src/jcli_lib => jcli-lib/src}/rest/v0/block/next_id.rs (100%) rename {jcli/src/jcli_lib => jcli-lib/src}/rest/v0/block/subcommand.rs (100%) rename {jcli/src/jcli_lib => jcli-lib/src}/rest/v0/diagnostic/mod.rs (100%) rename {jcli/src/jcli_lib => jcli-lib/src}/rest/v0/leaders/mod.rs (100%) rename {jcli/src/jcli_lib => jcli-lib/src}/rest/v0/message/mod.rs (100%) rename {jcli/src/jcli_lib => jcli-lib/src}/rest/v0/mod.rs (100%) rename {jcli/src/jcli_lib => jcli-lib/src}/rest/v0/network/mod.rs (100%) rename {jcli/src/jcli_lib => jcli-lib/src}/rest/v0/network/stats.rs (100%) rename {jcli/src/jcli_lib => jcli-lib/src}/rest/v0/node/mod.rs (100%) rename {jcli/src/jcli_lib => jcli-lib/src}/rest/v0/node/stats.rs (100%) rename {jcli/src/jcli_lib => jcli-lib/src}/rest/v0/rewards/epoch.rs (100%) rename {jcli/src/jcli_lib => jcli-lib/src}/rest/v0/rewards/history.rs (100%) rename {jcli/src/jcli_lib => jcli-lib/src}/rest/v0/rewards/mod.rs (100%) rename {jcli/src/jcli_lib => jcli-lib/src}/rest/v0/settings/mod.rs (100%) rename {jcli/src/jcli_lib => jcli-lib/src}/rest/v0/shutdown/mod.rs (100%) rename {jcli/src/jcli_lib => jcli-lib/src}/rest/v0/stake/mod.rs (100%) rename {jcli/src/jcli_lib => jcli-lib/src}/rest/v0/stake_pool/mod.rs (100%) rename {jcli/src/jcli_lib => jcli-lib/src}/rest/v0/stake_pools/mod.rs (100%) rename {jcli/src/jcli_lib => jcli-lib/src}/rest/v0/tip/mod.rs (100%) rename {jcli/src/jcli_lib => jcli-lib/src}/rest/v0/utxo/mod.rs (100%) rename {jcli/src/jcli_lib => jcli-lib/src}/rest/v0/vote/active.rs (100%) rename {jcli/src/jcli_lib => jcli-lib/src}/rest/v0/vote/committees.rs (100%) rename {jcli/src/jcli_lib => jcli-lib/src}/rest/v0/vote/mod.rs (100%) rename {jcli/src/jcli_lib => jcli-lib/src}/rest/v0/vote/plans.rs (100%) rename {jcli/src/jcli_lib => jcli-lib/src}/transaction/add_account.rs (100%) rename {jcli/src/jcli_lib => jcli-lib/src}/transaction/add_certificate.rs (100%) rename {jcli/src/jcli_lib => jcli-lib/src}/transaction/add_input.rs (100%) rename {jcli/src/jcli_lib => jcli-lib/src}/transaction/add_output.rs (100%) rename {jcli/src/jcli_lib => jcli-lib/src}/transaction/add_witness.rs (100%) rename {jcli/src/jcli_lib => jcli-lib/src}/transaction/auth.rs (100%) rename {jcli/src/jcli_lib => jcli-lib/src}/transaction/common.rs (100%) rename {jcli/src/jcli_lib => jcli-lib/src}/transaction/finalize.rs (100%) rename {jcli/src/jcli_lib => jcli-lib/src}/transaction/info.rs (100%) rename {jcli/src/jcli_lib => jcli-lib/src}/transaction/mk_witness.rs (100%) rename {jcli/src/jcli_lib => jcli-lib/src}/transaction/mod.rs (100%) rename {jcli/src/jcli_lib => jcli-lib/src}/transaction/new.rs (100%) rename {jcli/src/jcli_lib => jcli-lib/src}/transaction/seal.rs (100%) rename {jcli/src/jcli_lib => jcli-lib/src}/transaction/staging.rs (100%) rename {jcli/src/jcli_lib => jcli-lib/src}/utils/account_id.rs (100%) rename {jcli/src/jcli_lib => jcli-lib/src}/utils/io.rs (100%) rename {jcli/src/jcli_lib => jcli-lib/src}/utils/key_parser.rs (100%) rename {jcli/src/jcli_lib => jcli-lib/src}/utils/mod.rs (100%) rename {jcli/src/jcli_lib => jcli-lib/src}/utils/output_file.rs (100%) rename {jcli/src/jcli_lib => jcli-lib/src}/utils/output_format.rs (100%) rename {jcli/src/jcli_lib => jcli-lib/src}/utils/vote.rs (100%) rename {jcli/src/jcli_lib => jcli-lib/src}/vote/bech32_constants.rs (100%) rename {jcli/src/jcli_lib => jcli-lib/src}/vote/committee/communication_key.rs (100%) rename {jcli/src/jcli_lib => jcli-lib/src}/vote/committee/member_key.rs (100%) rename {jcli/src/jcli_lib => jcli-lib/src}/vote/committee/mod.rs (100%) rename {jcli/src/jcli_lib => jcli-lib/src}/vote/common_reference_string.rs (100%) rename {jcli/src/jcli_lib => jcli-lib/src}/vote/encrypting_vote_key.rs (100%) rename {jcli/src/jcli_lib => jcli-lib/src}/vote/mod.rs (100%) rename {jcli/src/jcli_lib => jcli-lib/src}/vote/tally/decrypt_shares.rs (100%) rename {jcli/src/jcli_lib => jcli-lib/src}/vote/tally/decryption_tally.rs (100%) rename {jcli/src/jcli_lib => jcli-lib/src}/vote/tally/mod.rs (100%) diff --git a/jcli/src/jcli_lib/address.rs b/jcli-lib/src/address.rs similarity index 100% rename from jcli/src/jcli_lib/address.rs rename to jcli-lib/src/address.rs diff --git a/jcli/src/jcli_lib/auto_completion.rs b/jcli-lib/src/auto_completion.rs similarity index 100% rename from jcli/src/jcli_lib/auto_completion.rs rename to jcli-lib/src/auto_completion.rs diff --git a/jcli/src/jcli_lib/block/mod.rs b/jcli-lib/src/block/mod.rs similarity index 100% rename from jcli/src/jcli_lib/block/mod.rs rename to jcli-lib/src/block/mod.rs diff --git a/jcli/src/jcli_lib/certificate/mod.rs b/jcli-lib/src/certificate/mod.rs similarity index 100% rename from jcli/src/jcli_lib/certificate/mod.rs rename to jcli-lib/src/certificate/mod.rs diff --git a/jcli/src/jcli_lib/certificate/new_encrypted_vote_tally.rs b/jcli-lib/src/certificate/new_encrypted_vote_tally.rs similarity index 100% rename from jcli/src/jcli_lib/certificate/new_encrypted_vote_tally.rs rename to jcli-lib/src/certificate/new_encrypted_vote_tally.rs diff --git a/jcli/src/jcli_lib/certificate/new_owner_stake_delegation.rs b/jcli-lib/src/certificate/new_owner_stake_delegation.rs similarity index 100% rename from jcli/src/jcli_lib/certificate/new_owner_stake_delegation.rs rename to jcli-lib/src/certificate/new_owner_stake_delegation.rs diff --git a/jcli/src/jcli_lib/certificate/new_stake_delegation.rs b/jcli-lib/src/certificate/new_stake_delegation.rs similarity index 100% rename from jcli/src/jcli_lib/certificate/new_stake_delegation.rs rename to jcli-lib/src/certificate/new_stake_delegation.rs diff --git a/jcli/src/jcli_lib/certificate/new_stake_pool_registration.rs b/jcli-lib/src/certificate/new_stake_pool_registration.rs similarity index 100% rename from jcli/src/jcli_lib/certificate/new_stake_pool_registration.rs rename to jcli-lib/src/certificate/new_stake_pool_registration.rs diff --git a/jcli/src/jcli_lib/certificate/new_stake_pool_retirement.rs b/jcli-lib/src/certificate/new_stake_pool_retirement.rs similarity index 100% rename from jcli/src/jcli_lib/certificate/new_stake_pool_retirement.rs rename to jcli-lib/src/certificate/new_stake_pool_retirement.rs diff --git a/jcli/src/jcli_lib/certificate/new_vote_cast.rs b/jcli-lib/src/certificate/new_vote_cast.rs similarity index 100% rename from jcli/src/jcli_lib/certificate/new_vote_cast.rs rename to jcli-lib/src/certificate/new_vote_cast.rs diff --git a/jcli/src/jcli_lib/certificate/new_vote_plan.rs b/jcli-lib/src/certificate/new_vote_plan.rs similarity index 100% rename from jcli/src/jcli_lib/certificate/new_vote_plan.rs rename to jcli-lib/src/certificate/new_vote_plan.rs diff --git a/jcli/src/jcli_lib/certificate/new_vote_tally.rs b/jcli-lib/src/certificate/new_vote_tally.rs similarity index 100% rename from jcli/src/jcli_lib/certificate/new_vote_tally.rs rename to jcli-lib/src/certificate/new_vote_tally.rs diff --git a/jcli/src/jcli_lib/certificate/show.rs b/jcli-lib/src/certificate/show.rs similarity index 100% rename from jcli/src/jcli_lib/certificate/show.rs rename to jcli-lib/src/certificate/show.rs diff --git a/jcli/src/jcli_lib/certificate/show/stake_pool_id.rs b/jcli-lib/src/certificate/show/stake_pool_id.rs similarity index 100% rename from jcli/src/jcli_lib/certificate/show/stake_pool_id.rs rename to jcli-lib/src/certificate/show/stake_pool_id.rs diff --git a/jcli/src/jcli_lib/certificate/show/vote_plan_id.rs b/jcli-lib/src/certificate/show/vote_plan_id.rs similarity index 100% rename from jcli/src/jcli_lib/certificate/show/vote_plan_id.rs rename to jcli-lib/src/certificate/show/vote_plan_id.rs diff --git a/jcli/src/jcli_lib/certificate/sign.rs b/jcli-lib/src/certificate/sign.rs similarity index 100% rename from jcli/src/jcli_lib/certificate/sign.rs rename to jcli-lib/src/certificate/sign.rs diff --git a/jcli/src/jcli_lib/certificate/weighted_pool_ids.rs b/jcli-lib/src/certificate/weighted_pool_ids.rs similarity index 100% rename from jcli/src/jcli_lib/certificate/weighted_pool_ids.rs rename to jcli-lib/src/certificate/weighted_pool_ids.rs diff --git a/jcli/src/jcli_lib/debug/block.rs b/jcli-lib/src/debug/block.rs similarity index 100% rename from jcli/src/jcli_lib/debug/block.rs rename to jcli-lib/src/debug/block.rs diff --git a/jcli/src/jcli_lib/debug/message.rs b/jcli-lib/src/debug/message.rs similarity index 100% rename from jcli/src/jcli_lib/debug/message.rs rename to jcli-lib/src/debug/message.rs diff --git a/jcli/src/jcli_lib/debug/mod.rs b/jcli-lib/src/debug/mod.rs similarity index 100% rename from jcli/src/jcli_lib/debug/mod.rs rename to jcli-lib/src/debug/mod.rs diff --git a/jcli/src/jcli_lib/key.rs b/jcli-lib/src/key.rs similarity index 100% rename from jcli/src/jcli_lib/key.rs rename to jcli-lib/src/key.rs diff --git a/jcli/src/jcli_lib/mod.rs b/jcli-lib/src/mod.rs similarity index 100% rename from jcli/src/jcli_lib/mod.rs rename to jcli-lib/src/mod.rs diff --git a/jcli/src/jcli_lib/rest/config.rs b/jcli-lib/src/rest/config.rs similarity index 100% rename from jcli/src/jcli_lib/rest/config.rs rename to jcli-lib/src/rest/config.rs diff --git a/jcli/src/jcli_lib/rest/mod.rs b/jcli-lib/src/rest/mod.rs similarity index 100% rename from jcli/src/jcli_lib/rest/mod.rs rename to jcli-lib/src/rest/mod.rs diff --git a/jcli/src/jcli_lib/rest/v0/account/mod.rs b/jcli-lib/src/rest/v0/account/mod.rs similarity index 100% rename from jcli/src/jcli_lib/rest/v0/account/mod.rs rename to jcli-lib/src/rest/v0/account/mod.rs diff --git a/jcli/src/jcli_lib/rest/v0/block/mod.rs b/jcli-lib/src/rest/v0/block/mod.rs similarity index 100% rename from jcli/src/jcli_lib/rest/v0/block/mod.rs rename to jcli-lib/src/rest/v0/block/mod.rs diff --git a/jcli/src/jcli_lib/rest/v0/block/next_id.rs b/jcli-lib/src/rest/v0/block/next_id.rs similarity index 100% rename from jcli/src/jcli_lib/rest/v0/block/next_id.rs rename to jcli-lib/src/rest/v0/block/next_id.rs diff --git a/jcli/src/jcli_lib/rest/v0/block/subcommand.rs b/jcli-lib/src/rest/v0/block/subcommand.rs similarity index 100% rename from jcli/src/jcli_lib/rest/v0/block/subcommand.rs rename to jcli-lib/src/rest/v0/block/subcommand.rs diff --git a/jcli/src/jcli_lib/rest/v0/diagnostic/mod.rs b/jcli-lib/src/rest/v0/diagnostic/mod.rs similarity index 100% rename from jcli/src/jcli_lib/rest/v0/diagnostic/mod.rs rename to jcli-lib/src/rest/v0/diagnostic/mod.rs diff --git a/jcli/src/jcli_lib/rest/v0/leaders/mod.rs b/jcli-lib/src/rest/v0/leaders/mod.rs similarity index 100% rename from jcli/src/jcli_lib/rest/v0/leaders/mod.rs rename to jcli-lib/src/rest/v0/leaders/mod.rs diff --git a/jcli/src/jcli_lib/rest/v0/message/mod.rs b/jcli-lib/src/rest/v0/message/mod.rs similarity index 100% rename from jcli/src/jcli_lib/rest/v0/message/mod.rs rename to jcli-lib/src/rest/v0/message/mod.rs diff --git a/jcli/src/jcli_lib/rest/v0/mod.rs b/jcli-lib/src/rest/v0/mod.rs similarity index 100% rename from jcli/src/jcli_lib/rest/v0/mod.rs rename to jcli-lib/src/rest/v0/mod.rs diff --git a/jcli/src/jcli_lib/rest/v0/network/mod.rs b/jcli-lib/src/rest/v0/network/mod.rs similarity index 100% rename from jcli/src/jcli_lib/rest/v0/network/mod.rs rename to jcli-lib/src/rest/v0/network/mod.rs diff --git a/jcli/src/jcli_lib/rest/v0/network/stats.rs b/jcli-lib/src/rest/v0/network/stats.rs similarity index 100% rename from jcli/src/jcli_lib/rest/v0/network/stats.rs rename to jcli-lib/src/rest/v0/network/stats.rs diff --git a/jcli/src/jcli_lib/rest/v0/node/mod.rs b/jcli-lib/src/rest/v0/node/mod.rs similarity index 100% rename from jcli/src/jcli_lib/rest/v0/node/mod.rs rename to jcli-lib/src/rest/v0/node/mod.rs diff --git a/jcli/src/jcli_lib/rest/v0/node/stats.rs b/jcli-lib/src/rest/v0/node/stats.rs similarity index 100% rename from jcli/src/jcli_lib/rest/v0/node/stats.rs rename to jcli-lib/src/rest/v0/node/stats.rs diff --git a/jcli/src/jcli_lib/rest/v0/rewards/epoch.rs b/jcli-lib/src/rest/v0/rewards/epoch.rs similarity index 100% rename from jcli/src/jcli_lib/rest/v0/rewards/epoch.rs rename to jcli-lib/src/rest/v0/rewards/epoch.rs diff --git a/jcli/src/jcli_lib/rest/v0/rewards/history.rs b/jcli-lib/src/rest/v0/rewards/history.rs similarity index 100% rename from jcli/src/jcli_lib/rest/v0/rewards/history.rs rename to jcli-lib/src/rest/v0/rewards/history.rs diff --git a/jcli/src/jcli_lib/rest/v0/rewards/mod.rs b/jcli-lib/src/rest/v0/rewards/mod.rs similarity index 100% rename from jcli/src/jcli_lib/rest/v0/rewards/mod.rs rename to jcli-lib/src/rest/v0/rewards/mod.rs diff --git a/jcli/src/jcli_lib/rest/v0/settings/mod.rs b/jcli-lib/src/rest/v0/settings/mod.rs similarity index 100% rename from jcli/src/jcli_lib/rest/v0/settings/mod.rs rename to jcli-lib/src/rest/v0/settings/mod.rs diff --git a/jcli/src/jcli_lib/rest/v0/shutdown/mod.rs b/jcli-lib/src/rest/v0/shutdown/mod.rs similarity index 100% rename from jcli/src/jcli_lib/rest/v0/shutdown/mod.rs rename to jcli-lib/src/rest/v0/shutdown/mod.rs diff --git a/jcli/src/jcli_lib/rest/v0/stake/mod.rs b/jcli-lib/src/rest/v0/stake/mod.rs similarity index 100% rename from jcli/src/jcli_lib/rest/v0/stake/mod.rs rename to jcli-lib/src/rest/v0/stake/mod.rs diff --git a/jcli/src/jcli_lib/rest/v0/stake_pool/mod.rs b/jcli-lib/src/rest/v0/stake_pool/mod.rs similarity index 100% rename from jcli/src/jcli_lib/rest/v0/stake_pool/mod.rs rename to jcli-lib/src/rest/v0/stake_pool/mod.rs diff --git a/jcli/src/jcli_lib/rest/v0/stake_pools/mod.rs b/jcli-lib/src/rest/v0/stake_pools/mod.rs similarity index 100% rename from jcli/src/jcli_lib/rest/v0/stake_pools/mod.rs rename to jcli-lib/src/rest/v0/stake_pools/mod.rs diff --git a/jcli/src/jcli_lib/rest/v0/tip/mod.rs b/jcli-lib/src/rest/v0/tip/mod.rs similarity index 100% rename from jcli/src/jcli_lib/rest/v0/tip/mod.rs rename to jcli-lib/src/rest/v0/tip/mod.rs diff --git a/jcli/src/jcli_lib/rest/v0/utxo/mod.rs b/jcli-lib/src/rest/v0/utxo/mod.rs similarity index 100% rename from jcli/src/jcli_lib/rest/v0/utxo/mod.rs rename to jcli-lib/src/rest/v0/utxo/mod.rs diff --git a/jcli/src/jcli_lib/rest/v0/vote/active.rs b/jcli-lib/src/rest/v0/vote/active.rs similarity index 100% rename from jcli/src/jcli_lib/rest/v0/vote/active.rs rename to jcli-lib/src/rest/v0/vote/active.rs diff --git a/jcli/src/jcli_lib/rest/v0/vote/committees.rs b/jcli-lib/src/rest/v0/vote/committees.rs similarity index 100% rename from jcli/src/jcli_lib/rest/v0/vote/committees.rs rename to jcli-lib/src/rest/v0/vote/committees.rs diff --git a/jcli/src/jcli_lib/rest/v0/vote/mod.rs b/jcli-lib/src/rest/v0/vote/mod.rs similarity index 100% rename from jcli/src/jcli_lib/rest/v0/vote/mod.rs rename to jcli-lib/src/rest/v0/vote/mod.rs diff --git a/jcli/src/jcli_lib/rest/v0/vote/plans.rs b/jcli-lib/src/rest/v0/vote/plans.rs similarity index 100% rename from jcli/src/jcli_lib/rest/v0/vote/plans.rs rename to jcli-lib/src/rest/v0/vote/plans.rs diff --git a/jcli/src/jcli_lib/transaction/add_account.rs b/jcli-lib/src/transaction/add_account.rs similarity index 100% rename from jcli/src/jcli_lib/transaction/add_account.rs rename to jcli-lib/src/transaction/add_account.rs diff --git a/jcli/src/jcli_lib/transaction/add_certificate.rs b/jcli-lib/src/transaction/add_certificate.rs similarity index 100% rename from jcli/src/jcli_lib/transaction/add_certificate.rs rename to jcli-lib/src/transaction/add_certificate.rs diff --git a/jcli/src/jcli_lib/transaction/add_input.rs b/jcli-lib/src/transaction/add_input.rs similarity index 100% rename from jcli/src/jcli_lib/transaction/add_input.rs rename to jcli-lib/src/transaction/add_input.rs diff --git a/jcli/src/jcli_lib/transaction/add_output.rs b/jcli-lib/src/transaction/add_output.rs similarity index 100% rename from jcli/src/jcli_lib/transaction/add_output.rs rename to jcli-lib/src/transaction/add_output.rs diff --git a/jcli/src/jcli_lib/transaction/add_witness.rs b/jcli-lib/src/transaction/add_witness.rs similarity index 100% rename from jcli/src/jcli_lib/transaction/add_witness.rs rename to jcli-lib/src/transaction/add_witness.rs diff --git a/jcli/src/jcli_lib/transaction/auth.rs b/jcli-lib/src/transaction/auth.rs similarity index 100% rename from jcli/src/jcli_lib/transaction/auth.rs rename to jcli-lib/src/transaction/auth.rs diff --git a/jcli/src/jcli_lib/transaction/common.rs b/jcli-lib/src/transaction/common.rs similarity index 100% rename from jcli/src/jcli_lib/transaction/common.rs rename to jcli-lib/src/transaction/common.rs diff --git a/jcli/src/jcli_lib/transaction/finalize.rs b/jcli-lib/src/transaction/finalize.rs similarity index 100% rename from jcli/src/jcli_lib/transaction/finalize.rs rename to jcli-lib/src/transaction/finalize.rs diff --git a/jcli/src/jcli_lib/transaction/info.rs b/jcli-lib/src/transaction/info.rs similarity index 100% rename from jcli/src/jcli_lib/transaction/info.rs rename to jcli-lib/src/transaction/info.rs diff --git a/jcli/src/jcli_lib/transaction/mk_witness.rs b/jcli-lib/src/transaction/mk_witness.rs similarity index 100% rename from jcli/src/jcli_lib/transaction/mk_witness.rs rename to jcli-lib/src/transaction/mk_witness.rs diff --git a/jcli/src/jcli_lib/transaction/mod.rs b/jcli-lib/src/transaction/mod.rs similarity index 100% rename from jcli/src/jcli_lib/transaction/mod.rs rename to jcli-lib/src/transaction/mod.rs diff --git a/jcli/src/jcli_lib/transaction/new.rs b/jcli-lib/src/transaction/new.rs similarity index 100% rename from jcli/src/jcli_lib/transaction/new.rs rename to jcli-lib/src/transaction/new.rs diff --git a/jcli/src/jcli_lib/transaction/seal.rs b/jcli-lib/src/transaction/seal.rs similarity index 100% rename from jcli/src/jcli_lib/transaction/seal.rs rename to jcli-lib/src/transaction/seal.rs diff --git a/jcli/src/jcli_lib/transaction/staging.rs b/jcli-lib/src/transaction/staging.rs similarity index 100% rename from jcli/src/jcli_lib/transaction/staging.rs rename to jcli-lib/src/transaction/staging.rs diff --git a/jcli/src/jcli_lib/utils/account_id.rs b/jcli-lib/src/utils/account_id.rs similarity index 100% rename from jcli/src/jcli_lib/utils/account_id.rs rename to jcli-lib/src/utils/account_id.rs diff --git a/jcli/src/jcli_lib/utils/io.rs b/jcli-lib/src/utils/io.rs similarity index 100% rename from jcli/src/jcli_lib/utils/io.rs rename to jcli-lib/src/utils/io.rs diff --git a/jcli/src/jcli_lib/utils/key_parser.rs b/jcli-lib/src/utils/key_parser.rs similarity index 100% rename from jcli/src/jcli_lib/utils/key_parser.rs rename to jcli-lib/src/utils/key_parser.rs diff --git a/jcli/src/jcli_lib/utils/mod.rs b/jcli-lib/src/utils/mod.rs similarity index 100% rename from jcli/src/jcli_lib/utils/mod.rs rename to jcli-lib/src/utils/mod.rs diff --git a/jcli/src/jcli_lib/utils/output_file.rs b/jcli-lib/src/utils/output_file.rs similarity index 100% rename from jcli/src/jcli_lib/utils/output_file.rs rename to jcli-lib/src/utils/output_file.rs diff --git a/jcli/src/jcli_lib/utils/output_format.rs b/jcli-lib/src/utils/output_format.rs similarity index 100% rename from jcli/src/jcli_lib/utils/output_format.rs rename to jcli-lib/src/utils/output_format.rs diff --git a/jcli/src/jcli_lib/utils/vote.rs b/jcli-lib/src/utils/vote.rs similarity index 100% rename from jcli/src/jcli_lib/utils/vote.rs rename to jcli-lib/src/utils/vote.rs diff --git a/jcli/src/jcli_lib/vote/bech32_constants.rs b/jcli-lib/src/vote/bech32_constants.rs similarity index 100% rename from jcli/src/jcli_lib/vote/bech32_constants.rs rename to jcli-lib/src/vote/bech32_constants.rs diff --git a/jcli/src/jcli_lib/vote/committee/communication_key.rs b/jcli-lib/src/vote/committee/communication_key.rs similarity index 100% rename from jcli/src/jcli_lib/vote/committee/communication_key.rs rename to jcli-lib/src/vote/committee/communication_key.rs diff --git a/jcli/src/jcli_lib/vote/committee/member_key.rs b/jcli-lib/src/vote/committee/member_key.rs similarity index 100% rename from jcli/src/jcli_lib/vote/committee/member_key.rs rename to jcli-lib/src/vote/committee/member_key.rs diff --git a/jcli/src/jcli_lib/vote/committee/mod.rs b/jcli-lib/src/vote/committee/mod.rs similarity index 100% rename from jcli/src/jcli_lib/vote/committee/mod.rs rename to jcli-lib/src/vote/committee/mod.rs diff --git a/jcli/src/jcli_lib/vote/common_reference_string.rs b/jcli-lib/src/vote/common_reference_string.rs similarity index 100% rename from jcli/src/jcli_lib/vote/common_reference_string.rs rename to jcli-lib/src/vote/common_reference_string.rs diff --git a/jcli/src/jcli_lib/vote/encrypting_vote_key.rs b/jcli-lib/src/vote/encrypting_vote_key.rs similarity index 100% rename from jcli/src/jcli_lib/vote/encrypting_vote_key.rs rename to jcli-lib/src/vote/encrypting_vote_key.rs diff --git a/jcli/src/jcli_lib/vote/mod.rs b/jcli-lib/src/vote/mod.rs similarity index 100% rename from jcli/src/jcli_lib/vote/mod.rs rename to jcli-lib/src/vote/mod.rs diff --git a/jcli/src/jcli_lib/vote/tally/decrypt_shares.rs b/jcli-lib/src/vote/tally/decrypt_shares.rs similarity index 100% rename from jcli/src/jcli_lib/vote/tally/decrypt_shares.rs rename to jcli-lib/src/vote/tally/decrypt_shares.rs diff --git a/jcli/src/jcli_lib/vote/tally/decryption_tally.rs b/jcli-lib/src/vote/tally/decryption_tally.rs similarity index 100% rename from jcli/src/jcli_lib/vote/tally/decryption_tally.rs rename to jcli-lib/src/vote/tally/decryption_tally.rs diff --git a/jcli/src/jcli_lib/vote/tally/mod.rs b/jcli-lib/src/vote/tally/mod.rs similarity index 100% rename from jcli/src/jcli_lib/vote/tally/mod.rs rename to jcli-lib/src/vote/tally/mod.rs From e4457220b0a173e9e4d9ab18b7d908ed837f8ec5 Mon Sep 17 00:00:00 2001 From: Filip Dulic Date: Tue, 13 Apr 2021 15:00:12 -0500 Subject: [PATCH 04/25] refactor main library modules, transfer to new crate --- jcli-lib/src/lib.rs | 96 ++++++++++++++++++++++++++++++++++++++++++--- jcli-lib/src/mod.rs | 93 ------------------------------------------- jcli/src/lib.rs | 2 - 3 files changed, 91 insertions(+), 100 deletions(-) delete mode 100644 jcli-lib/src/mod.rs delete mode 100644 jcli/src/lib.rs diff --git a/jcli-lib/src/lib.rs b/jcli-lib/src/lib.rs index 31e1bb209f..625c1ca213 100644 --- a/jcli-lib/src/lib.rs +++ b/jcli-lib/src/lib.rs @@ -1,7 +1,93 @@ -#[cfg(test)] -mod tests { - #[test] - fn it_works() { - assert_eq!(2 + 2, 4); +pub mod address; +pub mod auto_completion; +pub mod block; +pub mod certificate; +pub mod debug; +pub mod key; +pub mod rest; +pub mod transaction; +pub mod vote; + +pub mod utils; + +use std::error::Error; +use structopt::StructOpt; + +/// Jormungandr CLI toolkit +#[derive(StructOpt)] +#[structopt(rename_all = "kebab-case")] +pub struct JCli { + /// display full version details (software version, source version, targets and compiler used) + #[structopt(long = "full-version")] + full_version: bool, + + /// display the sources version, allowing to check the source's hash used to compile this executable. + /// this option is useful for scripting retrieving the logs of the version of this application. + #[structopt(long = "source-version")] + source_version: bool, + + #[structopt(subcommand)] + command: Option, +} + +#[allow(clippy::large_enum_variant)] +/// Jormungandr CLI toolkit +#[derive(StructOpt)] +#[structopt(rename_all = "kebab-case")] +pub enum JCliCommand { + /// Key Generation + Key(key::Key), + /// Address tooling and helper + Address(address::Address), + /// Block tooling and helper + Genesis(block::Genesis), + /// Send request to node REST API + Rest(rest::Rest), + /// Build and view offline transaction + Transaction(transaction::Transaction), + /// Debug tools for developers + Debug(debug::Debug), + /// Certificate generation tool + Certificate(certificate::Certificate), + /// Auto completion + AutoCompletion(auto_completion::AutoCompletion), + /// Utilities that perform specialized tasks + Utils(utils::Utils), + /// Vote related operations + Votes(vote::Vote), +} + +impl JCli { + pub fn exec(self) -> Result<(), Box> { + use std::io::Write as _; + if self.full_version { + Ok(writeln!(std::io::stdout(), "{}", env!("FULL_VERSION"))?) + } else if self.source_version { + Ok(writeln!(std::io::stdout(), "{}", env!("SOURCE_VERSION"))?) + } else if let Some(cmd) = self.command { + cmd.exec() + } else { + writeln!(std::io::stderr(), "No command, try `--help'")?; + std::process::exit(1); + } + } +} + +impl JCliCommand { + pub fn exec(self) -> Result<(), Box> { + use self::JCliCommand::*; + match self { + Key(key) => key.exec()?, + Address(address) => address.exec()?, + Genesis(genesis) => genesis.exec()?, + Rest(rest) => rest.exec()?, + Transaction(transaction) => transaction.exec()?, + Debug(debug) => debug.exec()?, + Certificate(certificate) => certificate.exec()?, + AutoCompletion(auto_completion) => auto_completion.exec::()?, + Utils(utils) => utils.exec()?, + Votes(vote) => vote.exec()?, + }; + Ok(()) } } diff --git a/jcli-lib/src/mod.rs b/jcli-lib/src/mod.rs deleted file mode 100644 index 625c1ca213..0000000000 --- a/jcli-lib/src/mod.rs +++ /dev/null @@ -1,93 +0,0 @@ -pub mod address; -pub mod auto_completion; -pub mod block; -pub mod certificate; -pub mod debug; -pub mod key; -pub mod rest; -pub mod transaction; -pub mod vote; - -pub mod utils; - -use std::error::Error; -use structopt::StructOpt; - -/// Jormungandr CLI toolkit -#[derive(StructOpt)] -#[structopt(rename_all = "kebab-case")] -pub struct JCli { - /// display full version details (software version, source version, targets and compiler used) - #[structopt(long = "full-version")] - full_version: bool, - - /// display the sources version, allowing to check the source's hash used to compile this executable. - /// this option is useful for scripting retrieving the logs of the version of this application. - #[structopt(long = "source-version")] - source_version: bool, - - #[structopt(subcommand)] - command: Option, -} - -#[allow(clippy::large_enum_variant)] -/// Jormungandr CLI toolkit -#[derive(StructOpt)] -#[structopt(rename_all = "kebab-case")] -pub enum JCliCommand { - /// Key Generation - Key(key::Key), - /// Address tooling and helper - Address(address::Address), - /// Block tooling and helper - Genesis(block::Genesis), - /// Send request to node REST API - Rest(rest::Rest), - /// Build and view offline transaction - Transaction(transaction::Transaction), - /// Debug tools for developers - Debug(debug::Debug), - /// Certificate generation tool - Certificate(certificate::Certificate), - /// Auto completion - AutoCompletion(auto_completion::AutoCompletion), - /// Utilities that perform specialized tasks - Utils(utils::Utils), - /// Vote related operations - Votes(vote::Vote), -} - -impl JCli { - pub fn exec(self) -> Result<(), Box> { - use std::io::Write as _; - if self.full_version { - Ok(writeln!(std::io::stdout(), "{}", env!("FULL_VERSION"))?) - } else if self.source_version { - Ok(writeln!(std::io::stdout(), "{}", env!("SOURCE_VERSION"))?) - } else if let Some(cmd) = self.command { - cmd.exec() - } else { - writeln!(std::io::stderr(), "No command, try `--help'")?; - std::process::exit(1); - } - } -} - -impl JCliCommand { - pub fn exec(self) -> Result<(), Box> { - use self::JCliCommand::*; - match self { - Key(key) => key.exec()?, - Address(address) => address.exec()?, - Genesis(genesis) => genesis.exec()?, - Rest(rest) => rest.exec()?, - Transaction(transaction) => transaction.exec()?, - Debug(debug) => debug.exec()?, - Certificate(certificate) => certificate.exec()?, - AutoCompletion(auto_completion) => auto_completion.exec::()?, - Utils(utils) => utils.exec()?, - Votes(vote) => vote.exec()?, - }; - Ok(()) - } -} diff --git a/jcli/src/lib.rs b/jcli/src/lib.rs deleted file mode 100644 index a4f4456cae..0000000000 --- a/jcli/src/lib.rs +++ /dev/null @@ -1,2 +0,0 @@ -pub mod jcli_lib; -pub use crate::jcli_lib::*; From 07fbb0c148622a0b2945c17cd778cb793136689b Mon Sep 17 00:00:00 2001 From: Filip Dulic Date: Tue, 13 Apr 2021 15:01:05 -0500 Subject: [PATCH 05/25] set jcli-lib as a dependency of jcli --- Cargo.lock | 1 + jcli/Cargo.toml | 5 +---- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 28dde11af6..ebeec9aa1b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1928,6 +1928,7 @@ dependencies = [ "ed25519-bip32", "gtmpl", "hex", + "jcli-lib", "jormungandr-lib", "mime", "predicates", diff --git a/jcli/Cargo.toml b/jcli/Cargo.toml index eff6d714e1..a8dc0d8b5e 100644 --- a/jcli/Cargo.toml +++ b/jcli/Cargo.toml @@ -31,6 +31,7 @@ chain-addr = { git = "https://github.com/input-output-hk/chain-libs.git", b chain-crypto = { git = "https://github.com/input-output-hk/chain-libs.git", branch = "master" } chain-time = { git = "https://github.com/input-output-hk/chain-libs.git", branch = "master" } chain-vote = { git = "https://github.com/input-output-hk/chain-libs.git", branch = "master", features = ["p256k1"] } +jcli-lib = { path = "../jcli-lib" } jormungandr-lib = { path = "../jormungandr-lib" } gtmpl = "0.6.0" valico = "3.5.0" @@ -55,10 +56,6 @@ predicates = "1.0" [build-dependencies] versionisator = "1.0.2" -[lib] -name = "jcli_lib" -path = "src/lib.rs" - [[bin]] name = "jcli" path = "src/main.rs" From 502f4731c45c9fed93066e7cc94907b5ed8b51a7 Mon Sep 17 00:00:00 2001 From: Filip Dulic Date: Tue, 13 Apr 2021 15:10:32 -0500 Subject: [PATCH 06/25] correct imports in new jcli-lib --- jcli-lib/src/address.rs | 2 +- jcli-lib/src/block/mod.rs | 2 +- jcli-lib/src/certificate/mod.rs | 2 +- jcli-lib/src/certificate/new_encrypted_vote_tally.rs | 2 +- .../src/certificate/new_owner_stake_delegation.rs | 2 +- jcli-lib/src/certificate/new_stake_delegation.rs | 2 +- .../src/certificate/new_stake_pool_registration.rs | 2 +- .../src/certificate/new_stake_pool_retirement.rs | 2 +- jcli-lib/src/certificate/new_vote_cast.rs | 9 ++++----- jcli-lib/src/certificate/new_vote_plan.rs | 2 +- jcli-lib/src/certificate/new_vote_tally.rs | 4 ++-- jcli-lib/src/certificate/show.rs | 2 +- jcli-lib/src/certificate/show/stake_pool_id.rs | 2 +- jcli-lib/src/certificate/show/vote_plan_id.rs | 2 +- jcli-lib/src/certificate/sign.rs | 2 +- jcli-lib/src/certificate/weighted_pool_ids.rs | 2 +- jcli-lib/src/debug/block.rs | 2 +- jcli-lib/src/debug/message.rs | 2 +- jcli-lib/src/key.rs | 4 ++-- jcli-lib/src/rest/mod.rs | 2 +- jcli-lib/src/rest/v0/account/mod.rs | 4 ++-- jcli-lib/src/rest/v0/block/mod.rs | 2 +- jcli-lib/src/rest/v0/block/next_id.rs | 2 +- jcli-lib/src/rest/v0/block/subcommand.rs | 2 +- jcli-lib/src/rest/v0/diagnostic/mod.rs | 2 +- jcli-lib/src/rest/v0/leaders/mod.rs | 4 ++-- jcli-lib/src/rest/v0/message/mod.rs | 2 +- jcli-lib/src/rest/v0/mod.rs | 2 +- jcli-lib/src/rest/v0/network/mod.rs | 2 +- jcli-lib/src/rest/v0/network/stats.rs | 4 ++-- jcli-lib/src/rest/v0/node/mod.rs | 2 +- jcli-lib/src/rest/v0/node/stats.rs | 4 ++-- jcli-lib/src/rest/v0/rewards/epoch.rs | 2 +- jcli-lib/src/rest/v0/rewards/history.rs | 2 +- jcli-lib/src/rest/v0/rewards/mod.rs | 2 +- jcli-lib/src/rest/v0/settings/mod.rs | 4 ++-- jcli-lib/src/rest/v0/shutdown/mod.rs | 2 +- jcli-lib/src/rest/v0/stake/mod.rs | 4 ++-- jcli-lib/src/rest/v0/stake_pool/mod.rs | 4 ++-- jcli-lib/src/rest/v0/stake_pools/mod.rs | 4 ++-- jcli-lib/src/rest/v0/tip/mod.rs | 2 +- jcli-lib/src/rest/v0/utxo/mod.rs | 4 ++-- jcli-lib/src/rest/v0/vote/active.rs | 2 +- jcli-lib/src/rest/v0/vote/committees.rs | 4 ++-- jcli-lib/src/rest/v0/vote/mod.rs | 2 +- jcli-lib/src/rest/v0/vote/plans.rs | 4 ++-- jcli-lib/src/transaction/add_account.rs | 2 +- jcli-lib/src/transaction/add_certificate.rs | 2 +- jcli-lib/src/transaction/add_input.rs | 4 ++-- jcli-lib/src/transaction/add_output.rs | 2 +- jcli-lib/src/transaction/add_witness.rs | 2 +- jcli-lib/src/transaction/auth.rs | 2 +- jcli-lib/src/transaction/common.rs | 2 +- jcli-lib/src/transaction/finalize.rs | 2 +- jcli-lib/src/transaction/info.rs | 2 +- jcli-lib/src/transaction/mk_witness.rs | 2 +- jcli-lib/src/transaction/mod.rs | 2 +- jcli-lib/src/transaction/new.rs | 2 +- jcli-lib/src/transaction/seal.rs | 2 +- jcli-lib/src/transaction/staging.rs | 4 ++-- jcli-lib/src/utils/output_file.rs | 2 +- jcli-lib/src/utils/vote.rs | 2 +- jcli-lib/src/vote/committee/communication_key.rs | 10 +++++----- jcli-lib/src/vote/committee/member_key.rs | 12 ++++++------ jcli-lib/src/vote/encrypting_vote_key.rs | 6 +++--- jcli-lib/src/vote/mod.rs | 6 +++--- jcli-lib/src/vote/tally/decrypt_shares.rs | 4 ++-- jcli-lib/src/vote/tally/decryption_tally.rs | 6 +++--- 68 files changed, 102 insertions(+), 103 deletions(-) diff --git a/jcli-lib/src/address.rs b/jcli-lib/src/address.rs index cf4c00e259..b19fde4c8f 100644 --- a/jcli-lib/src/address.rs +++ b/jcli-lib/src/address.rs @@ -1,4 +1,4 @@ -use crate::jcli_lib::utils::key_parser::parse_pub_key; +use crate::utils::key_parser::parse_pub_key; use chain_addr::{AddressReadable, Discrimination, Kind}; use chain_crypto::{bech32::Bech32 as _, AsymmetricPublicKey, Ed25519, PublicKey}; use structopt::StructOpt; diff --git a/jcli-lib/src/block/mod.rs b/jcli-lib/src/block/mod.rs index 0e0efa0227..890caba1bd 100644 --- a/jcli-lib/src/block/mod.rs +++ b/jcli-lib/src/block/mod.rs @@ -1,4 +1,4 @@ -use crate::jcli_lib::utils::io; +use crate::utils::io; use chain_core::property::{Block as _, Deserialize, Serialize}; use chain_impl_mockchain::{ block::Block, diff --git a/jcli-lib/src/certificate/mod.rs b/jcli-lib/src/certificate/mod.rs index 45fa7b2a51..00bd1118f7 100644 --- a/jcli-lib/src/certificate/mod.rs +++ b/jcli-lib/src/certificate/mod.rs @@ -15,7 +15,7 @@ pub(crate) use self::sign::{ pool_owner_sign, stake_delegation_account_binding_sign, }; -use crate::jcli_lib::utils::{ +use crate::utils::{ io, key_parser, vote::{SharesError, VotePlanError}, }; diff --git a/jcli-lib/src/certificate/new_encrypted_vote_tally.rs b/jcli-lib/src/certificate/new_encrypted_vote_tally.rs index 937fe3836b..e34afef3a9 100644 --- a/jcli-lib/src/certificate/new_encrypted_vote_tally.rs +++ b/jcli-lib/src/certificate/new_encrypted_vote_tally.rs @@ -1,4 +1,4 @@ -use crate::jcli_lib::certificate::{write_cert, Error}; +use crate::certificate::{write_cert, Error}; use chain_impl_mockchain::certificate; use chain_impl_mockchain::certificate::{Certificate, VotePlanId}; use std::path::PathBuf; diff --git a/jcli-lib/src/certificate/new_owner_stake_delegation.rs b/jcli-lib/src/certificate/new_owner_stake_delegation.rs index 27bcc6ed8e..f5977859f3 100644 --- a/jcli-lib/src/certificate/new_owner_stake_delegation.rs +++ b/jcli-lib/src/certificate/new_owner_stake_delegation.rs @@ -1,4 +1,4 @@ -use crate::jcli_lib::certificate::{weighted_pool_ids::WeightedPoolIds, write_cert, Error}; +use crate::certificate::{weighted_pool_ids::WeightedPoolIds, write_cert, Error}; use chain_impl_mockchain::certificate::{Certificate, OwnerStakeDelegation as Delegation}; use jormungandr_lib::interfaces::Certificate as CertificateType; use std::{convert::TryInto, path::PathBuf}; diff --git a/jcli-lib/src/certificate/new_stake_delegation.rs b/jcli-lib/src/certificate/new_stake_delegation.rs index 13e85717e8..d58aed1d79 100644 --- a/jcli-lib/src/certificate/new_stake_delegation.rs +++ b/jcli-lib/src/certificate/new_stake_delegation.rs @@ -1,4 +1,4 @@ -use crate::jcli_lib::{ +use crate::{ certificate::{weighted_pool_ids::WeightedPoolIds, write_cert, Error}, utils::key_parser::parse_pub_key, }; diff --git a/jcli-lib/src/certificate/new_stake_pool_registration.rs b/jcli-lib/src/certificate/new_stake_pool_registration.rs index 6d31d3fdc6..e06f4470f7 100644 --- a/jcli-lib/src/certificate/new_stake_pool_registration.rs +++ b/jcli-lib/src/certificate/new_stake_pool_registration.rs @@ -1,4 +1,4 @@ -use crate::jcli_lib::{ +use crate::{ certificate::{write_cert, Error}, utils::key_parser::parse_pub_key, }; diff --git a/jcli-lib/src/certificate/new_stake_pool_retirement.rs b/jcli-lib/src/certificate/new_stake_pool_retirement.rs index dd0c0f9dd5..4a16dd04cf 100644 --- a/jcli-lib/src/certificate/new_stake_pool_retirement.rs +++ b/jcli-lib/src/certificate/new_stake_pool_retirement.rs @@ -1,4 +1,4 @@ -use crate::jcli_lib::certificate::{write_cert, Error}; +use crate::certificate::{write_cert, Error}; use chain_crypto::Blake2b256; use chain_impl_mockchain::certificate::{Certificate, PoolRetirement}; use chain_time::DurationSeconds; diff --git a/jcli-lib/src/certificate/new_vote_cast.rs b/jcli-lib/src/certificate/new_vote_cast.rs index 6a3c1286d1..61b4022979 100644 --- a/jcli-lib/src/certificate/new_vote_cast.rs +++ b/jcli-lib/src/certificate/new_vote_cast.rs @@ -1,5 +1,5 @@ -use crate::jcli_lib::certificate::{write_cert, Error}; -use crate::jcli_lib::utils; +use crate::certificate::{write_cert, Error}; +use crate::utils; use bech32::FromBase32; use chain_impl_mockchain::{ certificate::{Certificate, VoteCast, VotePlanId}, @@ -79,10 +79,9 @@ impl PrivateVoteCast { let mut rng = rand_chacha::ChaChaRng::from_entropy(); let key_line = utils::io::read_line(&self.encrypting_key_path)?; let (hrp, data) = bech32::decode(&key_line).map_err(Error::InvalidBech32)?; - if hrp != crate::jcli_lib::vote::bech32_constants::ENCRYPTING_VOTE_PK_HRP { + if hrp != crate::vote::bech32_constants::ENCRYPTING_VOTE_PK_HRP { return Err(Error::InvalidBech32Key { - expected: crate::jcli_lib::vote::bech32_constants::ENCRYPTING_VOTE_PK_HRP - .to_string(), + expected: crate::vote::bech32_constants::ENCRYPTING_VOTE_PK_HRP.to_string(), actual: hrp, }); } diff --git a/jcli-lib/src/certificate/new_vote_plan.rs b/jcli-lib/src/certificate/new_vote_plan.rs index f58bd6511c..e3e7373c9c 100644 --- a/jcli-lib/src/certificate/new_vote_plan.rs +++ b/jcli-lib/src/certificate/new_vote_plan.rs @@ -1,4 +1,4 @@ -use crate::jcli_lib::{ +use crate::{ certificate::{write_cert, Error}, utils::io, }; diff --git a/jcli-lib/src/certificate/new_vote_tally.rs b/jcli-lib/src/certificate/new_vote_tally.rs index eee668f9be..b6a1f900fd 100644 --- a/jcli-lib/src/certificate/new_vote_tally.rs +++ b/jcli-lib/src/certificate/new_vote_tally.rs @@ -1,5 +1,5 @@ -use crate::jcli_lib::certificate::{write_cert, Error}; -use crate::jcli_lib::utils::vote; +use crate::certificate::{write_cert, Error}; +use crate::utils::vote; use chain_impl_mockchain::certificate::{ Certificate, DecryptedPrivateTally, DecryptedPrivateTallyProposal, VotePlanId, VoteTally, }; diff --git a/jcli-lib/src/certificate/show.rs b/jcli-lib/src/certificate/show.rs index 6040889d08..6f8dcadb35 100644 --- a/jcli-lib/src/certificate/show.rs +++ b/jcli-lib/src/certificate/show.rs @@ -1,7 +1,7 @@ mod stake_pool_id; mod vote_plan_id; -use crate::jcli_lib::certificate::Error; +use crate::certificate::Error; use structopt::StructOpt; #[derive(StructOpt)] diff --git a/jcli-lib/src/certificate/show/stake_pool_id.rs b/jcli-lib/src/certificate/show/stake_pool_id.rs index 0532926108..5aa196c3f3 100644 --- a/jcli-lib/src/certificate/show/stake_pool_id.rs +++ b/jcli-lib/src/certificate/show/stake_pool_id.rs @@ -1,4 +1,4 @@ -use crate::jcli_lib::certificate::{read_cert_or_signed_cert, write_output, Error}; +use crate::certificate::{read_cert_or_signed_cert, write_output, Error}; use chain_impl_mockchain::certificate::Certificate; use jormungandr_lib::interfaces::Certificate as CertificateType; use std::path::PathBuf; diff --git a/jcli-lib/src/certificate/show/vote_plan_id.rs b/jcli-lib/src/certificate/show/vote_plan_id.rs index c489fe9626..99cd340a80 100644 --- a/jcli-lib/src/certificate/show/vote_plan_id.rs +++ b/jcli-lib/src/certificate/show/vote_plan_id.rs @@ -1,4 +1,4 @@ -use crate::jcli_lib::certificate::{read_cert_or_signed_cert, write_output, Error}; +use crate::certificate::{read_cert_or_signed_cert, write_output, Error}; use chain_impl_mockchain::certificate::Certificate; use jormungandr_lib::interfaces::Certificate as CertificateType; use std::path::PathBuf; diff --git a/jcli-lib/src/certificate/sign.rs b/jcli-lib/src/certificate/sign.rs index 122be994d1..543a0759ca 100644 --- a/jcli-lib/src/certificate/sign.rs +++ b/jcli-lib/src/certificate/sign.rs @@ -1,4 +1,4 @@ -use crate::jcli_lib::{ +use crate::{ certificate::{read_cert, read_input, write_signed_cert, Error}, utils::key_parser::{self, parse_ed25519_secret_key}, }; diff --git a/jcli-lib/src/certificate/weighted_pool_ids.rs b/jcli-lib/src/certificate/weighted_pool_ids.rs index 23839a6f8c..82f7cd7a9e 100644 --- a/jcli-lib/src/certificate/weighted_pool_ids.rs +++ b/jcli-lib/src/certificate/weighted_pool_ids.rs @@ -1,4 +1,4 @@ -use crate::jcli_lib::certificate::Error; +use crate::certificate::Error; use chain_crypto::Blake2b256; use chain_impl_mockchain::{ account::{DelegationRatio, DelegationType}, diff --git a/jcli-lib/src/debug/block.rs b/jcli-lib/src/debug/block.rs index 620d8c6480..12d840dd30 100644 --- a/jcli-lib/src/debug/block.rs +++ b/jcli-lib/src/debug/block.rs @@ -1,4 +1,4 @@ -use crate::jcli_lib::{debug::Error, utils::io}; +use crate::{debug::Error, utils::io}; use chain_core::property::Deserialize as _; use chain_impl_mockchain::block::Block as BlockMock; use std::io::{BufRead, BufReader}; diff --git a/jcli-lib/src/debug/message.rs b/jcli-lib/src/debug/message.rs index dd70a491b1..71271be988 100644 --- a/jcli-lib/src/debug/message.rs +++ b/jcli-lib/src/debug/message.rs @@ -1,4 +1,4 @@ -use crate::jcli_lib::{debug::Error, utils::io}; +use crate::{debug::Error, utils::io}; use chain_core::property::Deserialize as _; use chain_impl_mockchain::fragment::Fragment as MockFragment; use std::io::{BufRead, BufReader}; diff --git a/jcli-lib/src/key.rs b/jcli-lib/src/key.rs index 8235718f07..46f43ede35 100644 --- a/jcli-lib/src/key.rs +++ b/jcli-lib/src/key.rs @@ -1,5 +1,5 @@ -use crate::jcli_lib::utils::io; -use crate::jcli_lib::utils::output_file::{self, OutputFile}; +use crate::utils::io; +use crate::utils::output_file::{self, OutputFile}; use bech32::{self, u5, FromBase32, ToBase32}; use chain_crypto::{ bech32::Bech32 as _, AsymmetricKey, AsymmetricPublicKey, Curve25519_2HashDH, Ed25519, diff --git a/jcli-lib/src/rest/mod.rs b/jcli-lib/src/rest/mod.rs index 1bd2be1780..bd28b8f32d 100644 --- a/jcli-lib/src/rest/mod.rs +++ b/jcli-lib/src/rest/mod.rs @@ -1,7 +1,7 @@ mod config; mod v0; -use crate::jcli_lib::utils::{io::ReadYamlError, output_format}; +use crate::utils::{io::ReadYamlError, output_format}; use config::RestArgs; use hex::FromHexError; use structopt::StructOpt; diff --git a/jcli-lib/src/rest/v0/account/mod.rs b/jcli-lib/src/rest/v0/account/mod.rs index dd8e08e10d..f022a7b910 100644 --- a/jcli-lib/src/rest/v0/account/mod.rs +++ b/jcli-lib/src/rest/v0/account/mod.rs @@ -1,5 +1,5 @@ -use crate::jcli_lib::rest::{Error, RestArgs}; -use crate::jcli_lib::utils::{AccountId, OutputFormat}; +use crate::rest::{Error, RestArgs}; +use crate::utils::{AccountId, OutputFormat}; use structopt::StructOpt; #[derive(StructOpt)] diff --git a/jcli-lib/src/rest/v0/block/mod.rs b/jcli-lib/src/rest/v0/block/mod.rs index 6bc1761732..9cec98ef86 100644 --- a/jcli-lib/src/rest/v0/block/mod.rs +++ b/jcli-lib/src/rest/v0/block/mod.rs @@ -1,4 +1,4 @@ -use crate::jcli_lib::rest::Error; +use crate::rest::Error; use structopt::StructOpt; mod next_id; diff --git a/jcli-lib/src/rest/v0/block/next_id.rs b/jcli-lib/src/rest/v0/block/next_id.rs index 89c361d5a4..2ba08e48bd 100644 --- a/jcli-lib/src/rest/v0/block/next_id.rs +++ b/jcli-lib/src/rest/v0/block/next_id.rs @@ -1,4 +1,4 @@ -use crate::jcli_lib::rest::{Error, RestArgs}; +use crate::rest::{Error, RestArgs}; use chain_crypto::Blake2b256; use structopt::StructOpt; diff --git a/jcli-lib/src/rest/v0/block/subcommand.rs b/jcli-lib/src/rest/v0/block/subcommand.rs index 7bd189e616..9380363014 100644 --- a/jcli-lib/src/rest/v0/block/subcommand.rs +++ b/jcli-lib/src/rest/v0/block/subcommand.rs @@ -1,5 +1,5 @@ use super::next_id::NextId; -use crate::jcli_lib::rest::{Error, RestArgs}; +use crate::rest::{Error, RestArgs}; use structopt::StructOpt; #[derive(StructOpt)] diff --git a/jcli-lib/src/rest/v0/diagnostic/mod.rs b/jcli-lib/src/rest/v0/diagnostic/mod.rs index 74754a9f42..1d7c7f7891 100644 --- a/jcli-lib/src/rest/v0/diagnostic/mod.rs +++ b/jcli-lib/src/rest/v0/diagnostic/mod.rs @@ -1,4 +1,4 @@ -use crate::jcli_lib::rest::{Error, RestArgs}; +use crate::rest::{Error, RestArgs}; use structopt::StructOpt; #[derive(StructOpt)] diff --git a/jcli-lib/src/rest/v0/leaders/mod.rs b/jcli-lib/src/rest/v0/leaders/mod.rs index 8a4f17f153..e2dd9cdc94 100644 --- a/jcli-lib/src/rest/v0/leaders/mod.rs +++ b/jcli-lib/src/rest/v0/leaders/mod.rs @@ -1,5 +1,5 @@ -use crate::jcli_lib::rest::{Error, RestArgs}; -use crate::jcli_lib::utils::{io, OutputFormat}; +use crate::rest::{Error, RestArgs}; +use crate::utils::{io, OutputFormat}; use std::path::PathBuf; use structopt::StructOpt; diff --git a/jcli-lib/src/rest/v0/message/mod.rs b/jcli-lib/src/rest/v0/message/mod.rs index 18f0403148..63a699d873 100644 --- a/jcli-lib/src/rest/v0/message/mod.rs +++ b/jcli-lib/src/rest/v0/message/mod.rs @@ -1,4 +1,4 @@ -use crate::jcli_lib::{ +use crate::{ rest::{Error, RestArgs}, utils::{io, OutputFormat}, }; diff --git a/jcli-lib/src/rest/v0/mod.rs b/jcli-lib/src/rest/v0/mod.rs index f957a34d1c..8f20dd43ff 100644 --- a/jcli-lib/src/rest/v0/mod.rs +++ b/jcli-lib/src/rest/v0/mod.rs @@ -15,7 +15,7 @@ mod tip; mod utxo; mod vote; -use crate::jcli_lib::rest::Error; +use crate::rest::Error; use structopt::StructOpt; #[derive(StructOpt)] diff --git a/jcli-lib/src/rest/v0/network/mod.rs b/jcli-lib/src/rest/v0/network/mod.rs index a30483447c..108f55b976 100644 --- a/jcli-lib/src/rest/v0/network/mod.rs +++ b/jcli-lib/src/rest/v0/network/mod.rs @@ -1,7 +1,7 @@ mod stats; use self::stats::Stats; -use crate::jcli_lib::rest::Error; +use crate::rest::Error; use structopt::StructOpt; #[derive(StructOpt)] diff --git a/jcli-lib/src/rest/v0/network/stats.rs b/jcli-lib/src/rest/v0/network/stats.rs index ba97d0ef6c..7118dd08c7 100644 --- a/jcli-lib/src/rest/v0/network/stats.rs +++ b/jcli-lib/src/rest/v0/network/stats.rs @@ -1,5 +1,5 @@ -use crate::jcli_lib::rest::{Error, RestArgs}; -use crate::jcli_lib::utils::OutputFormat; +use crate::rest::{Error, RestArgs}; +use crate::utils::OutputFormat; use structopt::StructOpt; #[derive(StructOpt)] diff --git a/jcli-lib/src/rest/v0/node/mod.rs b/jcli-lib/src/rest/v0/node/mod.rs index 0e3087cc4a..90dbf9e3ff 100644 --- a/jcli-lib/src/rest/v0/node/mod.rs +++ b/jcli-lib/src/rest/v0/node/mod.rs @@ -1,7 +1,7 @@ mod stats; use self::stats::Stats; -use crate::jcli_lib::rest::Error; +use crate::rest::Error; use structopt::StructOpt; #[derive(StructOpt)] diff --git a/jcli-lib/src/rest/v0/node/stats.rs b/jcli-lib/src/rest/v0/node/stats.rs index fa057ab755..30632069c3 100644 --- a/jcli-lib/src/rest/v0/node/stats.rs +++ b/jcli-lib/src/rest/v0/node/stats.rs @@ -1,5 +1,5 @@ -use crate::jcli_lib::rest::{Error, RestArgs}; -use crate::jcli_lib::utils::OutputFormat; +use crate::rest::{Error, RestArgs}; +use crate::utils::OutputFormat; use structopt::StructOpt; #[derive(StructOpt)] diff --git a/jcli-lib/src/rest/v0/rewards/epoch.rs b/jcli-lib/src/rest/v0/rewards/epoch.rs index a5f6092af3..c4f19a24ed 100644 --- a/jcli-lib/src/rest/v0/rewards/epoch.rs +++ b/jcli-lib/src/rest/v0/rewards/epoch.rs @@ -1,4 +1,4 @@ -use crate::jcli_lib::rest::{Error, RestArgs}; +use crate::rest::{Error, RestArgs}; use structopt::StructOpt; #[derive(StructOpt)] diff --git a/jcli-lib/src/rest/v0/rewards/history.rs b/jcli-lib/src/rest/v0/rewards/history.rs index 3c720cf58a..dc84e59b1c 100644 --- a/jcli-lib/src/rest/v0/rewards/history.rs +++ b/jcli-lib/src/rest/v0/rewards/history.rs @@ -1,4 +1,4 @@ -use crate::jcli_lib::rest::{Error, RestArgs}; +use crate::rest::{Error, RestArgs}; use structopt::StructOpt; #[derive(StructOpt)] diff --git a/jcli-lib/src/rest/v0/rewards/mod.rs b/jcli-lib/src/rest/v0/rewards/mod.rs index 464b2c1e9d..e93e4e34c0 100644 --- a/jcli-lib/src/rest/v0/rewards/mod.rs +++ b/jcli-lib/src/rest/v0/rewards/mod.rs @@ -4,7 +4,7 @@ mod history; use self::epoch::Epoch; use self::history::History; -use crate::jcli_lib::rest::Error; +use crate::rest::Error; use structopt::StructOpt; #[derive(StructOpt)] diff --git a/jcli-lib/src/rest/v0/settings/mod.rs b/jcli-lib/src/rest/v0/settings/mod.rs index 3f2f751a02..29caac2897 100644 --- a/jcli-lib/src/rest/v0/settings/mod.rs +++ b/jcli-lib/src/rest/v0/settings/mod.rs @@ -1,5 +1,5 @@ -use crate::jcli_lib::rest::{Error, RestArgs}; -use crate::jcli_lib::utils::OutputFormat; +use crate::rest::{Error, RestArgs}; +use crate::utils::OutputFormat; use structopt::StructOpt; #[derive(StructOpt)] diff --git a/jcli-lib/src/rest/v0/shutdown/mod.rs b/jcli-lib/src/rest/v0/shutdown/mod.rs index 6b91eb7650..310f6d21a6 100644 --- a/jcli-lib/src/rest/v0/shutdown/mod.rs +++ b/jcli-lib/src/rest/v0/shutdown/mod.rs @@ -1,4 +1,4 @@ -use crate::jcli_lib::rest::{Error, RestArgs}; +use crate::rest::{Error, RestArgs}; use structopt::StructOpt; /// Shutdown node diff --git a/jcli-lib/src/rest/v0/stake/mod.rs b/jcli-lib/src/rest/v0/stake/mod.rs index 7b671f394e..dafca5ebc5 100644 --- a/jcli-lib/src/rest/v0/stake/mod.rs +++ b/jcli-lib/src/rest/v0/stake/mod.rs @@ -1,5 +1,5 @@ -use crate::jcli_lib::rest::{Error, RestArgs}; -use crate::jcli_lib::utils::OutputFormat; +use crate::rest::{Error, RestArgs}; +use crate::utils::OutputFormat; use structopt::StructOpt; #[derive(StructOpt)] diff --git a/jcli-lib/src/rest/v0/stake_pool/mod.rs b/jcli-lib/src/rest/v0/stake_pool/mod.rs index 7d3a5514a0..e524f0e162 100644 --- a/jcli-lib/src/rest/v0/stake_pool/mod.rs +++ b/jcli-lib/src/rest/v0/stake_pool/mod.rs @@ -1,5 +1,5 @@ -use crate::jcli_lib::rest::{Error, RestArgs}; -use crate::jcli_lib::utils::OutputFormat; +use crate::rest::{Error, RestArgs}; +use crate::utils::OutputFormat; use structopt::StructOpt; #[derive(StructOpt)] diff --git a/jcli-lib/src/rest/v0/stake_pools/mod.rs b/jcli-lib/src/rest/v0/stake_pools/mod.rs index bb6143ba06..aa5d91f71a 100644 --- a/jcli-lib/src/rest/v0/stake_pools/mod.rs +++ b/jcli-lib/src/rest/v0/stake_pools/mod.rs @@ -1,5 +1,5 @@ -use crate::jcli_lib::rest::{Error, RestArgs}; -use crate::jcli_lib::utils::OutputFormat; +use crate::rest::{Error, RestArgs}; +use crate::utils::OutputFormat; use structopt::StructOpt; #[derive(StructOpt)] diff --git a/jcli-lib/src/rest/v0/tip/mod.rs b/jcli-lib/src/rest/v0/tip/mod.rs index 1efc1c45ac..48b617eae2 100644 --- a/jcli-lib/src/rest/v0/tip/mod.rs +++ b/jcli-lib/src/rest/v0/tip/mod.rs @@ -1,4 +1,4 @@ -use crate::jcli_lib::rest::{Error, RestArgs}; +use crate::rest::{Error, RestArgs}; use structopt::StructOpt; #[derive(StructOpt)] diff --git a/jcli-lib/src/rest/v0/utxo/mod.rs b/jcli-lib/src/rest/v0/utxo/mod.rs index 15c852c916..a71c3e75e8 100644 --- a/jcli-lib/src/rest/v0/utxo/mod.rs +++ b/jcli-lib/src/rest/v0/utxo/mod.rs @@ -1,5 +1,5 @@ -use crate::jcli_lib::rest::{Error, RestArgs}; -use crate::jcli_lib::utils::OutputFormat; +use crate::rest::{Error, RestArgs}; +use crate::utils::OutputFormat; use structopt::StructOpt; #[derive(StructOpt)] diff --git a/jcli-lib/src/rest/v0/vote/active.rs b/jcli-lib/src/rest/v0/vote/active.rs index f9f269165b..bf95c61150 100644 --- a/jcli-lib/src/rest/v0/vote/active.rs +++ b/jcli-lib/src/rest/v0/vote/active.rs @@ -1,5 +1,5 @@ use super::{committees::Committees, plans::Plans}; -use crate::jcli_lib::rest::Error; +use crate::rest::Error; use structopt::StructOpt; #[derive(StructOpt)] diff --git a/jcli-lib/src/rest/v0/vote/committees.rs b/jcli-lib/src/rest/v0/vote/committees.rs index 5c9a037c6f..079fd2013f 100644 --- a/jcli-lib/src/rest/v0/vote/committees.rs +++ b/jcli-lib/src/rest/v0/vote/committees.rs @@ -1,5 +1,5 @@ -use crate::jcli_lib::rest::{Error, RestArgs}; -use crate::jcli_lib::utils::OutputFormat; +use crate::rest::{Error, RestArgs}; +use crate::utils::OutputFormat; use structopt::StructOpt; #[derive(StructOpt)] diff --git a/jcli-lib/src/rest/v0/vote/mod.rs b/jcli-lib/src/rest/v0/vote/mod.rs index b48f38a61c..a20f9b8609 100644 --- a/jcli-lib/src/rest/v0/vote/mod.rs +++ b/jcli-lib/src/rest/v0/vote/mod.rs @@ -3,7 +3,7 @@ mod committees; mod plans; use self::active::Active; -use crate::jcli_lib::rest::Error; +use crate::rest::Error; use structopt::StructOpt; #[derive(StructOpt)] diff --git a/jcli-lib/src/rest/v0/vote/plans.rs b/jcli-lib/src/rest/v0/vote/plans.rs index 93a9ed6a14..e9e6704155 100644 --- a/jcli-lib/src/rest/v0/vote/plans.rs +++ b/jcli-lib/src/rest/v0/vote/plans.rs @@ -1,5 +1,5 @@ -use crate::jcli_lib::rest::{Error, RestArgs}; -use crate::jcli_lib::utils::OutputFormat; +use crate::rest::{Error, RestArgs}; +use crate::utils::OutputFormat; use structopt::StructOpt; #[derive(StructOpt)] diff --git a/jcli-lib/src/transaction/add_account.rs b/jcli-lib/src/transaction/add_account.rs index bb26257aa6..0a17adf0a4 100644 --- a/jcli-lib/src/transaction/add_account.rs +++ b/jcli-lib/src/transaction/add_account.rs @@ -1,4 +1,4 @@ -use crate::jcli_lib::transaction::{common, Error}; +use crate::transaction::{common, Error}; use chain_addr::{Address, Kind}; use chain_impl_mockchain::transaction::UnspecifiedAccountIdentifier; use jormungandr_lib::interfaces; diff --git a/jcli-lib/src/transaction/add_certificate.rs b/jcli-lib/src/transaction/add_certificate.rs index 8c952baa31..ac72447fb6 100644 --- a/jcli-lib/src/transaction/add_certificate.rs +++ b/jcli-lib/src/transaction/add_certificate.rs @@ -1,4 +1,4 @@ -use crate::jcli_lib::transaction::{common, Error}; +use crate::transaction::{common, Error}; use jormungandr_lib::interfaces::Certificate; use structopt::StructOpt; diff --git a/jcli-lib/src/transaction/add_input.rs b/jcli-lib/src/transaction/add_input.rs index 6172330d30..f7dafaba03 100644 --- a/jcli-lib/src/transaction/add_input.rs +++ b/jcli-lib/src/transaction/add_input.rs @@ -1,4 +1,4 @@ -use crate::jcli_lib::transaction::{common, Error}; +use crate::transaction::{common, Error}; use chain_impl_mockchain::{fragment::FragmentId, transaction::TransactionIndex}; use jormungandr_lib::interfaces; use structopt::StructOpt; @@ -40,7 +40,7 @@ impl AddInput { mod tests { use self::common::CommonTransaction; use super::*; - use crate::jcli_lib::transaction::staging::Staging; + use crate::transaction::staging::Staging; use chain_impl_mockchain::{key::Hash, value::Value}; use assert_fs::NamedTempFile; diff --git a/jcli-lib/src/transaction/add_output.rs b/jcli-lib/src/transaction/add_output.rs index 4d0ca8251f..3fd8951257 100644 --- a/jcli-lib/src/transaction/add_output.rs +++ b/jcli-lib/src/transaction/add_output.rs @@ -1,4 +1,4 @@ -use crate::jcli_lib::transaction::{common, Error}; +use crate::transaction::{common, Error}; use chain_impl_mockchain::transaction::Output; use jormungandr_lib::interfaces; use structopt::StructOpt; diff --git a/jcli-lib/src/transaction/add_witness.rs b/jcli-lib/src/transaction/add_witness.rs index b66123f38d..adf455370c 100644 --- a/jcli-lib/src/transaction/add_witness.rs +++ b/jcli-lib/src/transaction/add_witness.rs @@ -1,4 +1,4 @@ -use crate::jcli_lib::{ +use crate::{ transaction::{common, Error}, utils::io, }; diff --git a/jcli-lib/src/transaction/auth.rs b/jcli-lib/src/transaction/auth.rs index 4db878e5a5..edc024655b 100644 --- a/jcli-lib/src/transaction/auth.rs +++ b/jcli-lib/src/transaction/auth.rs @@ -1,4 +1,4 @@ -use crate::jcli_lib::{ +use crate::{ certificate::read_input, transaction::{common, Error}, }; diff --git a/jcli-lib/src/transaction/common.rs b/jcli-lib/src/transaction/common.rs index 5485122a27..c8f5a593c4 100644 --- a/jcli-lib/src/transaction/common.rs +++ b/jcli-lib/src/transaction/common.rs @@ -1,4 +1,4 @@ -use crate::jcli_lib::transaction::{staging::Staging, Error}; +use crate::transaction::{staging::Staging, Error}; use chain_impl_mockchain::fee::{LinearFee, PerCertificateFee, PerVoteCertificateFee}; use std::{num::NonZeroU64, path::PathBuf}; use structopt::StructOpt; diff --git a/jcli-lib/src/transaction/finalize.rs b/jcli-lib/src/transaction/finalize.rs index f9c42b47be..85c8964acd 100644 --- a/jcli-lib/src/transaction/finalize.rs +++ b/jcli-lib/src/transaction/finalize.rs @@ -1,4 +1,4 @@ -use crate::jcli_lib::transaction::{common, Error}; +use crate::transaction::{common, Error}; use chain_impl_mockchain::transaction::OutputPolicy; use jormungandr_lib::interfaces; use structopt::StructOpt; diff --git a/jcli-lib/src/transaction/info.rs b/jcli-lib/src/transaction/info.rs index 9f810af6d7..fc80523d6a 100644 --- a/jcli-lib/src/transaction/info.rs +++ b/jcli-lib/src/transaction/info.rs @@ -1,4 +1,4 @@ -use crate::jcli_lib::{ +use crate::{ transaction::{common, Error}, utils::{io, OutputFormat}, }; diff --git a/jcli-lib/src/transaction/mk_witness.rs b/jcli-lib/src/transaction/mk_witness.rs index 09a178cb24..9d55d8985c 100644 --- a/jcli-lib/src/transaction/mk_witness.rs +++ b/jcli-lib/src/transaction/mk_witness.rs @@ -1,4 +1,4 @@ -use crate::jcli_lib::{ +use crate::{ transaction::Error, utils::{io, key_parser::read_ed25519_secret_key_from_file}, }; diff --git a/jcli-lib/src/transaction/mod.rs b/jcli-lib/src/transaction/mod.rs index a26979d786..364c3a6da7 100644 --- a/jcli-lib/src/transaction/mod.rs +++ b/jcli-lib/src/transaction/mod.rs @@ -13,7 +13,7 @@ mod seal; mod staging; use self::staging::StagingKind; -use crate::jcli_lib::{ +use crate::{ certificate, utils::{key_parser, output_format}, }; diff --git a/jcli-lib/src/transaction/new.rs b/jcli-lib/src/transaction/new.rs index 423d2d6050..ffe1d664e3 100644 --- a/jcli-lib/src/transaction/new.rs +++ b/jcli-lib/src/transaction/new.rs @@ -1,6 +1,6 @@ use structopt::StructOpt; -use crate::jcli_lib::transaction::{common, staging::Staging, Error}; +use crate::transaction::{common, staging::Staging, Error}; #[derive(StructOpt)] #[structopt(rename_all = "kebab-case")] diff --git a/jcli-lib/src/transaction/seal.rs b/jcli-lib/src/transaction/seal.rs index d7db27eb52..d98418c957 100644 --- a/jcli-lib/src/transaction/seal.rs +++ b/jcli-lib/src/transaction/seal.rs @@ -1,4 +1,4 @@ -use crate::jcli_lib::transaction::{common, Error}; +use crate::transaction::{common, Error}; use structopt::StructOpt; #[derive(StructOpt)] diff --git a/jcli-lib/src/transaction/staging.rs b/jcli-lib/src/transaction/staging.rs index e5508cfdd3..2c3cc7a79e 100644 --- a/jcli-lib/src/transaction/staging.rs +++ b/jcli-lib/src/transaction/staging.rs @@ -1,5 +1,5 @@ -use crate::jcli_lib::certificate::committee_encrypted_vote_tally_sign; -use crate::jcli_lib::{ +use crate::certificate::committee_encrypted_vote_tally_sign; +use crate::{ certificate::{ committee_vote_plan_sign, committee_vote_tally_sign, pool_owner_sign, stake_delegation_account_binding_sign, diff --git a/jcli-lib/src/utils/output_file.rs b/jcli-lib/src/utils/output_file.rs index 34310dac4e..747b1f6587 100644 --- a/jcli-lib/src/utils/output_file.rs +++ b/jcli-lib/src/utils/output_file.rs @@ -1,4 +1,4 @@ -use crate::jcli_lib::utils::io; +use crate::utils::io; use structopt::StructOpt; diff --git a/jcli-lib/src/utils/vote.rs b/jcli-lib/src/utils/vote.rs index 97a65f61bc..ff2f1f0e3a 100644 --- a/jcli-lib/src/utils/vote.rs +++ b/jcli-lib/src/utils/vote.rs @@ -1,4 +1,4 @@ -use crate::jcli_lib::utils::io; +use crate::utils::io; use jormungandr_lib::crypto::hash::Hash; use jormungandr_lib::interfaces::{serde_base64_bytes, VotePlanStatus}; use serde::{Deserialize, Serialize}; diff --git a/jcli-lib/src/vote/committee/communication_key.rs b/jcli-lib/src/vote/committee/communication_key.rs index 60f8c8feba..08fda2b39f 100644 --- a/jcli-lib/src/vote/committee/communication_key.rs +++ b/jcli-lib/src/vote/committee/communication_key.rs @@ -1,4 +1,4 @@ -use crate::jcli_lib::vote::{Error, OutputFile, Seed}; +use crate::vote::{Error, OutputFile, Seed}; use bech32::{FromBase32, ToBase32}; use chain_vote::MemberCommunicationKey; use rand::rngs::OsRng; @@ -56,7 +56,7 @@ impl Generate { output, "{}", bech32::encode( - crate::jcli_lib::vote::bech32_constants::COMMUNICATION_SK_HRP, + crate::vote::bech32_constants::COMMUNICATION_SK_HRP, key.to_bytes().to_base32() ) .map_err(Error::Bech32)? @@ -67,10 +67,10 @@ impl Generate { impl ToPublic { fn exec(self) -> Result<(), Error> { - let line = crate::jcli_lib::utils::io::read_line(&self.input_key)?; + let line = crate::utils::io::read_line(&self.input_key)?; let (hrp, bytes) = bech32::decode(&line).map_err(Error::Bech32)?; - if hrp != crate::jcli_lib::vote::bech32_constants::COMMUNICATION_SK_HRP { + if hrp != crate::vote::bech32_constants::COMMUNICATION_SK_HRP { return Err(Error::InvalidSecretKey); } @@ -86,7 +86,7 @@ impl ToPublic { output, "{}", bech32::encode( - crate::jcli_lib::vote::bech32_constants::COMMUNICATION_PK_HRP, + crate::vote::bech32_constants::COMMUNICATION_PK_HRP, kp.public_key.to_bytes().to_base32() ) .map_err(Error::Bech32)? diff --git a/jcli-lib/src/vote/committee/member_key.rs b/jcli-lib/src/vote/committee/member_key.rs index cdb299ad8e..23a9899d79 100644 --- a/jcli-lib/src/vote/committee/member_key.rs +++ b/jcli-lib/src/vote/committee/member_key.rs @@ -1,4 +1,4 @@ -use crate::jcli_lib::vote::{Error, OutputFile, Seed}; +use crate::vote::{Error, OutputFile, Seed}; use bech32::{FromBase32, ToBase32}; use chain_vote::gargamel::PublicKey; use chain_vote::{MemberCommunicationPublicKey, MemberState}; @@ -97,7 +97,7 @@ impl Generate { output, "{}", bech32::encode( - crate::jcli_lib::vote::bech32_constants::MEMBER_SK_HRP, + crate::vote::bech32_constants::MEMBER_SK_HRP, key.to_bytes().to_base32() ) .map_err(Error::Bech32)? @@ -108,10 +108,10 @@ impl Generate { impl ToPublic { fn exec(self) -> Result<(), Error> { - let line = crate::jcli_lib::utils::io::read_line(&self.input_key)?; + let line = crate::utils::io::read_line(&self.input_key)?; let (hrp, key) = bech32::decode(&line).map_err(Error::Bech32)?; - if hrp != crate::jcli_lib::vote::bech32_constants::MEMBER_SK_HRP { + if hrp != crate::vote::bech32_constants::MEMBER_SK_HRP { return Err(Error::InvalidSecretKey); } @@ -124,7 +124,7 @@ impl ToPublic { let mut output = self.output_file.open()?; let key = bech32::encode( - crate::jcli_lib::vote::bech32_constants::MEMBER_PK_HRP, + crate::vote::bech32_constants::MEMBER_PK_HRP, pk.to_bytes().to_base32(), ) .map_err(Error::Bech32)?; @@ -146,7 +146,7 @@ impl MemberKey { fn parse_member_communication_key(key: &str) -> Result { let (hrp, raw_key) = bech32::decode(key).map_err(Error::Bech32)?; - if hrp != crate::jcli_lib::vote::bech32_constants::COMMUNICATION_PK_HRP { + if hrp != crate::vote::bech32_constants::COMMUNICATION_PK_HRP { return Err(Error::InvalidPublicKey); } diff --git a/jcli-lib/src/vote/encrypting_vote_key.rs b/jcli-lib/src/vote/encrypting_vote_key.rs index 7380661f12..36f9551ac5 100644 --- a/jcli-lib/src/vote/encrypting_vote_key.rs +++ b/jcli-lib/src/vote/encrypting_vote_key.rs @@ -1,4 +1,4 @@ -use crate::jcli_lib::vote::{Error, OutputFile}; +use crate::vote::{Error, OutputFile}; use bech32::{FromBase32, ToBase32}; use std::io::Write as _; use structopt::StructOpt; @@ -29,7 +29,7 @@ impl EncryptingVoteKey { output, "{}", bech32::encode( - crate::jcli_lib::vote::bech32_constants::ENCRYPTING_VOTE_PK_HRP, + crate::vote::bech32_constants::ENCRYPTING_VOTE_PK_HRP, election_public_key.to_bytes().to_base32() ) .map_err(Error::Bech32)? @@ -42,7 +42,7 @@ fn parse_member_key(key: &str) -> Result>(path: &Option

) -> Result Date: Tue, 13 Apr 2021 15:10:47 -0500 Subject: [PATCH 07/25] copy build.rs from jcli crate --- jcli-lib/build.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 jcli-lib/build.rs diff --git a/jcli-lib/build.rs b/jcli-lib/build.rs new file mode 100644 index 0000000000..37b45dccf6 --- /dev/null +++ b/jcli-lib/build.rs @@ -0,0 +1,19 @@ +fn main() { + let pkg_version = if let Ok(date) = std::env::var("DATE") { + format!("{}.{}", env!("CARGO_PKG_VERSION"), date) + } else { + env!("CARGO_PKG_VERSION").to_string() + }; + + println!("cargo:rustc-env=CARGO_PKG_VERSION={}", pkg_version); + + let version = versionisator::Version::new( + env!("CARGO_MANIFEST_DIR"), + env!("CARGO_PKG_NAME").to_string(), + pkg_version, + ); + + println!("cargo:rustc-env=FULL_VERSION={}", version.full()); + println!("cargo:rustc-env=SIMPLE_VERSION={}", version.simple()); + println!("cargo:rustc-env=SOURCE_VERSION={}", version.hash()); +} From b5235e99faa659b3dcc9db82ebff06e6e5e72e89 Mon Sep 17 00:00:00 2001 From: Filip Dulic Date: Tue, 13 Apr 2021 15:32:56 -0500 Subject: [PATCH 08/25] remove unused dependencies from jcli --- Cargo.lock | 28 ---------------------------- jcli/Cargo.toml | 38 -------------------------------------- 2 files changed, 66 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ebeec9aa1b..88e8f76e6f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1913,36 +1913,8 @@ checksum = "dd25036021b0de88a0aff6b850051563c6516d0bf53f8638938edbb9de732736" name = "jcli" version = "0.11.1" dependencies = [ - "assert_fs", - "base64 0.13.0", - "bech32", - "bincode", - "bytes 1.0.1", - "chain-addr", - "chain-core", - "chain-crypto", - "chain-impl-mockchain", - "chain-time", - "chain-vote", - "clap", - "ed25519-bip32", - "gtmpl", - "hex", "jcli-lib", - "jormungandr-lib", - "mime", - "predicates", - "rand 0.8.3", - "rand_chacha 0.3.0", - "rayon", - "reqwest", - "serde", - "serde_derive", - "serde_json", - "serde_yaml", "structopt", - "thiserror", - "valico", "versionisator", ] diff --git a/jcli/Cargo.toml b/jcli/Cargo.toml index a8dc0d8b5e..99630f80eb 100644 --- a/jcli/Cargo.toml +++ b/jcli/Cargo.toml @@ -12,46 +12,8 @@ Midgard Serpent edition = "2018" [dependencies] -rand = "0.8" -rand_chacha = "0.3" -serde = "1.0" -serde_derive = "1.0" -serde_json = "1.0.59" -serde_yaml = "0.8" -bincode = "1.3.3" -mime = "^0.3.7" structopt = "^0.3" -bech32 = "0.7" -hex = "0.4.2" -rayon = "1.5" -base64 = "0.13.0" -chain-core = { git = "https://github.com/input-output-hk/chain-libs.git", branch = "master" } -chain-impl-mockchain = { git = "https://github.com/input-output-hk/chain-libs.git", branch = "master" } -chain-addr = { git = "https://github.com/input-output-hk/chain-libs.git", branch = "master" } -chain-crypto = { git = "https://github.com/input-output-hk/chain-libs.git", branch = "master" } -chain-time = { git = "https://github.com/input-output-hk/chain-libs.git", branch = "master" } -chain-vote = { git = "https://github.com/input-output-hk/chain-libs.git", branch = "master", features = ["p256k1"] } jcli-lib = { path = "../jcli-lib" } -jormungandr-lib = { path = "../jormungandr-lib" } -gtmpl = "0.6.0" -valico = "3.5.0" -ed25519-bip32 = "0.3" -thiserror = "1.0" -bytes = "1.0" - -[dependencies.clap] -version = "2.33" -default-features = false -features = [ "suggestions", "color", "wrap_help" ] - -[dependencies.reqwest] -version = "0.11" -default-features = false -features = ["blocking", "rustls-tls", "json"] - -[dev-dependencies] -assert_fs = "1.0" -predicates = "1.0" [build-dependencies] versionisator = "1.0.2" From 92f5a70f3cb3c3d4f248057d068e909adc65b148 Mon Sep 17 00:00:00 2001 From: Filip Dulic Date: Wed, 14 Apr 2021 13:56:09 -0500 Subject: [PATCH 09/25] make structopt an optional feature, add to default features in Cargo manifest --- jcli-lib/Cargo.toml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/jcli-lib/Cargo.toml b/jcli-lib/Cargo.toml index 53e34c2fa2..b0d1bd731d 100644 --- a/jcli-lib/Cargo.toml +++ b/jcli-lib/Cargo.toml @@ -20,7 +20,6 @@ serde_json = "1.0.59" serde_yaml = "0.8" bincode = "1.3.3" mime = "^0.3.7" -structopt = "^0.3" bech32 = "0.7" hex = "0.4.2" rayon = "1.5" @@ -38,6 +37,10 @@ ed25519-bip32 = "0.3" thiserror = "1.0" bytes = "1.0" +[dependencies.structopt] +version = "^0.3" +optional = true + [dependencies.clap] version = "2.33" default-features = false @@ -54,3 +57,6 @@ predicates = "1.0" [build-dependencies] versionisator = "1.0.2" + +[features] +default = ["structopt"] From 49c52d856cdac367024590e0a276d9472c7d1d9d Mon Sep 17 00:00:00 2001 From: Filip Dulic Date: Wed, 14 Apr 2021 14:03:41 -0500 Subject: [PATCH 10/25] feature gate structopt attributes for jcli_lib::address --- jcli-lib/src/address.rs | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/jcli-lib/src/address.rs b/jcli-lib/src/address.rs index b19fde4c8f..2d3bff60d3 100644 --- a/jcli-lib/src/address.rs +++ b/jcli-lib/src/address.rs @@ -1,11 +1,15 @@ use crate::utils::key_parser::parse_pub_key; use chain_addr::{AddressReadable, Discrimination, Kind}; use chain_crypto::{bech32::Bech32 as _, AsymmetricPublicKey, Ed25519, PublicKey}; +#[cfg(feature = "structopt")] use structopt::StructOpt; use thiserror::Error; -#[derive(StructOpt)] -#[structopt(name = "address", rename_all = "kebab-case")] +#[cfg_attr( + feature = "structopt", + derive(StructOpt), + structopt(name = "address", rename_all = "kebab-case") +)] pub enum Address { /// Display the content and info of a bech32 formatted address. Info(InfoArgs), @@ -18,48 +22,51 @@ pub enum Address { Account(AccountArgs), } -#[derive(StructOpt)] +#[cfg_attr(feature = "structopt", derive(StructOpt))] pub struct InfoArgs { /// An address, in bech32 format, to display the content /// and info that can be extracted from. - #[structopt(name = "ADDRESS")] + #[cfg_attr(feature = "structopt", structopt(name = "ADDRESS"))] address: AddressReadable, } -#[derive(StructOpt)] +#[cfg_attr(feature = "structopt", derive(StructOpt))] pub struct DiscriminationData { /// Set the discrimination type to testing (default is production). - #[structopt(long = "testing")] + #[cfg_attr(feature = "structopt", structopt(long = "testing"))] testing: bool, /// Set the prefix to use to describe the address. This is only available /// on the human readable representation of the address and will not be /// used or checked by the node. - #[structopt(long = "prefix", default_value = "ca")] + #[cfg_attr( + feature = "structopt", + structopt(long = "prefix", default_value = "ca") + )] prefix: String, } -#[derive(StructOpt)] +#[cfg_attr(feature = "structopt", derive(StructOpt))] pub struct SingleArgs { /// A public key in bech32 encoding with the key type prefix. - #[structopt(name = "PUBLIC_KEY", parse(try_from_str = parse_pub_key))] + #[cfg_attr(feature = "structopt", structopt(name = "PUBLIC_KEY", parse(try_from_str = parse_pub_key)))] key: PublicKey, /// A public key in bech32 encoding with the key type prefix. - #[structopt(name = "DELEGATION_KEY", parse(try_from_str = parse_pub_key))] + #[cfg_attr(feature = "structopt", structopt(name = "DELEGATION_KEY", parse(try_from_str = parse_pub_key)))] delegation: Option>, - #[structopt(flatten)] + #[cfg_attr(feature = "structopt", structopt(flatten))] discrimination_data: DiscriminationData, } -#[derive(StructOpt)] +#[cfg_attr(feature = "structopt", derive(StructOpt))] pub struct AccountArgs { /// A public key in bech32 encoding with the key type prefix. - #[structopt(name = "PUBLIC_KEY", parse(try_from_str = parse_pub_key))] + #[cfg_attr(feature = "structopt", structopt(name = "PUBLIC_KEY", parse(try_from_str = parse_pub_key)))] key: PublicKey, - #[structopt(flatten)] + #[cfg_attr(feature = "structopt", structopt(flatten))] discrimination_data: DiscriminationData, } From fbc507d9daf9486cffa83a013a1e31f51a651e9f Mon Sep 17 00:00:00 2001 From: Filip Dulic Date: Wed, 14 Apr 2021 14:08:57 -0500 Subject: [PATCH 11/25] feature gate structopt attributes for jcli_lib::auto_complete This module really doesn't make sense to have if the 'structopt' feature is disabled. The gated attributes can be safely removed as long as the entire module is gated. I'm leaving the gated attributes in place, until the API is better defined. --- jcli-lib/src/auto_completion.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/jcli-lib/src/auto_completion.rs b/jcli-lib/src/auto_completion.rs index c5acd3da66..2c8bd2af8b 100644 --- a/jcli-lib/src/auto_completion.rs +++ b/jcli-lib/src/auto_completion.rs @@ -1,10 +1,16 @@ +//! Generated auto-completions for supported shells supported by `structopt` via `clap`. use std::path::{Path, PathBuf}; +#[cfg(feature = "structopt")] use structopt::{clap::Shell, StructOpt}; use thiserror::Error; -#[derive(StructOpt)] -#[structopt(rename_all = "kebab-case")] +#[cfg_attr( + feature = "structopt", + derive(StructOpt), + structopt(rename_all = "kebab-case") +)] pub struct AutoCompletion { + #[cfg(feature = "structopt")] /// set the type shell for the auto completion output (bash, zsh...) shell: Shell, @@ -12,6 +18,7 @@ pub struct AutoCompletion { output: PathBuf, } +#[cfg(feature = "structopt")] impl AutoCompletion { pub fn exec(self) -> Result<(), Error> { validate_output(&self.output)?; From 422f2828a970d98b8ba09da623b1619f4fe46b67 Mon Sep 17 00:00:00 2001 From: Filip Dulic Date: Wed, 14 Apr 2021 14:15:16 -0500 Subject: [PATCH 12/25] feature gate structopt attributes for jcli_lib::block --- jcli-lib/src/block/mod.rs | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/jcli-lib/src/block/mod.rs b/jcli-lib/src/block/mod.rs index 890caba1bd..2cf8d21025 100644 --- a/jcli-lib/src/block/mod.rs +++ b/jcli-lib/src/block/mod.rs @@ -11,6 +11,7 @@ use std::{ io::{BufRead, Write}, path::PathBuf, }; +#[cfg(feature = "structopt")] use structopt::StructOpt; use thiserror::Error; @@ -85,8 +86,11 @@ fn print_hash(input: Input) -> Result<(), Error> { } /// create block 0 of the blockchain (i.e. the genesis block) -#[derive(StructOpt)] -#[structopt(name = "genesis", rename_all = "kebab-case")] +#[cfg_attr( + feature = "structopt", + derive(StructOpt), + structopt(name = "genesis", rename_all = "kebab-case") +)] pub enum Genesis { /// Create a default Genesis file with appropriate documentation /// to help creating the YAML file @@ -104,13 +108,16 @@ pub enum Genesis { Hash(Input), } -#[derive(StructOpt)] +#[cfg_attr(feature = "structopt", derive(StructOpt))] pub struct Input { /// the file path to the genesis file defining the block 0 /// /// If not available the command will expect to read the configuration from /// the standard input. - #[structopt(long = "input", parse(from_os_str), name = "FILE_INPUT")] + #[cfg_attr( + feature = "structopt", + structopt(long = "input", parse(from_os_str), name = "FILE_INPUT") + )] input_file: Option, } @@ -128,16 +135,19 @@ impl Input { } } -#[derive(StructOpt)] +#[cfg_attr(feature = "structopt", derive(StructOpt))] pub struct Common { - #[structopt(flatten)] + #[cfg_attr(feature = "structopt", structopt(flatten))] pub input: Input, /// the file path to the block to create /// /// If not available the command will expect to write the block to /// to the standard output - #[structopt(long = "output", parse(from_os_str), name = "FILE_OUTPUT")] + #[cfg_attr( + feature = "structopt", + structopt(long = "output", parse(from_os_str), name = "FILE_OUTPUT") + )] pub output_file: Option, } From 30fdb1ffb8ec23cd4e36cab9e99703d779461cbb Mon Sep 17 00:00:00 2001 From: Filip Dulic Date: Wed, 14 Apr 2021 14:26:51 -0500 Subject: [PATCH 13/25] feature gate structopt attributes for jcli_lib::certificate::* --- jcli-lib/src/certificate/mod.rs | 30 +++++++---- .../certificate/new_encrypted_vote_tally.rs | 12 +++-- .../certificate/new_owner_stake_delegation.rs | 7 +-- .../src/certificate/new_stake_delegation.rs | 9 ++-- .../new_stake_pool_registration.rs | 50 +++++++++++++------ .../certificate/new_stake_pool_retirement.rs | 10 ++-- jcli-lib/src/certificate/new_vote_cast.rs | 27 +++++----- jcli-lib/src/certificate/new_vote_plan.rs | 10 ++-- jcli-lib/src/certificate/new_vote_tally.rs | 34 ++++++++----- jcli-lib/src/certificate/show.rs | 8 ++- .../src/certificate/show/stake_pool_id.rs | 18 +++++-- jcli-lib/src/certificate/show/vote_plan_id.rs | 18 +++++-- jcli-lib/src/certificate/sign.rs | 14 ++++-- jcli-lib/src/certificate/weighted_pool_ids.rs | 8 ++- 14 files changed, 171 insertions(+), 84 deletions(-) diff --git a/jcli-lib/src/certificate/mod.rs b/jcli-lib/src/certificate/mod.rs index 00bd1118f7..66145c64c0 100644 --- a/jcli-lib/src/certificate/mod.rs +++ b/jcli-lib/src/certificate/mod.rs @@ -26,6 +26,7 @@ use std::{ io::{BufRead, BufReader, Write}, path::{Path, PathBuf}, }; +#[cfg(feature = "structopt")] use structopt::StructOpt; use thiserror::Error; @@ -114,8 +115,11 @@ pub enum Error { } #[allow(clippy::large_enum_variant)] -#[derive(StructOpt)] -#[structopt(rename_all = "kebab-case")] +#[cfg_attr( + feature = "structopt", + derive(StructOpt), + structopt(rename_all = "kebab-case") +)] pub enum Certificate { /// Build certificate New(NewArgs), @@ -129,8 +133,11 @@ pub enum Certificate { } #[allow(clippy::large_enum_variant)] -#[derive(StructOpt)] -#[structopt(rename_all = "kebab-case")] +#[cfg_attr( + feature = "structopt", + derive(StructOpt), + structopt(rename_all = "kebab-case") +)] pub enum NewArgs { /// create the stake pool registration certificate. /// @@ -167,21 +174,24 @@ pub enum NewArgs { VoteCast(new_vote_cast::VoteCastCmd), } -#[derive(StructOpt)] -#[structopt(rename_all = "kebab-case")] +#[cfg_attr( + feature = "structopt", + derive(StructOpt), + structopt(rename_all = "kebab-case") +)] pub struct PrintArgs { /// get the certificate to sign from the given file. If no file /// provided, it will be read from the standard input pub input: Option, } -#[derive(StructOpt)] +#[cfg_attr(feature = "structopt", derive(StructOpt))] pub struct StakeDelegationArgs { - #[structopt(name = "PUBLIC_KEY")] + #[cfg_attr(feature = "structopt", structopt(name = "PUBLIC_KEY"))] pub key: String, - #[structopt(name = "POOL_ID")] + #[cfg_attr(feature = "structopt", structopt(name = "POOL_ID"))] pub pool_id: String, - #[structopt(name = "SIGNING_KEY")] + #[cfg_attr(feature = "structopt", structopt(name = "SIGNING_KEY"))] pub private_key: PathBuf, } diff --git a/jcli-lib/src/certificate/new_encrypted_vote_tally.rs b/jcli-lib/src/certificate/new_encrypted_vote_tally.rs index e34afef3a9..3bc10ffd5b 100644 --- a/jcli-lib/src/certificate/new_encrypted_vote_tally.rs +++ b/jcli-lib/src/certificate/new_encrypted_vote_tally.rs @@ -2,22 +2,26 @@ use crate::certificate::{write_cert, Error}; use chain_impl_mockchain::certificate; use chain_impl_mockchain::certificate::{Certificate, VotePlanId}; use std::path::PathBuf; +#[cfg(feature = "structopt")] use structopt::StructOpt; /// create an encrypted vote tally certificate /// /// voteplan id needs to be provided -#[derive(StructOpt)] -#[structopt(rename_all = "kebab-case")] +#[cfg_attr( + feature = "structopt", + derive(StructOpt), + structopt(rename_all = "kebab-case") +)] pub struct EncryptedVoteTally { /// vote plan id /// /// the vote plan identifier on the blockchain - #[structopt(long = "vote-plan-id")] + #[cfg_attr(feature = "structopt", structopt(long = "vote-plan-id"))] pub id: VotePlanId, /// write the output to the given file or print it to the standard output if not defined - #[structopt(long = "output")] + #[cfg_attr(feature = "structopt", structopt(long = "output"))] pub output: Option, } diff --git a/jcli-lib/src/certificate/new_owner_stake_delegation.rs b/jcli-lib/src/certificate/new_owner_stake_delegation.rs index f5977859f3..f36de5214c 100644 --- a/jcli-lib/src/certificate/new_owner_stake_delegation.rs +++ b/jcli-lib/src/certificate/new_owner_stake_delegation.rs @@ -2,15 +2,16 @@ use crate::certificate::{weighted_pool_ids::WeightedPoolIds, write_cert, Error}; use chain_impl_mockchain::certificate::{Certificate, OwnerStakeDelegation as Delegation}; use jormungandr_lib::interfaces::Certificate as CertificateType; use std::{convert::TryInto, path::PathBuf}; +#[cfg(feature = "structopt")] use structopt::StructOpt; -#[derive(StructOpt)] +#[cfg_attr(feature = "structopt", derive(StructOpt))] pub struct OwnerStakeDelegation { - #[structopt(flatten)] + #[cfg_attr(feature = "structopt", structopt(flatten))] pool_ids: WeightedPoolIds, /// write the output to the given file or print it to the standard output if not defined - #[structopt(short = "o", long = "output")] + #[cfg_attr(feature = "structopt", structopt(short = "o", long = "output"))] output: Option, } diff --git a/jcli-lib/src/certificate/new_stake_delegation.rs b/jcli-lib/src/certificate/new_stake_delegation.rs index d58aed1d79..fb3dde649a 100644 --- a/jcli-lib/src/certificate/new_stake_delegation.rs +++ b/jcli-lib/src/certificate/new_stake_delegation.rs @@ -9,19 +9,20 @@ use chain_impl_mockchain::{ }; use jormungandr_lib::interfaces::Certificate as CertificateType; use std::{convert::TryInto, path::PathBuf}; +#[cfg(feature = "structopt")] use structopt::StructOpt; -#[derive(StructOpt)] +#[cfg_attr(feature = "structopt", derive(StructOpt))] pub struct StakeDelegation { /// the public key used in the stake key registration - #[structopt(name = "STAKE_KEY", parse(try_from_str = parse_pub_key))] + #[cfg_attr(feature = "structopt", structopt(name = "STAKE_KEY", parse(try_from_str = parse_pub_key)))] stake_id: PublicKey, - #[structopt(flatten)] + #[cfg_attr(feature = "structopt", structopt(flatten))] pool_ids: WeightedPoolIds, /// write the output to the given file or print it to the standard output if not defined - #[structopt(short = "o", long = "output")] + #[cfg_attr(feature = "structopt", structopt(short = "o", long = "output"))] output: Option, } diff --git a/jcli-lib/src/certificate/new_stake_pool_registration.rs b/jcli-lib/src/certificate/new_stake_pool_registration.rs index e06f4470f7..6e8f8f36fe 100644 --- a/jcli-lib/src/certificate/new_stake_pool_registration.rs +++ b/jcli-lib/src/certificate/new_stake_pool_registration.rs @@ -14,6 +14,7 @@ use std::{ num::{NonZeroU64, NonZeroU8}, path::PathBuf, }; +#[cfg(feature = "structopt")] use structopt::StructOpt; /// create the stake pool registration certificate. @@ -31,20 +32,27 @@ use structopt::StructOpt; /// /// Delegators will then receive a share of the remaining rewards: `Y - T`. /// -#[derive(Debug, StructOpt)] +#[derive(Debug)] +#[cfg_attr(feature = "structopt", derive(StructOpt))] pub struct StakePoolRegistration { /// management threshold /// /// This is the number of owners keys that are required to update the stake /// pools parameter (the tax, update the keys, the threshold itsef...). - #[structopt(long = "management-threshold", name = "THRESHOLD")] + #[cfg_attr( + feature = "structopt", + structopt(long = "management-threshold", name = "THRESHOLD") + )] pub management_threshold: NonZeroU8, /// start validity /// /// This state when the stake pool registration becomes effective in seconds since /// the block0 start time. - #[structopt(long = "start-validity", name = "SECONDS-SINCE-START")] + #[cfg_attr( + feature = "structopt", + structopt(long = "start-validity", name = "SECONDS-SINCE-START") + )] pub start_validity: u64, /// public key of the owner(s) @@ -54,67 +62,79 @@ pub struct StakePoolRegistration { /// /// Owner will receive a share of the fixed and ratio tax too. unless a reward /// account is specified for the stake pool. - #[structopt( + #[cfg_attr(feature = "structopt", structopt( long = "owner", name = "OWNER_KEY", parse(try_from_str = parse_pub_key), required = true - )] + ))] pub owners: Vec>, /// public key of the operators(s) /// /// Owners can allow an operator to update some or all of the stake pool parameters. /// Different operators can have different permissions. - #[structopt( + #[cfg_attr(feature = "structopt", structopt( long = "operator", name = "OPERATOR_KEY", parse(try_from_str = parse_pub_key) - )] + ))] pub operators: Vec>, /// Public key of the block signing key - #[structopt( + #[cfg_attr(feature = "structopt", structopt( long = "kes-key", name = "KES_KEY", parse(try_from_str = parse_pub_key) - )] + ))] pub kes_key: PublicKey, /// public key of the VRF key - #[structopt( + #[cfg_attr(feature = "structopt", structopt( long = "vrf-key", name = "VRF_KEY", parse(try_from_str = parse_pub_key) - )] + ))] pub vrf_key: PublicKey, /// set the fixed value tax the stake pool will reserve from the reward /// /// For example, a stake pool may set this value to cover their fixed operation /// costs. - #[structopt(long = "tax-fixed", name = "TAX_VALUE", default_value = "0")] + #[cfg_attr( + feature = "structopt", + structopt(long = "tax-fixed", name = "TAX_VALUE", default_value = "0") + )] pub tax_fixed: Value, /// The percentage take of the stake pool. /// /// Once the `tax-fixed` has been take, this is the percentage the stake pool will /// take for themselves. - #[structopt(long = "tax-ratio", name = "TAX_RATIO", default_value = "0/1")] + #[cfg_attr( + feature = "structopt", + structopt(long = "tax-ratio", name = "TAX_RATIO", default_value = "0/1") + )] pub tax_ratio: Ratio, /// The maximum tax value the stake pool will take. /// /// This will set the maximum the stake pool value will reserve for themselves from /// the `--tax-ratio` (excluding `--tax-fixed`). - #[structopt(long = "tax-limit", name = "TAX_LIMIT")] + #[cfg_attr( + feature = "structopt", + structopt(long = "tax-limit", name = "TAX_LIMIT") + )] pub tax_limit: Option, /// the account to reward the stake pool tax too /// /// If this value is set, instead of distributing the rewards to the owners /// the rewards will be distributed to this account. - #[structopt(long = "reward-account", name = "REWARD_ACCOUNT")] + #[cfg_attr( + feature = "structopt", + structopt(long = "reward-account", name = "REWARD_ACCOUNT") + )] pub reward_account: Option, /// print the output signed certificate in the given file, if no file given diff --git a/jcli-lib/src/certificate/new_stake_pool_retirement.rs b/jcli-lib/src/certificate/new_stake_pool_retirement.rs index 4a16dd04cf..6573c14319 100644 --- a/jcli-lib/src/certificate/new_stake_pool_retirement.rs +++ b/jcli-lib/src/certificate/new_stake_pool_retirement.rs @@ -3,23 +3,27 @@ use chain_crypto::Blake2b256; use chain_impl_mockchain::certificate::{Certificate, PoolRetirement}; use chain_time::DurationSeconds; use std::path::PathBuf; +#[cfg(feature = "structopt")] use structopt::StructOpt; /// retire the given stake pool ID From the blockchain /// /// by doing so all remaining stake delegated to this stake pool will /// become pending and will need to be re-delegated. -#[derive(StructOpt)] +#[cfg_attr(feature = "structopt", derive(StructOpt))] pub struct StakePoolRetirement { /// set the 32bytes (in hexadecimal) of the Stake Pool identifier - #[structopt(long = "pool-id", name = "POOL_ID")] + #[cfg_attr(feature = "structopt", structopt(long = "pool-id", name = "POOL_ID"))] pool_id: Blake2b256, /// start retirement /// /// This state when the stake pool retirement becomes effective in seconds since /// the block0 start time. - #[structopt(long = "retirement-time", name = "SECONDS-SINCE-START")] + #[cfg_attr( + feature = "structopt", + structopt(long = "retirement-time", name = "SECONDS-SINCE-START") + )] pub retirement_time: u64, /// print the output signed certificate in the given file, if no file given diff --git a/jcli-lib/src/certificate/new_vote_cast.rs b/jcli-lib/src/certificate/new_vote_cast.rs index 61b4022979..f01161b864 100644 --- a/jcli-lib/src/certificate/new_vote_cast.rs +++ b/jcli-lib/src/certificate/new_vote_cast.rs @@ -7,56 +7,57 @@ use chain_impl_mockchain::{ }; use rand_chacha::rand_core::SeedableRng; use std::path::PathBuf; +#[cfg(feature = "structopt")] use structopt::StructOpt; -#[derive(StructOpt)] +#[cfg_attr(feature = "structopt", derive(StructOpt))] pub struct PublicVoteCast { /// the vote plan identified on the blockchain - #[structopt(long = "vote-plan-id")] + #[cfg_attr(feature = "structopt", structopt(long = "vote-plan-id"))] vote_plan_id: VotePlanId, /// the number of proposal in the vote plan you vote for - #[structopt(long = "proposal-index")] + #[cfg_attr(feature = "structopt", structopt(long = "proposal-index"))] proposal_index: u8, /// the number of choice within the proposal you vote for - #[structopt(long = "choice")] + #[cfg_attr(feature = "structopt", structopt(long = "choice"))] choice: u8, /// write the output to the given file or print it to the standard output if not defined - #[structopt(long = "output")] + #[cfg_attr(feature = "structopt", structopt(long = "output"))] output: Option, } -#[derive(StructOpt)] +#[cfg_attr(feature = "structopt", derive(StructOpt))] pub struct PrivateVoteCast { /// the vote plan identified on the blockchain - #[structopt(long = "vote-plan-id")] + #[cfg_attr(feature = "structopt", structopt(long = "vote-plan-id"))] vote_plan_id: VotePlanId, /// the number of proposal in the vote plan you vote for - #[structopt(long = "proposal-index")] + #[cfg_attr(feature = "structopt", structopt(long = "proposal-index"))] proposal_index: u8, /// size of voting options - #[structopt(long = "options-size")] + #[cfg_attr(feature = "structopt", structopt(long = "options-size"))] options: usize, /// the number of choice within the proposal you vote for - #[structopt(long = "choice")] + #[cfg_attr(feature = "structopt", structopt(long = "choice"))] choice: u8, /// key to encrypt the vote with - #[structopt(long = "key-path")] + #[cfg_attr(feature = "structopt", structopt(long = "key-path"))] encrypting_key_path: Option, /// write the output to the given file or print it to the standard output if not defined - #[structopt(long = "output")] + #[cfg_attr(feature = "structopt", structopt(long = "output"))] output: Option, } /// create a vote cast certificate -#[derive(StructOpt)] +#[cfg_attr(feature = "structopt", derive(StructOpt))] pub enum VoteCastCmd { Public(PublicVoteCast), Private(PrivateVoteCast), diff --git a/jcli-lib/src/certificate/new_vote_plan.rs b/jcli-lib/src/certificate/new_vote_plan.rs index e3e7373c9c..0a94e0b269 100644 --- a/jcli-lib/src/certificate/new_vote_plan.rs +++ b/jcli-lib/src/certificate/new_vote_plan.rs @@ -9,20 +9,24 @@ use chain_impl_mockchain::{ use jormungandr_lib::interfaces::VotePlanDef; use serde::Deserialize; use std::path::PathBuf; +#[cfg(feature = "structopt")] use structopt::StructOpt; /// create a vote plan certificate /// /// the vote plan configuration data needs to be provided -#[derive(StructOpt)] -#[structopt(rename_all = "kebab-case")] +#[cfg_attr( + feature = "structopt", + derive(StructOpt), + structopt(rename_all = "kebab-case") +)] pub struct VotePlanRegistration { /// the file containing the vote plan configuration (YAML). If no file /// provided, it will be read from the standard input pub input: Option, /// write the output to the given file or print it to the standard output if not defined - #[structopt(long = "output")] + #[cfg_attr(feature = "structopt", structopt(long = "output"))] pub output: Option, } diff --git a/jcli-lib/src/certificate/new_vote_tally.rs b/jcli-lib/src/certificate/new_vote_tally.rs index b6a1f900fd..58774e0492 100644 --- a/jcli-lib/src/certificate/new_vote_tally.rs +++ b/jcli-lib/src/certificate/new_vote_tally.rs @@ -7,50 +7,60 @@ use jormungandr_lib::crypto::hash::Hash; use jormungandr_lib::interfaces::{PrivateTallyState, Tally}; use std::convert::TryInto; use std::path::PathBuf; +#[cfg(feature = "structopt")] use structopt::StructOpt; /// create a vote tally certificate /// /// voteplan id needs to be provided -#[derive(StructOpt)] -#[structopt(rename_all = "kebab-case")] +#[cfg_attr( + feature = "structopt", + derive(StructOpt), + structopt(rename_all = "kebab-case") +)] pub enum VoteTallyRegistration { Public(PublicTally), Private(PrivateTally), } -#[derive(StructOpt)] -#[structopt(rename_all = "kebab-case")] +#[cfg_attr( + feature = "structopt", + derive(StructOpt), + structopt(rename_all = "kebab-case") +)] pub struct PublicTally { /// vote plan id /// /// the vote plan identifier on the blockchain - #[structopt(long = "vote-plan-id")] + #[cfg_attr(feature = "structopt", structopt(long = "vote-plan-id"))] pub id: VotePlanId, /// write the output to the given file or print it to the standard output if not defined - #[structopt(long = "output")] + #[cfg_attr(feature = "structopt", structopt(long = "output"))] pub output: Option, } -#[derive(StructOpt)] -#[structopt(rename_all = "kebab-case")] +#[cfg_attr( + feature = "structopt", + derive(StructOpt), + structopt(rename_all = "kebab-case") +)] pub struct PrivateTally { /// path to the json file containing the tally shares - #[structopt(long)] + #[cfg_attr(feature = "structopt", structopt(long))] pub shares: PathBuf, /// path to the json file containing the vote plan result - #[structopt(long)] + #[cfg_attr(feature = "structopt", structopt(long))] pub vote_plan: PathBuf, /// The id of the vote plan to include in the certificate. /// Can be left unspecified if there is only one vote plan in the input - #[structopt(long)] + #[cfg_attr(feature = "structopt", structopt(long))] pub vote_plan_id: Option, /// write the output to the given file or print it to the standard output if not defined - #[structopt(long)] + #[cfg_attr(feature = "structopt", structopt(long))] pub output: Option, } diff --git a/jcli-lib/src/certificate/show.rs b/jcli-lib/src/certificate/show.rs index 6f8dcadb35..8b7c367d53 100644 --- a/jcli-lib/src/certificate/show.rs +++ b/jcli-lib/src/certificate/show.rs @@ -2,10 +2,14 @@ mod stake_pool_id; mod vote_plan_id; use crate::certificate::Error; +#[cfg(feature = "structopt")] use structopt::StructOpt; -#[derive(StructOpt)] -#[structopt(rename_all = "kebab-case")] +#[cfg_attr( + feature = "structopt", + derive(StructOpt), + structopt(rename_all = "kebab-case") +)] pub enum ShowArgs { /// get the stake pool id from the given stake pool registration certificate StakePoolId(stake_pool_id::GetStakePoolId), diff --git a/jcli-lib/src/certificate/show/stake_pool_id.rs b/jcli-lib/src/certificate/show/stake_pool_id.rs index 5aa196c3f3..711cd2df24 100644 --- a/jcli-lib/src/certificate/show/stake_pool_id.rs +++ b/jcli-lib/src/certificate/show/stake_pool_id.rs @@ -2,16 +2,26 @@ use crate::certificate::{read_cert_or_signed_cert, write_output, Error}; use chain_impl_mockchain::certificate::Certificate; use jormungandr_lib::interfaces::Certificate as CertificateType; use std::path::PathBuf; +#[cfg(feature = "structopt")] use structopt::StructOpt; -#[derive(StructOpt)] -#[structopt(rename_all = "kebab-case")] +#[cfg_attr( + feature = "structopt", + derive(StructOpt), + structopt(rename_all = "kebab-case") +)] pub struct GetStakePoolId { /// file to read the certificate from (defaults to stdin) - #[structopt(long, parse(from_os_str), value_name = "PATH")] + #[cfg_attr( + feature = "structopt", + structopt(long, parse(from_os_str), value_name = "PATH") + )] pub input: Option, /// file to write the output to (defaults to stdout) - #[structopt(long, parse(from_os_str), value_name = "PATH")] + #[cfg_attr( + feature = "structopt", + structopt(long, parse(from_os_str), value_name = "PATH") + )] pub output: Option, } diff --git a/jcli-lib/src/certificate/show/vote_plan_id.rs b/jcli-lib/src/certificate/show/vote_plan_id.rs index 99cd340a80..843577b972 100644 --- a/jcli-lib/src/certificate/show/vote_plan_id.rs +++ b/jcli-lib/src/certificate/show/vote_plan_id.rs @@ -2,16 +2,26 @@ use crate::certificate::{read_cert_or_signed_cert, write_output, Error}; use chain_impl_mockchain::certificate::Certificate; use jormungandr_lib::interfaces::Certificate as CertificateType; use std::path::PathBuf; +#[cfg(feature = "structopt")] use structopt::StructOpt; -#[derive(StructOpt)] -#[structopt(rename_all = "kebab-case")] +#[cfg_attr( + feature = "structopt", + derive(StructOpt), + structopt(rename_all = "kebab-case") +)] pub struct GetVotePlanId { /// file to read the certificate from (defaults to stdin) - #[structopt(long, parse(from_os_str), value_name = "PATH")] + #[cfg_attr( + feature = "structopt", + structopt(long, parse(from_os_str), value_name = "PATH") + )] pub input: Option, /// file to write the output to (defaults to stdout) - #[structopt(long, parse(from_os_str), value_name = "PATH")] + #[cfg_attr( + feature = "structopt", + structopt(long, parse(from_os_str), value_name = "PATH") + )] pub output: Option, } diff --git a/jcli-lib/src/certificate/sign.rs b/jcli-lib/src/certificate/sign.rs index 543a0759ca..3fa608de9b 100644 --- a/jcli-lib/src/certificate/sign.rs +++ b/jcli-lib/src/certificate/sign.rs @@ -17,21 +17,25 @@ use chain_impl_mockchain::{ }; use jormungandr_lib::interfaces; use std::{convert::TryInto, path::PathBuf}; +#[cfg(feature = "structopt")] use structopt::StructOpt; -#[derive(StructOpt)] -#[structopt(rename_all = "kebab-case")] +#[cfg_attr( + feature = "structopt", + derive(StructOpt), + structopt(rename_all = "kebab-case") +)] pub struct Sign { /// path to the file with the signing key - #[structopt(short = "k", long = "key")] + #[cfg_attr(feature = "structopt", structopt(short = "k", long = "key"))] pub signing_keys: Vec, /// get the certificate to sign from the given file. If no file /// provided, it will be read from the standard input - #[structopt(short = "c", long = "certificate")] + #[cfg_attr(feature = "structopt", structopt(short = "c", long = "certificate"))] pub input: Option, /// write the signed certificate into the given file. If no file /// provided it will be written into the standard output - #[structopt(short = "o", long = "output")] + #[cfg_attr(feature = "structopt", structopt(short = "o", long = "output"))] pub output: Option, } diff --git a/jcli-lib/src/certificate/weighted_pool_ids.rs b/jcli-lib/src/certificate/weighted_pool_ids.rs index 82f7cd7a9e..fe0e4bb4f5 100644 --- a/jcli-lib/src/certificate/weighted_pool_ids.rs +++ b/jcli-lib/src/certificate/weighted_pool_ids.rs @@ -5,13 +5,17 @@ use chain_impl_mockchain::{ accounting::account::DELEGATION_RATIO_MAX_DECLS, }; use std::{convert::TryFrom, error::Error as StdError, str::FromStr}; +#[cfg(feature = "structopt")] use structopt::StructOpt; -#[derive(StructOpt)] +#[cfg_attr(feature = "structopt", derive(StructOpt))] pub struct WeightedPoolIds { /// hex-encoded stake pool IDs and their numeric weights in format "pool_id:weight". /// If weight is not provided, it defaults to 1. - #[structopt(name = "STAKE_POOL_IDS", required = true)] + #[cfg_attr( + feature = "structopt", + structopt(name = "STAKE_POOL_IDS", required = true) + )] pool_ids: Vec, } From 4f21efd24f5dff89f1e857ae05c9724c638c30ad Mon Sep 17 00:00:00 2001 From: Filip Dulic Date: Wed, 14 Apr 2021 14:27:18 -0500 Subject: [PATCH 14/25] feature gate structopt attributes for jcli_lib::debug::* --- jcli-lib/src/debug/block.rs | 5 +++-- jcli-lib/src/debug/message.rs | 5 +++-- jcli-lib/src/debug/mod.rs | 8 ++++++-- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/jcli-lib/src/debug/block.rs b/jcli-lib/src/debug/block.rs index 12d840dd30..fa35918bf3 100644 --- a/jcli-lib/src/debug/block.rs +++ b/jcli-lib/src/debug/block.rs @@ -3,12 +3,13 @@ use chain_core::property::Deserialize as _; use chain_impl_mockchain::block::Block as BlockMock; use std::io::{BufRead, BufReader}; use std::path::PathBuf; +#[cfg(feature = "structopt")] use structopt::StructOpt; -#[derive(StructOpt)] +#[cfg_attr(feature = "structopt", derive(StructOpt))] pub struct Block { /// file containing hex-encoded message. If not provided, it will be read from stdin. - #[structopt(short, long)] + #[cfg_attr(feature = "structopt", structopt(short, long))] input: Option, } diff --git a/jcli-lib/src/debug/message.rs b/jcli-lib/src/debug/message.rs index 71271be988..eca2447c69 100644 --- a/jcli-lib/src/debug/message.rs +++ b/jcli-lib/src/debug/message.rs @@ -3,12 +3,13 @@ use chain_core::property::Deserialize as _; use chain_impl_mockchain::fragment::Fragment as MockFragment; use std::io::{BufRead, BufReader}; use std::path::PathBuf; +#[cfg(feature = "structopt")] use structopt::StructOpt; -#[derive(StructOpt)] +#[cfg_attr(feature = "structopt", derive(StructOpt))] pub struct Message { /// file containing hex-encoded message. If not provided, it will be read from stdin. - #[structopt(short, long)] + #[cfg_attr(feature = "structopt", structopt(short, long))] input: Option, } diff --git a/jcli-lib/src/debug/mod.rs b/jcli-lib/src/debug/mod.rs index d73c648808..0dbc7a8fb9 100644 --- a/jcli-lib/src/debug/mod.rs +++ b/jcli-lib/src/debug/mod.rs @@ -2,11 +2,15 @@ mod block; mod message; use hex::FromHexError; use std::path::PathBuf; +#[cfg(feature = "structopt")] use structopt::StructOpt; use thiserror::Error; -#[derive(StructOpt)] -#[structopt(rename_all = "kebab-case")] +#[cfg_attr( + feature = "structopt", + derive(StructOpt), + structopt(rename_all = "kebab-case") +)] pub enum Debug { /// Decode hex-encoded message and display its content Message(message::Message), From 652517733cbdaba06a6c6c094240ececb34e758b Mon Sep 17 00:00:00 2001 From: Filip Dulic Date: Wed, 14 Apr 2021 14:27:45 -0500 Subject: [PATCH 15/25] feature gate structopt attributes for jcli_lib::key --- jcli-lib/src/key.rs | 78 ++++++++++++++++++++++++++++++--------------- 1 file changed, 52 insertions(+), 26 deletions(-) diff --git a/jcli-lib/src/key.rs b/jcli-lib/src/key.rs index 46f43ede35..7b159f74f3 100644 --- a/jcli-lib/src/key.rs +++ b/jcli-lib/src/key.rs @@ -14,6 +14,7 @@ use std::{ io::{Read, Write}, path::{Path, PathBuf}, }; +#[cfg(feature = "structopt")] use structopt::{clap::arg_enum, StructOpt}; use thiserror::Error; @@ -58,8 +59,12 @@ pub enum Error { }, } -#[derive(StructOpt, Debug)] -#[structopt(name = "genesis", rename_all = "kebab-case")] +#[derive(Debug)] +#[cfg_attr( + feature = "structopt", + derive(StructOpt), + structopt(name = "genesis", rename_all = "kebab-case") +)] pub enum Key { /// generate a private key Generate(Generate), @@ -77,115 +82,126 @@ pub enum Key { Derive(Derive), } -#[derive(StructOpt, Debug)] +#[derive(Debug)] +#[cfg_attr(feature = "structopt", derive(StructOpt))] pub struct FromBytes { /// Type of a private key /// /// supported values are: ed25519, ed25519bip32, ed25519extended, curve25519_2hashdh or sumed25519_12 - #[structopt(long = "type")] + #[cfg_attr(feature = "structopt", structopt(long = "type"))] key_type: GenPrivKeyType, /// retrieve the private key from the given bytes - #[structopt(name = "INPUT_BYTES")] + #[cfg_attr(feature = "structopt", structopt(name = "INPUT_BYTES"))] input_bytes: Option, - #[structopt(flatten)] + #[cfg_attr(feature = "structopt", structopt(flatten))] output_file: OutputFile, } -#[derive(StructOpt, Debug)] +#[derive(Debug)] +#[cfg_attr(feature = "structopt", derive(StructOpt))] pub struct ToBytes { - #[structopt(flatten)] + #[cfg_attr(feature = "structopt", structopt(flatten))] output_file: OutputFile, /// path to the private key to serialize in bytes /// Or read from the standard input - #[structopt(name = "INPUT_FILE")] + #[cfg_attr(feature = "structopt", structopt(name = "INPUT_FILE"))] input_key: Option, } -#[derive(StructOpt, Debug)] +#[derive(Debug)] +#[cfg_attr(feature = "structopt", derive(StructOpt))] pub struct Generate { /// Type of a private key /// /// supported values are: ed25519, ed25519bip32, ed25519extended, curve25519_2hashdh or sumed25519_12 - #[structopt(long = "type")] + #[cfg_attr(feature = "structopt", structopt(long = "type"))] key_type: GenPrivKeyType, - #[structopt(flatten)] + #[cfg_attr(feature = "structopt", structopt(flatten))] output_file: OutputFile, /// optional seed to generate the key, for the same entropy the same key /// will be generated (32 bytes in hexadecimal). This seed will be fed to /// ChaChaRNG and allow pseudo random key generation. Do not use if you /// are not sure. - #[structopt(long = "seed", short = "s", name = "SEED", parse(try_from_str))] + #[cfg_attr( + feature = "structopt", + structopt(long = "seed", short = "s", name = "SEED", parse(try_from_str)) + )] seed: Option, } -#[derive(StructOpt, Debug)] +#[derive(Debug)] +#[cfg_attr(feature = "structopt", derive(StructOpt))] pub struct ToPublic { /// the source private key to extract the public key from /// /// if no value passed, the private key will be read from the /// standard input - #[structopt(long = "input")] + #[cfg_attr(feature = "structopt", structopt(long = "input"))] input_key: Option, - #[structopt(flatten)] + #[cfg_attr(feature = "structopt", structopt(flatten))] output_file: OutputFile, } -#[derive(StructOpt, Debug)] +#[derive(Debug)] +#[cfg_attr(feature = "structopt", derive(StructOpt))] pub struct Sign { /// path to file with bech32-encoded secret key /// /// supported key formats are: ed25519, ed25519bip32, ed25519extended and sumed25519_12 - #[structopt(long = "secret-key")] + #[cfg_attr(feature = "structopt", structopt(long = "secret-key"))] secret_key: PathBuf, /// path to file to write signature into, if no value is passed, standard output will be used - #[structopt(long = "output", short = "o")] + #[cfg_attr(feature = "structopt", structopt(long = "output", short = "o"))] output: Option, /// path to file with data to sign, if no value is passed, standard input will be used data: Option, } -#[derive(StructOpt, Debug)] +#[derive(Debug)] +#[cfg_attr(feature = "structopt", derive(StructOpt))] pub struct Verify { /// path to file with bech32-encoded public key /// /// supported key formats are: ed25519, ed25519bip32 and sumed25519_12 - #[structopt(long = "public-key")] + #[cfg_attr(feature = "structopt", structopt(long = "public-key"))] public_key: PathBuf, /// path to file with signature - #[structopt(long = "signature")] + #[cfg_attr(feature = "structopt", structopt(long = "signature"))] signature: PathBuf, /// path to file with signed data, if no value is passed, standard input will be used data: Option, } -#[derive(StructOpt, Debug)] +#[derive(Debug)] +#[cfg_attr(feature = "structopt", derive(StructOpt))] pub struct Derive { /// the ed25519bip32 parent key to derive a child key from /// /// if no value passed, the parent key will be read from the /// standard input - #[structopt(long = "input")] + #[cfg_attr(feature = "structopt", structopt(long = "input"))] parent_key: Option, /// the index of child key index: u32, - #[structopt(flatten)] + #[cfg_attr(feature = "structopt", structopt(flatten))] child_key: OutputFile, } +#[cfg(feature = "structopt")] arg_enum! { - #[derive(StructOpt, Debug)] + #[derive(Debug, StructOpt)] pub enum GenPrivKeyType { Ed25519, Ed25519Bip32, @@ -195,6 +211,16 @@ arg_enum! { } } +#[cfg(not(feature = "structopt"))] +#[derive(Debug)] +pub enum GenPrivKeyType { + Ed25519, + Ed25519Bip32, + Ed25519Extended, + SumEd25519_12, + Curve25519_2HashDh, +} + impl Key { pub fn exec(self) -> Result<(), Error> { match self { From 6584dd4b809f285cfadbfb92bdbb5346179fda81 Mon Sep 17 00:00:00 2001 From: Filip Dulic Date: Wed, 14 Apr 2021 14:45:39 -0500 Subject: [PATCH 16/25] feature gate structopt attributes for jcli_lib::rest::* --- jcli-lib/src/rest/config.rs | 15 ++++++++---- jcli-lib/src/rest/mod.rs | 8 +++++-- jcli-lib/src/rest/v0/account/mod.rs | 14 ++++++++---- jcli-lib/src/rest/v0/block/mod.rs | 10 +++++--- jcli-lib/src/rest/v0/block/next_id.rs | 12 ++++++---- jcli-lib/src/rest/v0/block/subcommand.rs | 10 +++++--- jcli-lib/src/rest/v0/diagnostic/mod.rs | 10 +++++--- jcli-lib/src/rest/v0/leaders/mod.rs | 29 +++++++++++++++--------- jcli-lib/src/rest/v0/message/mod.rs | 16 ++++++++----- jcli-lib/src/rest/v0/mod.rs | 8 +++++-- jcli-lib/src/rest/v0/network/mod.rs | 8 +++++-- jcli-lib/src/rest/v0/network/stats.rs | 12 ++++++---- jcli-lib/src/rest/v0/node/mod.rs | 8 +++++-- jcli-lib/src/rest/v0/node/stats.rs | 12 ++++++---- jcli-lib/src/rest/v0/rewards/epoch.rs | 10 +++++--- jcli-lib/src/rest/v0/rewards/history.rs | 10 +++++--- jcli-lib/src/rest/v0/rewards/mod.rs | 8 +++++-- jcli-lib/src/rest/v0/settings/mod.rs | 12 ++++++---- jcli-lib/src/rest/v0/shutdown/mod.rs | 10 +++++--- jcli-lib/src/rest/v0/stake/mod.rs | 12 ++++++---- jcli-lib/src/rest/v0/stake_pool/mod.rs | 12 ++++++---- jcli-lib/src/rest/v0/stake_pools/mod.rs | 12 ++++++---- jcli-lib/src/rest/v0/tip/mod.rs | 10 +++++--- jcli-lib/src/rest/v0/utxo/mod.rs | 21 +++++++++++------ jcli-lib/src/rest/v0/vote/active.rs | 8 +++++-- jcli-lib/src/rest/v0/vote/committees.rs | 12 ++++++---- jcli-lib/src/rest/v0/vote/mod.rs | 8 +++++-- jcli-lib/src/rest/v0/vote/plans.rs | 12 ++++++---- 28 files changed, 225 insertions(+), 104 deletions(-) diff --git a/jcli-lib/src/rest/config.rs b/jcli-lib/src/rest/config.rs index a0779471eb..3771f5e1a4 100644 --- a/jcli-lib/src/rest/config.rs +++ b/jcli-lib/src/rest/config.rs @@ -4,22 +4,29 @@ use reqwest::{ Url, }; use std::path::PathBuf; +#[cfg(feature = "structopt")] use structopt::StructOpt; use thiserror::Error; -#[derive(StructOpt)] +#[cfg_attr(feature = "structopt", derive(StructOpt))] pub struct RestArgs { /// node API address. Must always have `http://` or `https://` prefix. /// E.g. `-h http://127.0.0.1`, `--host https://node.com:8443/cardano/api` - #[structopt(short, long, env = "JORMUNGANDR_RESTAPI_URL")] + #[cfg_attr( + feature = "structopt", + structopt(short, long, env = "JORMUNGANDR_RESTAPI_URL") + )] host: Url, /// print additional debug information to stderr. /// The output format is intentionally undocumented and unstable - #[structopt(long)] + #[cfg_attr(feature = "structopt", structopt(long))] debug: bool, /// An optional TLS root certificate to be used in a case when the /// certificate CA is not present within the webpki certificate bundle. - #[structopt(long, name = "PATH", env = "JORMUNGANDR_TLS_CERT_PATH")] + #[cfg_attr( + feature = "structopt", + structopt(long, name = "PATH", env = "JORMUNGANDR_TLS_CERT_PATH") + )] tls_cert_path: Option, } diff --git a/jcli-lib/src/rest/mod.rs b/jcli-lib/src/rest/mod.rs index bd28b8f32d..2b3607cbad 100644 --- a/jcli-lib/src/rest/mod.rs +++ b/jcli-lib/src/rest/mod.rs @@ -4,12 +4,16 @@ mod v0; use crate::utils::{io::ReadYamlError, output_format}; use config::RestArgs; use hex::FromHexError; +#[cfg(feature = "structopt")] use structopt::StructOpt; use thiserror::Error; /// Send request to node REST API -#[derive(StructOpt)] -#[structopt(rename_all = "kebab-case")] +#[cfg_attr( + feature = "structopt", + derive(StructOpt), + structopt(rename_all = "kebab-case") +)] pub enum Rest { /// API version 0 V0(v0::V0), diff --git a/jcli-lib/src/rest/v0/account/mod.rs b/jcli-lib/src/rest/v0/account/mod.rs index f022a7b910..21155ce8fa 100644 --- a/jcli-lib/src/rest/v0/account/mod.rs +++ b/jcli-lib/src/rest/v0/account/mod.rs @@ -1,18 +1,22 @@ use crate::rest::{Error, RestArgs}; use crate::utils::{AccountId, OutputFormat}; +#[cfg(feature = "structopt")] use structopt::StructOpt; -#[derive(StructOpt)] -#[structopt(rename_all = "kebab-case")] +#[cfg_attr( + feature = "structopt", + derive(StructOpt), + structopt(rename_all = "kebab-case") +)] pub enum Account { /// Get account state Get { - #[structopt(flatten)] + #[cfg_attr(feature = "structopt", structopt(flatten))] args: RestArgs, - #[structopt(flatten)] + #[cfg_attr(feature = "structopt", structopt(flatten))] output_format: OutputFormat, /// An Account ID either in the form of an address of kind account, or an account public key - #[structopt(parse(try_from_str = AccountId::try_from_str))] + #[cfg_attr(feature = "structopt", structopt(parse(try_from_str = AccountId::try_from_str)))] account_id: AccountId, }, } diff --git a/jcli-lib/src/rest/v0/block/mod.rs b/jcli-lib/src/rest/v0/block/mod.rs index 9cec98ef86..ea567800a4 100644 --- a/jcli-lib/src/rest/v0/block/mod.rs +++ b/jcli-lib/src/rest/v0/block/mod.rs @@ -1,16 +1,20 @@ use crate::rest::Error; +#[cfg(feature = "structopt")] use structopt::StructOpt; mod next_id; mod subcommand; -#[derive(StructOpt)] -#[structopt(rename_all = "kebab-case")] +#[cfg_attr( + feature = "structopt", + derive(StructOpt), + structopt(rename_all = "kebab-case") +)] pub struct Block { /// ID of the block block_id: String, - #[structopt(subcommand)] + #[cfg_attr(feature = "structopt", structopt(subcommand))] subcommand: subcommand::Subcommand, } diff --git a/jcli-lib/src/rest/v0/block/next_id.rs b/jcli-lib/src/rest/v0/block/next_id.rs index 2ba08e48bd..6fd4c27fd9 100644 --- a/jcli-lib/src/rest/v0/block/next_id.rs +++ b/jcli-lib/src/rest/v0/block/next_id.rs @@ -1,16 +1,20 @@ use crate::rest::{Error, RestArgs}; use chain_crypto::Blake2b256; +#[cfg(feature = "structopt")] use structopt::StructOpt; -#[derive(StructOpt)] -#[structopt(rename_all = "kebab-case")] +#[cfg_attr( + feature = "structopt", + derive(StructOpt), + structopt(rename_all = "kebab-case") +)] pub enum NextId { /// Get block descendant ID Get { - #[structopt(flatten)] + #[cfg_attr(feature = "structopt", structopt(flatten))] args: RestArgs, /// Maximum number of IDs, must be between 1 and 100, default 1 - #[structopt(short, long)] + #[cfg_attr(feature = "structopt", structopt(short, long))] count: Option, }, } diff --git a/jcli-lib/src/rest/v0/block/subcommand.rs b/jcli-lib/src/rest/v0/block/subcommand.rs index 9380363014..b04f102393 100644 --- a/jcli-lib/src/rest/v0/block/subcommand.rs +++ b/jcli-lib/src/rest/v0/block/subcommand.rs @@ -1,13 +1,17 @@ use super::next_id::NextId; use crate::rest::{Error, RestArgs}; +#[cfg(feature = "structopt")] use structopt::StructOpt; -#[derive(StructOpt)] -#[structopt(rename_all = "kebab-case")] +#[cfg_attr( + feature = "structopt", + derive(StructOpt), + structopt(rename_all = "kebab-case") +)] pub enum Subcommand { /// Get block Get { - #[structopt(flatten)] + #[cfg_attr(feature = "structopt", structopt(flatten))] args: RestArgs, }, /// Get block descendant ID diff --git a/jcli-lib/src/rest/v0/diagnostic/mod.rs b/jcli-lib/src/rest/v0/diagnostic/mod.rs index 1d7c7f7891..db44fc2c3b 100644 --- a/jcli-lib/src/rest/v0/diagnostic/mod.rs +++ b/jcli-lib/src/rest/v0/diagnostic/mod.rs @@ -1,12 +1,16 @@ use crate::rest::{Error, RestArgs}; +#[cfg(feature = "structopt")] use structopt::StructOpt; -#[derive(StructOpt)] -#[structopt(rename_all = "kebab-case")] +#[cfg_attr( + feature = "structopt", + derive(StructOpt), + structopt(rename_all = "kebab-case") +)] pub enum Diagnostic { /// Get system diagnostic information Get { - #[structopt(flatten)] + #[cfg_attr(feature = "structopt", structopt(flatten))] args: RestArgs, }, } diff --git a/jcli-lib/src/rest/v0/leaders/mod.rs b/jcli-lib/src/rest/v0/leaders/mod.rs index e2dd9cdc94..08618d2a1d 100644 --- a/jcli-lib/src/rest/v0/leaders/mod.rs +++ b/jcli-lib/src/rest/v0/leaders/mod.rs @@ -1,31 +1,35 @@ use crate::rest::{Error, RestArgs}; use crate::utils::{io, OutputFormat}; use std::path::PathBuf; +#[cfg(feature = "structopt")] use structopt::StructOpt; -#[derive(StructOpt)] -#[structopt(rename_all = "kebab-case")] +#[cfg_attr( + feature = "structopt", + derive(StructOpt), + structopt(rename_all = "kebab-case") +)] pub enum Leaders { /// Get list of leader IDs Get { - #[structopt(flatten)] + #[cfg_attr(feature = "structopt", structopt(flatten))] args: RestArgs, - #[structopt(flatten)] + #[cfg_attr(feature = "structopt", structopt(flatten))] output_format: OutputFormat, }, /// Register new leader and get its ID Post { - #[structopt(flatten)] + #[cfg_attr(feature = "structopt", structopt(flatten))] args: RestArgs, /// File containing YAML with leader secret. /// It must have the same format as secret YAML passed to Jormungandr as --secret. /// If not provided, YAML will be read from stdin. - #[structopt(short, long)] + #[cfg_attr(feature = "structopt", structopt(short, long))] file: Option, }, /// Delete leader Delete { - #[structopt(flatten)] + #[cfg_attr(feature = "structopt", structopt(flatten))] args: RestArgs, /// ID of deleted leader id: u32, @@ -35,14 +39,17 @@ pub enum Leaders { Logs(GetLogs), } -#[derive(StructOpt)] -#[structopt(rename_all = "kebab-case")] +#[cfg_attr( + feature = "structopt", + derive(StructOpt), + structopt(rename_all = "kebab-case") +)] pub enum GetLogs { /// Get leadership log Get { - #[structopt(flatten)] + #[cfg_attr(feature = "structopt", structopt(flatten))] args: RestArgs, - #[structopt(flatten)] + #[cfg_attr(feature = "structopt", structopt(flatten))] output_format: OutputFormat, }, } diff --git a/jcli-lib/src/rest/v0/message/mod.rs b/jcli-lib/src/rest/v0/message/mod.rs index 63a699d873..ab0eab190e 100644 --- a/jcli-lib/src/rest/v0/message/mod.rs +++ b/jcli-lib/src/rest/v0/message/mod.rs @@ -5,18 +5,22 @@ use crate::{ use chain_core::property::Deserialize; use chain_impl_mockchain::fragment::Fragment; use std::path::PathBuf; +#[cfg(feature = "structopt")] use structopt::StructOpt; -#[derive(StructOpt)] -#[structopt(rename_all = "kebab-case")] +#[cfg_attr( + feature = "structopt", + derive(StructOpt), + structopt(rename_all = "kebab-case") +)] pub enum Message { /// Post message. Prints id for posted message Post { - #[structopt(flatten)] + #[cfg_attr(feature = "structopt", structopt(flatten))] args: RestArgs, /// File containing hex-encoded message. /// If not provided, message will be read from stdin. - #[structopt(short, long)] + #[cfg_attr(feature = "structopt", structopt(short, long))] file: Option, }, @@ -24,9 +28,9 @@ pub enum Message { /// on pending transaction, rejected transaction and or when a transaction /// has been added in a block Logs { - #[structopt(flatten)] + #[cfg_attr(feature = "structopt", structopt(flatten))] args: RestArgs, - #[structopt(flatten)] + #[cfg_attr(feature = "structopt", structopt(flatten))] output_format: OutputFormat, }, } diff --git a/jcli-lib/src/rest/v0/mod.rs b/jcli-lib/src/rest/v0/mod.rs index 8f20dd43ff..7320f65083 100644 --- a/jcli-lib/src/rest/v0/mod.rs +++ b/jcli-lib/src/rest/v0/mod.rs @@ -16,10 +16,14 @@ mod utxo; mod vote; use crate::rest::Error; +#[cfg(feature = "structopt")] use structopt::StructOpt; -#[derive(StructOpt)] -#[structopt(rename_all = "kebab-case")] +#[cfg_attr( + feature = "structopt", + derive(StructOpt), + structopt(rename_all = "kebab-case") +)] pub enum V0 { /// Account operations Account(account::Account), diff --git a/jcli-lib/src/rest/v0/network/mod.rs b/jcli-lib/src/rest/v0/network/mod.rs index 108f55b976..f7dc730493 100644 --- a/jcli-lib/src/rest/v0/network/mod.rs +++ b/jcli-lib/src/rest/v0/network/mod.rs @@ -2,10 +2,14 @@ mod stats; use self::stats::Stats; use crate::rest::Error; +#[cfg(feature = "structopt")] use structopt::StructOpt; -#[derive(StructOpt)] -#[structopt(rename_all = "kebab-case")] +#[cfg_attr( + feature = "structopt", + derive(StructOpt), + structopt(rename_all = "kebab-case") +)] pub enum Network { /// Network information Stats(Stats), diff --git a/jcli-lib/src/rest/v0/network/stats.rs b/jcli-lib/src/rest/v0/network/stats.rs index 7118dd08c7..b6055efb66 100644 --- a/jcli-lib/src/rest/v0/network/stats.rs +++ b/jcli-lib/src/rest/v0/network/stats.rs @@ -1,15 +1,19 @@ use crate::rest::{Error, RestArgs}; use crate::utils::OutputFormat; +#[cfg(feature = "structopt")] use structopt::StructOpt; -#[derive(StructOpt)] -#[structopt(rename_all = "kebab-case")] +#[cfg_attr( + feature = "structopt", + derive(StructOpt), + structopt(rename_all = "kebab-case") +)] pub enum Stats { /// Get network information Get { - #[structopt(flatten)] + #[cfg_attr(feature = "structopt", structopt(flatten))] args: RestArgs, - #[structopt(flatten)] + #[cfg_attr(feature = "structopt", structopt(flatten))] output_format: OutputFormat, }, } diff --git a/jcli-lib/src/rest/v0/node/mod.rs b/jcli-lib/src/rest/v0/node/mod.rs index 90dbf9e3ff..04acc26f72 100644 --- a/jcli-lib/src/rest/v0/node/mod.rs +++ b/jcli-lib/src/rest/v0/node/mod.rs @@ -2,10 +2,14 @@ mod stats; use self::stats::Stats; use crate::rest::Error; +#[cfg(feature = "structopt")] use structopt::StructOpt; -#[derive(StructOpt)] -#[structopt(rename_all = "kebab-case")] +#[cfg_attr( + feature = "structopt", + derive(StructOpt), + structopt(rename_all = "kebab-case") +)] pub enum Node { /// Node information Stats(Stats), diff --git a/jcli-lib/src/rest/v0/node/stats.rs b/jcli-lib/src/rest/v0/node/stats.rs index 30632069c3..5979f90542 100644 --- a/jcli-lib/src/rest/v0/node/stats.rs +++ b/jcli-lib/src/rest/v0/node/stats.rs @@ -1,15 +1,19 @@ use crate::rest::{Error, RestArgs}; use crate::utils::OutputFormat; +#[cfg(feature = "structopt")] use structopt::StructOpt; -#[derive(StructOpt)] -#[structopt(rename_all = "kebab-case")] +#[cfg_attr( + feature = "structopt", + derive(StructOpt), + structopt(rename_all = "kebab-case") +)] pub enum Stats { /// Get node information Get { - #[structopt(flatten)] + #[cfg_attr(feature = "structopt", structopt(flatten))] args: RestArgs, - #[structopt(flatten)] + #[cfg_attr(feature = "structopt", structopt(flatten))] output_format: OutputFormat, }, } diff --git a/jcli-lib/src/rest/v0/rewards/epoch.rs b/jcli-lib/src/rest/v0/rewards/epoch.rs index c4f19a24ed..1ac4787411 100644 --- a/jcli-lib/src/rest/v0/rewards/epoch.rs +++ b/jcli-lib/src/rest/v0/rewards/epoch.rs @@ -1,12 +1,16 @@ use crate::rest::{Error, RestArgs}; +#[cfg(feature = "structopt")] use structopt::StructOpt; -#[derive(StructOpt)] -#[structopt(rename_all = "kebab-case")] +#[cfg_attr( + feature = "structopt", + derive(StructOpt), + structopt(rename_all = "kebab-case") +)] pub enum Epoch { /// Get rewards for epoch Get { - #[structopt(flatten)] + #[cfg_attr(feature = "structopt", structopt(flatten))] args: RestArgs, /// Epoch number epoch: u32, diff --git a/jcli-lib/src/rest/v0/rewards/history.rs b/jcli-lib/src/rest/v0/rewards/history.rs index dc84e59b1c..c742372f74 100644 --- a/jcli-lib/src/rest/v0/rewards/history.rs +++ b/jcli-lib/src/rest/v0/rewards/history.rs @@ -1,12 +1,16 @@ use crate::rest::{Error, RestArgs}; +#[cfg(feature = "structopt")] use structopt::StructOpt; -#[derive(StructOpt)] -#[structopt(rename_all = "kebab-case")] +#[cfg_attr( + feature = "structopt", + derive(StructOpt), + structopt(rename_all = "kebab-case") +)] pub enum History { /// Get rewards for one or more epochs Get { - #[structopt(flatten)] + #[cfg_attr(feature = "structopt", structopt(flatten))] args: RestArgs, /// Number of epochs length: usize, diff --git a/jcli-lib/src/rest/v0/rewards/mod.rs b/jcli-lib/src/rest/v0/rewards/mod.rs index e93e4e34c0..90855942b3 100644 --- a/jcli-lib/src/rest/v0/rewards/mod.rs +++ b/jcli-lib/src/rest/v0/rewards/mod.rs @@ -5,10 +5,14 @@ use self::epoch::Epoch; use self::history::History; use crate::rest::Error; +#[cfg(feature = "structopt")] use structopt::StructOpt; -#[derive(StructOpt)] -#[structopt(name = "rewards", rename_all = "kebab-case")] +#[cfg_attr( + feature = "structopt", + derive(StructOpt), + structopt(name = "rewards", rename_all = "kebab-case") +)] pub enum Rewards { /// Rewards distribution history one or more epochs starting from the last one History(History), diff --git a/jcli-lib/src/rest/v0/settings/mod.rs b/jcli-lib/src/rest/v0/settings/mod.rs index 29caac2897..ef6d3356ac 100644 --- a/jcli-lib/src/rest/v0/settings/mod.rs +++ b/jcli-lib/src/rest/v0/settings/mod.rs @@ -1,15 +1,19 @@ use crate::rest::{Error, RestArgs}; use crate::utils::OutputFormat; +#[cfg(feature = "structopt")] use structopt::StructOpt; -#[derive(StructOpt)] -#[structopt(rename_all = "kebab-case")] +#[cfg_attr( + feature = "structopt", + derive(StructOpt), + structopt(rename_all = "kebab-case") +)] pub enum Settings { /// Get node settings Get { - #[structopt(flatten)] + #[cfg_attr(feature = "structopt", structopt(flatten))] args: RestArgs, - #[structopt(flatten)] + #[cfg_attr(feature = "structopt", structopt(flatten))] output_format: OutputFormat, }, } diff --git a/jcli-lib/src/rest/v0/shutdown/mod.rs b/jcli-lib/src/rest/v0/shutdown/mod.rs index 310f6d21a6..336e0dbd9c 100644 --- a/jcli-lib/src/rest/v0/shutdown/mod.rs +++ b/jcli-lib/src/rest/v0/shutdown/mod.rs @@ -1,12 +1,16 @@ use crate::rest::{Error, RestArgs}; +#[cfg(feature = "structopt")] use structopt::StructOpt; /// Shutdown node -#[derive(StructOpt)] -#[structopt(rename_all = "kebab-case")] +#[cfg_attr( + feature = "structopt", + derive(StructOpt), + structopt(rename_all = "kebab-case") +)] pub enum Shutdown { Post { - #[structopt(flatten)] + #[cfg_attr(feature = "structopt", structopt(flatten))] args: RestArgs, }, } diff --git a/jcli-lib/src/rest/v0/stake/mod.rs b/jcli-lib/src/rest/v0/stake/mod.rs index dafca5ebc5..c1214a809d 100644 --- a/jcli-lib/src/rest/v0/stake/mod.rs +++ b/jcli-lib/src/rest/v0/stake/mod.rs @@ -1,15 +1,19 @@ use crate::rest::{Error, RestArgs}; use crate::utils::OutputFormat; +#[cfg(feature = "structopt")] use structopt::StructOpt; -#[derive(StructOpt)] -#[structopt(rename_all = "kebab-case")] +#[cfg_attr( + feature = "structopt", + derive(StructOpt), + structopt(rename_all = "kebab-case") +)] pub enum Stake { /// Get stake distribution Get { - #[structopt(flatten)] + #[cfg_attr(feature = "structopt", structopt(flatten))] args: RestArgs, - #[structopt(flatten)] + #[cfg_attr(feature = "structopt", structopt(flatten))] output_format: OutputFormat, /// Epoch to get the stake distribution from epoch: Option, diff --git a/jcli-lib/src/rest/v0/stake_pool/mod.rs b/jcli-lib/src/rest/v0/stake_pool/mod.rs index e524f0e162..045223e751 100644 --- a/jcli-lib/src/rest/v0/stake_pool/mod.rs +++ b/jcli-lib/src/rest/v0/stake_pool/mod.rs @@ -1,17 +1,21 @@ use crate::rest::{Error, RestArgs}; use crate::utils::OutputFormat; +#[cfg(feature = "structopt")] use structopt::StructOpt; -#[derive(StructOpt)] -#[structopt(rename_all = "kebab-case")] +#[cfg_attr( + feature = "structopt", + derive(StructOpt), + structopt(rename_all = "kebab-case") +)] pub enum StakePool { /// Get stake pool details Get { - #[structopt(flatten)] + #[cfg_attr(feature = "structopt", structopt(flatten))] args: RestArgs, /// hex-encoded pool ID pool_id: String, - #[structopt(flatten)] + #[cfg_attr(feature = "structopt", structopt(flatten))] output_format: OutputFormat, }, } diff --git a/jcli-lib/src/rest/v0/stake_pools/mod.rs b/jcli-lib/src/rest/v0/stake_pools/mod.rs index aa5d91f71a..ef5e7b7282 100644 --- a/jcli-lib/src/rest/v0/stake_pools/mod.rs +++ b/jcli-lib/src/rest/v0/stake_pools/mod.rs @@ -1,15 +1,19 @@ use crate::rest::{Error, RestArgs}; use crate::utils::OutputFormat; +#[cfg(feature = "structopt")] use structopt::StructOpt; -#[derive(StructOpt)] -#[structopt(rename_all = "kebab-case")] +#[cfg_attr( + feature = "structopt", + derive(StructOpt), + structopt(rename_all = "kebab-case") +)] pub enum StakePools { /// Get stake pool IDs Get { - #[structopt(flatten)] + #[cfg_attr(feature = "structopt", structopt(flatten))] args: RestArgs, - #[structopt(flatten)] + #[cfg_attr(feature = "structopt", structopt(flatten))] output_format: OutputFormat, }, } diff --git a/jcli-lib/src/rest/v0/tip/mod.rs b/jcli-lib/src/rest/v0/tip/mod.rs index 48b617eae2..02150134df 100644 --- a/jcli-lib/src/rest/v0/tip/mod.rs +++ b/jcli-lib/src/rest/v0/tip/mod.rs @@ -1,12 +1,16 @@ use crate::rest::{Error, RestArgs}; +#[cfg(feature = "structopt")] use structopt::StructOpt; -#[derive(StructOpt)] -#[structopt(rename_all = "kebab-case")] +#[cfg_attr( + feature = "structopt", + derive(StructOpt), + structopt(rename_all = "kebab-case") +)] pub enum Tip { /// Get tip ID Get { - #[structopt(flatten)] + #[cfg_attr(feature = "structopt", structopt(flatten))] args: RestArgs, }, } diff --git a/jcli-lib/src/rest/v0/utxo/mod.rs b/jcli-lib/src/rest/v0/utxo/mod.rs index a71c3e75e8..fd98addef5 100644 --- a/jcli-lib/src/rest/v0/utxo/mod.rs +++ b/jcli-lib/src/rest/v0/utxo/mod.rs @@ -1,9 +1,13 @@ use crate::rest::{Error, RestArgs}; use crate::utils::OutputFormat; +#[cfg(feature = "structopt")] use structopt::StructOpt; -#[derive(StructOpt)] -#[structopt(rename_all = "kebab-case")] +#[cfg_attr( + feature = "structopt", + derive(StructOpt), + structopt(rename_all = "kebab-case") +)] pub struct Utxo { /// hex-encoded ID of the transaction fragment fragment_id: String, @@ -11,19 +15,22 @@ pub struct Utxo { /// index of the transaction output output_index: u8, - #[structopt(subcommand)] + #[cfg_attr(feature = "structopt", structopt(subcommand))] subcommand: Subcommand, } -#[derive(StructOpt)] -#[structopt(rename_all = "kebab-case")] +#[cfg_attr( + feature = "structopt", + derive(StructOpt), + structopt(rename_all = "kebab-case") +)] enum Subcommand { /// Get UTxO details Get { - #[structopt(flatten)] + #[cfg_attr(feature = "structopt", structopt(flatten))] output_format: OutputFormat, - #[structopt(flatten)] + #[cfg_attr(feature = "structopt", structopt(flatten))] args: RestArgs, }, } diff --git a/jcli-lib/src/rest/v0/vote/active.rs b/jcli-lib/src/rest/v0/vote/active.rs index bf95c61150..0332b3489f 100644 --- a/jcli-lib/src/rest/v0/vote/active.rs +++ b/jcli-lib/src/rest/v0/vote/active.rs @@ -1,9 +1,13 @@ use super::{committees::Committees, plans::Plans}; use crate::rest::Error; +#[cfg(feature = "structopt")] use structopt::StructOpt; -#[derive(StructOpt)] -#[structopt(rename_all = "kebab-case")] +#[cfg_attr( + feature = "structopt", + derive(StructOpt), + structopt(rename_all = "kebab-case") +)] pub enum Active { /// Committee members Committees(Committees), diff --git a/jcli-lib/src/rest/v0/vote/committees.rs b/jcli-lib/src/rest/v0/vote/committees.rs index 079fd2013f..1cf2cb889c 100644 --- a/jcli-lib/src/rest/v0/vote/committees.rs +++ b/jcli-lib/src/rest/v0/vote/committees.rs @@ -1,15 +1,19 @@ use crate::rest::{Error, RestArgs}; use crate::utils::OutputFormat; +#[cfg(feature = "structopt")] use structopt::StructOpt; -#[derive(StructOpt)] -#[structopt(rename_all = "kebab-case")] +#[cfg_attr( + feature = "structopt", + derive(StructOpt), + structopt(rename_all = "kebab-case") +)] pub enum Committees { /// Get committee members list Get { - #[structopt(flatten)] + #[cfg_attr(feature = "structopt", structopt(flatten))] args: RestArgs, - #[structopt(flatten)] + #[cfg_attr(feature = "structopt", structopt(flatten))] output_format: OutputFormat, }, } diff --git a/jcli-lib/src/rest/v0/vote/mod.rs b/jcli-lib/src/rest/v0/vote/mod.rs index a20f9b8609..9599d2b09b 100644 --- a/jcli-lib/src/rest/v0/vote/mod.rs +++ b/jcli-lib/src/rest/v0/vote/mod.rs @@ -4,10 +4,14 @@ mod plans; use self::active::Active; use crate::rest::Error; +#[cfg(feature = "structopt")] use structopt::StructOpt; -#[derive(StructOpt)] -#[structopt(name = "active", rename_all = "kebab-case")] +#[cfg_attr( + feature = "structopt", + derive(StructOpt), + structopt(name = "active", rename_all = "kebab-case") +)] pub enum Vote { /// Active vote related operations Active(Active), diff --git a/jcli-lib/src/rest/v0/vote/plans.rs b/jcli-lib/src/rest/v0/vote/plans.rs index e9e6704155..05f3fe640b 100644 --- a/jcli-lib/src/rest/v0/vote/plans.rs +++ b/jcli-lib/src/rest/v0/vote/plans.rs @@ -1,15 +1,19 @@ use crate::rest::{Error, RestArgs}; use crate::utils::OutputFormat; +#[cfg(feature = "structopt")] use structopt::StructOpt; -#[derive(StructOpt)] -#[structopt(rename_all = "kebab-case")] +#[cfg_attr( + feature = "structopt", + derive(StructOpt), + structopt(rename_all = "kebab-case") +)] pub enum Plans { /// Get active vote plans list Get { - #[structopt(flatten)] + #[cfg_attr(feature = "structopt", structopt(flatten))] args: RestArgs, - #[structopt(flatten)] + #[cfg_attr(feature = "structopt", structopt(flatten))] output_format: OutputFormat, }, } From a0bce019e57a7e1a35babda116acb1c20d83d45e Mon Sep 17 00:00:00 2001 From: Filip Dulic Date: Wed, 14 Apr 2021 14:49:22 -0500 Subject: [PATCH 17/25] feature gate structopt attributes for jcli_lib::transaction::* --- jcli-lib/src/transaction/add_account.rs | 14 ++++--- jcli-lib/src/transaction/add_certificate.rs | 10 +++-- jcli-lib/src/transaction/add_input.rs | 16 +++++--- jcli-lib/src/transaction/add_output.rs | 14 ++++--- jcli-lib/src/transaction/add_witness.rs | 10 +++-- jcli-lib/src/transaction/auth.rs | 12 ++++-- jcli-lib/src/transaction/common.rs | 45 +++++++++++++++------ jcli-lib/src/transaction/finalize.rs | 12 ++++-- jcli-lib/src/transaction/info.rs | 21 ++++++---- jcli-lib/src/transaction/mk_witness.rs | 19 ++++++--- jcli-lib/src/transaction/mod.rs | 8 +++- jcli-lib/src/transaction/new.rs | 10 +++-- jcli-lib/src/transaction/seal.rs | 10 +++-- 13 files changed, 137 insertions(+), 64 deletions(-) diff --git a/jcli-lib/src/transaction/add_account.rs b/jcli-lib/src/transaction/add_account.rs index 0a17adf0a4..d715305596 100644 --- a/jcli-lib/src/transaction/add_account.rs +++ b/jcli-lib/src/transaction/add_account.rs @@ -2,20 +2,24 @@ use crate::transaction::{common, Error}; use chain_addr::{Address, Kind}; use chain_impl_mockchain::transaction::UnspecifiedAccountIdentifier; use jormungandr_lib::interfaces; +#[cfg(feature = "structopt")] use structopt::StructOpt; -#[derive(StructOpt)] -#[structopt(rename_all = "kebab-case")] +#[cfg_attr( + feature = "structopt", + derive(StructOpt), + structopt(rename_all = "kebab-case") +)] pub struct AddAccount { - #[structopt(flatten)] + #[cfg_attr(feature = "structopt", structopt(flatten))] pub common: common::CommonTransaction, /// the account to debit the funds from - #[structopt(name = "ACCOUNT")] + #[cfg_attr(feature = "structopt", structopt(name = "ACCOUNT"))] pub account: interfaces::Address, /// the value - #[structopt(name = "VALUE")] + #[cfg_attr(feature = "structopt", structopt(name = "VALUE"))] pub value: interfaces::Value, } diff --git a/jcli-lib/src/transaction/add_certificate.rs b/jcli-lib/src/transaction/add_certificate.rs index ac72447fb6..f5cae9649a 100644 --- a/jcli-lib/src/transaction/add_certificate.rs +++ b/jcli-lib/src/transaction/add_certificate.rs @@ -1,11 +1,15 @@ use crate::transaction::{common, Error}; use jormungandr_lib::interfaces::Certificate; +#[cfg(feature = "structopt")] use structopt::StructOpt; -#[derive(StructOpt)] -#[structopt(rename_all = "kebab-case")] +#[cfg_attr( + feature = "structopt", + derive(StructOpt), + structopt(rename_all = "kebab-case") +)] pub struct AddCertificate { - #[structopt(flatten)] + #[cfg_attr(feature = "structopt", structopt(flatten))] pub common: common::CommonTransaction, /// bech32-encoded certificate diff --git a/jcli-lib/src/transaction/add_input.rs b/jcli-lib/src/transaction/add_input.rs index f7dafaba03..5a3ceed6c4 100644 --- a/jcli-lib/src/transaction/add_input.rs +++ b/jcli-lib/src/transaction/add_input.rs @@ -1,24 +1,28 @@ use crate::transaction::{common, Error}; use chain_impl_mockchain::{fragment::FragmentId, transaction::TransactionIndex}; use jormungandr_lib::interfaces; +#[cfg(feature = "structopt")] use structopt::StructOpt; -#[derive(StructOpt)] -#[structopt(rename_all = "kebab-case")] +#[cfg_attr( + feature = "structopt", + derive(StructOpt), + structopt(rename_all = "kebab-case") +)] pub struct AddInput { - #[structopt(flatten)] + #[cfg_attr(feature = "structopt", structopt(flatten))] pub common: common::CommonTransaction, /// the Transaction ID which contains the credited funds to utilise. - #[structopt(name = "TRANSACTION_ID")] + #[cfg_attr(feature = "structopt", structopt(name = "TRANSACTION_ID"))] pub transaction_id: FragmentId, /// the output index where the credited funds to utilise are. - #[structopt(name = "INDEX")] + #[cfg_attr(feature = "structopt", structopt(name = "INDEX"))] pub index: TransactionIndex, /// the value - #[structopt(name = "VALUE")] + #[cfg_attr(feature = "structopt", structopt(name = "VALUE"))] pub value: interfaces::Value, } diff --git a/jcli-lib/src/transaction/add_output.rs b/jcli-lib/src/transaction/add_output.rs index 3fd8951257..072a5bb22c 100644 --- a/jcli-lib/src/transaction/add_output.rs +++ b/jcli-lib/src/transaction/add_output.rs @@ -1,20 +1,24 @@ use crate::transaction::{common, Error}; use chain_impl_mockchain::transaction::Output; use jormungandr_lib::interfaces; +#[cfg(feature = "structopt")] use structopt::StructOpt; -#[derive(StructOpt)] -#[structopt(rename_all = "kebab-case")] +#[cfg_attr( + feature = "structopt", + derive(StructOpt), + structopt(rename_all = "kebab-case") +)] pub struct AddOutput { - #[structopt(flatten)] + #[cfg_attr(feature = "structopt", structopt(flatten))] pub common: common::CommonTransaction, /// the UTxO address or account address to credit funds to - #[structopt(name = "ADDRESS")] + #[cfg_attr(feature = "structopt", structopt(name = "ADDRESS"))] pub address: interfaces::Address, /// the value - #[structopt(name = "VALUE")] + #[cfg_attr(feature = "structopt", structopt(name = "VALUE"))] pub value: interfaces::Value, } diff --git a/jcli-lib/src/transaction/add_witness.rs b/jcli-lib/src/transaction/add_witness.rs index adf455370c..6dd2e85ed5 100644 --- a/jcli-lib/src/transaction/add_witness.rs +++ b/jcli-lib/src/transaction/add_witness.rs @@ -6,12 +6,16 @@ use bech32::{self, FromBase32 as _}; use chain_core::mempack::{ReadBuf, Readable as _}; use chain_impl_mockchain::transaction::Witness; use std::path::PathBuf; +#[cfg(feature = "structopt")] use structopt::StructOpt; -#[derive(StructOpt)] -#[structopt(rename_all = "kebab-case")] +#[cfg_attr( + feature = "structopt", + derive(StructOpt), + structopt(rename_all = "kebab-case") +)] pub struct AddWitness { - #[structopt(flatten)] + #[cfg_attr(feature = "structopt", structopt(flatten))] pub common: common::CommonTransaction, pub witness: PathBuf, diff --git a/jcli-lib/src/transaction/auth.rs b/jcli-lib/src/transaction/auth.rs index edc024655b..e653dd2ca5 100644 --- a/jcli-lib/src/transaction/auth.rs +++ b/jcli-lib/src/transaction/auth.rs @@ -3,15 +3,19 @@ use crate::{ transaction::{common, Error}, }; use std::path::PathBuf; +#[cfg(feature = "structopt")] use structopt::StructOpt; -#[derive(StructOpt)] -#[structopt(rename_all = "kebab-case")] +#[cfg_attr( + feature = "structopt", + derive(StructOpt), + structopt(rename_all = "kebab-case") +)] pub struct Auth { - #[structopt(flatten)] + #[cfg_attr(feature = "structopt", structopt(flatten))] pub common: common::CommonTransaction, /// path to the file with the signing key - #[structopt(short = "k", long = "key")] + #[cfg_attr(feature = "structopt", structopt(short = "k", long = "key"))] pub signing_keys: Vec, } diff --git a/jcli-lib/src/transaction/common.rs b/jcli-lib/src/transaction/common.rs index c8f5a593c4..b5a730d21d 100644 --- a/jcli-lib/src/transaction/common.rs +++ b/jcli-lib/src/transaction/common.rs @@ -1,46 +1,65 @@ use crate::transaction::{staging::Staging, Error}; use chain_impl_mockchain::fee::{LinearFee, PerCertificateFee, PerVoteCertificateFee}; use std::{num::NonZeroU64, path::PathBuf}; +#[cfg(feature = "structopt")] use structopt::StructOpt; -#[derive(StructOpt)] -#[structopt(rename_all = "kebab-case")] +#[cfg_attr( + feature = "structopt", + derive(StructOpt), + structopt(rename_all = "kebab-case") +)] pub struct CommonFees { /// fee per transaction - #[structopt(long = "fee-constant", default_value = "0")] + #[cfg_attr( + feature = "structopt", + structopt(long = "fee-constant", default_value = "0") + )] pub constant: u64, /// fee per every input and output - #[structopt(long = "fee-coefficient", default_value = "0")] + #[cfg_attr( + feature = "structopt", + structopt(long = "fee-coefficient", default_value = "0") + )] pub coefficient: u64, /// fee per certificate - #[structopt(long = "fee-certificate", default_value = "0")] + #[cfg_attr( + feature = "structopt", + structopt(long = "fee-certificate", default_value = "0") + )] pub certificate: u64, /// fee per pool registration (default: fee-certificate) - #[structopt(long = "fee-pool-registration")] + #[cfg_attr(feature = "structopt", structopt(long = "fee-pool-registration"))] pub certificate_pool_registration: Option, /// fee per stake delegation (default: fee-certificate) - #[structopt(long = "fee-stake-delegation")] + #[cfg_attr(feature = "structopt", structopt(long = "fee-stake-delegation"))] pub certificate_stake_delegation: Option, /// fee per owner stake delegation (default: fee-certificate) - #[structopt(long = "fee-owner-stake-delegation")] + #[cfg_attr(feature = "structopt", structopt(long = "fee-owner-stake-delegation"))] pub certificate_owner_stake_delegation: Option, /// fee per vote plan - #[structopt(long = "fee-vote-plan")] + #[cfg_attr(feature = "structopt", structopt(long = "fee-vote-plan"))] pub certificate_vote_plan: Option, /// fee per vote cast - #[structopt(long = "fee-vote-cast")] + #[cfg_attr(feature = "structopt", structopt(long = "fee-vote-cast"))] pub certificate_vote_cast: Option, } -#[derive(StructOpt)] -#[structopt(rename_all = "kebab-case")] +#[cfg_attr( + feature = "structopt", + derive(StructOpt), + structopt(rename_all = "kebab-case") +)] pub struct CommonTransaction { /// place where the transaction is going to be save during its staging phase /// If a file is given, the transaction will be read from this file and /// modification will be written into this same file. /// If no file is given, the transaction will be read from the standard /// input and will be rendered in the standard output - #[structopt(long = "staging", alias = "transaction")] + #[cfg_attr( + feature = "structopt", + structopt(long = "staging", alias = "transaction") + )] pub staging_file: Option, } diff --git a/jcli-lib/src/transaction/finalize.rs b/jcli-lib/src/transaction/finalize.rs index 85c8964acd..4959ec23b0 100644 --- a/jcli-lib/src/transaction/finalize.rs +++ b/jcli-lib/src/transaction/finalize.rs @@ -1,15 +1,19 @@ use crate::transaction::{common, Error}; use chain_impl_mockchain::transaction::OutputPolicy; use jormungandr_lib::interfaces; +#[cfg(feature = "structopt")] use structopt::StructOpt; -#[derive(StructOpt)] -#[structopt(rename_all = "kebab-case")] +#[cfg_attr( + feature = "structopt", + derive(StructOpt), + structopt(rename_all = "kebab-case") +)] pub struct Finalize { - #[structopt(flatten)] + #[cfg_attr(feature = "structopt", structopt(flatten))] pub common: common::CommonTransaction, - #[structopt(flatten)] + #[cfg_attr(feature = "structopt", structopt(flatten))] pub fee: common::CommonFees, /// Set the change in the given address diff --git a/jcli-lib/src/transaction/info.rs b/jcli-lib/src/transaction/info.rs index fc80523d6a..1caaedc5cd 100644 --- a/jcli-lib/src/transaction/info.rs +++ b/jcli-lib/src/transaction/info.rs @@ -7,26 +7,33 @@ use chain_impl_mockchain::transaction::{Balance, UnspecifiedAccountIdentifier}; use jormungandr_lib::{crypto::hash::Hash, interfaces::TransactionInputType}; use serde_json::json; use std::{io::Write, path::PathBuf}; +#[cfg(feature = "structopt")] use structopt::StructOpt; -#[derive(StructOpt)] -#[structopt(rename_all = "kebab-case")] +#[cfg_attr( + feature = "structopt", + derive(StructOpt), + structopt(rename_all = "kebab-case") +)] pub struct Info { - #[structopt(flatten)] + #[cfg_attr(feature = "structopt", structopt(flatten))] common: common::CommonTransaction, - #[structopt(flatten)] + #[cfg_attr(feature = "structopt", structopt(flatten))] fee: common::CommonFees, /// write the info in the given file or print it to the standard output - #[structopt(long = "output")] + #[cfg_attr(feature = "structopt", structopt(long = "output"))] output: Option, - #[structopt(flatten)] + #[cfg_attr(feature = "structopt", structopt(flatten))] output_format: OutputFormat, /// set the address prefix to use when displaying the addresses - #[structopt(long = "prefix", default_value = "ca")] + #[cfg_attr( + feature = "structopt", + structopt(long = "prefix", default_value = "ca") + )] address_prefix: String, } diff --git a/jcli-lib/src/transaction/mk_witness.rs b/jcli-lib/src/transaction/mk_witness.rs index 9d55d8985c..44d19794a7 100644 --- a/jcli-lib/src/transaction/mk_witness.rs +++ b/jcli-lib/src/transaction/mk_witness.rs @@ -10,13 +10,17 @@ use chain_impl_mockchain::{ transaction::{TransactionSignDataHash, Witness}, }; use std::{io::Write, path::PathBuf}; +#[cfg(feature = "structopt")] use structopt::StructOpt; -#[derive(StructOpt)] -#[structopt(rename_all = "kebab-case")] +#[cfg_attr( + feature = "structopt", + derive(StructOpt), + structopt(rename_all = "kebab-case") +)] pub struct MkWitness { /// the Transaction ID of the witness to sign - #[structopt(name = "TRANSACTION_ID")] + #[cfg_attr(feature = "structopt", structopt(name = "TRANSACTION_ID"))] pub sign_data_hash: TransactionSignDataHash, /// the file path to the file to write the witness in. @@ -24,16 +28,19 @@ pub struct MkWitness { pub output: Option, /// the type of witness to build: account, UTxO or Legacy UtxO - #[structopt(long = "type", parse(try_from_str))] + #[cfg_attr(feature = "structopt", structopt(long = "type", parse(try_from_str)))] pub witness_type: WitnessType, /// the hash of the block0, the first block of the blockchain - #[structopt(long = "genesis-block-hash", parse(try_from_str))] + #[cfg_attr( + feature = "structopt", + structopt(long = "genesis-block-hash", parse(try_from_str)) + )] pub genesis_block_hash: HeaderId, /// value is mandatory is `--type=account' It is the counter for /// every time the account is being utilized. - #[structopt(long = "account-spending-counter")] + #[cfg_attr(feature = "structopt", structopt(long = "account-spending-counter"))] pub account_spending_counter: Option, /// the file path to the file to read the signing key from. diff --git a/jcli-lib/src/transaction/mod.rs b/jcli-lib/src/transaction/mod.rs index 364c3a6da7..765c094906 100644 --- a/jcli-lib/src/transaction/mod.rs +++ b/jcli-lib/src/transaction/mod.rs @@ -20,12 +20,16 @@ use crate::{ use chain_core::property::Serialize as _; use chain_impl_mockchain as chain; use std::path::PathBuf; +#[cfg(feature = "structopt")] use structopt::StructOpt; use thiserror::Error; #[allow(clippy::large_enum_variant)] -#[derive(StructOpt)] -#[structopt(rename_all = "kebab-case")] +#[cfg_attr( + feature = "structopt", + derive(StructOpt), + structopt(rename_all = "kebab-case") +)] pub enum Transaction { /// create a new staging transaction. The transaction is initially /// empty. diff --git a/jcli-lib/src/transaction/new.rs b/jcli-lib/src/transaction/new.rs index ffe1d664e3..c163253d84 100644 --- a/jcli-lib/src/transaction/new.rs +++ b/jcli-lib/src/transaction/new.rs @@ -1,11 +1,15 @@ +#[cfg(feature = "structopt")] use structopt::StructOpt; use crate::transaction::{common, staging::Staging, Error}; -#[derive(StructOpt)] -#[structopt(rename_all = "kebab-case")] +#[cfg_attr( + feature = "structopt", + derive(StructOpt), + structopt(rename_all = "kebab-case") +)] pub struct New { - #[structopt(flatten)] + #[cfg_attr(feature = "structopt", structopt(flatten))] pub common: common::CommonTransaction, } diff --git a/jcli-lib/src/transaction/seal.rs b/jcli-lib/src/transaction/seal.rs index d98418c957..6f71a2df9b 100644 --- a/jcli-lib/src/transaction/seal.rs +++ b/jcli-lib/src/transaction/seal.rs @@ -1,10 +1,14 @@ use crate::transaction::{common, Error}; +#[cfg(feature = "structopt")] use structopt::StructOpt; -#[derive(StructOpt)] -#[structopt(rename_all = "kebab-case")] +#[cfg_attr( + feature = "structopt", + derive(StructOpt), + structopt(rename_all = "kebab-case") +)] pub struct Seal { - #[structopt(flatten)] + #[cfg_attr(feature = "structopt", structopt(flatten))] pub common: common::CommonTransaction, } From 5d2f1b4d514de79dd3ab083c4b3413ff391f83cd Mon Sep 17 00:00:00 2001 From: Filip Dulic Date: Wed, 14 Apr 2021 14:50:30 -0500 Subject: [PATCH 18/25] feature gate structopt attributes for jcli_lib::utils::* --- jcli-lib/src/utils/mod.rs | 14 +++++++++----- jcli-lib/src/utils/output_file.rs | 6 ++++-- jcli-lib/src/utils/output_format.rs | 8 ++++++-- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/jcli-lib/src/utils/mod.rs b/jcli-lib/src/utils/mod.rs index d463328cd9..6ca807c205 100644 --- a/jcli-lib/src/utils/mod.rs +++ b/jcli-lib/src/utils/mod.rs @@ -9,24 +9,28 @@ pub mod vote; pub use self::account_id::AccountId; pub use self::output_format::OutputFormat; +#[cfg(feature = "structopt")] use structopt::StructOpt; use thiserror::Error; -#[derive(StructOpt)] -#[structopt(name = "utils", rename_all = "kebab-case")] +#[cfg_attr(feature = "structopt", derive(StructOpt))] +#[cfg_attr( + feature = "structopt", + structopt(name = "utils", rename_all = "kebab-case") +)] pub enum Utils { /// convert a bech32 with hrp n into a bech32 with prefix m Bech32Convert(Bech32ConvertArgs), } -#[derive(StructOpt)] +#[cfg_attr(feature = "structopt", derive(StructOpt))] pub struct Bech32ConvertArgs { /// the bech32 you want to convert - #[structopt(name = "FROM_BECH32")] + #[cfg_attr(feature = "structopt", structopt(name = "FROM_BECH32"))] from_bech32: String, /// the new bech32 hrp you want to use - #[structopt(name = "NEW_PREFIX")] + #[cfg_attr(feature = "structopt", structopt(name = "NEW_PREFIX"))] new_hrp: String, } diff --git a/jcli-lib/src/utils/output_file.rs b/jcli-lib/src/utils/output_file.rs index 747b1f6587..0b9ad34c2f 100644 --- a/jcli-lib/src/utils/output_file.rs +++ b/jcli-lib/src/utils/output_file.rs @@ -1,5 +1,6 @@ use crate::utils::io; +#[cfg(feature = "structopt")] use structopt::StructOpt; use std::io::Write; @@ -15,10 +16,11 @@ pub enum Error { }, } -#[derive(StructOpt, Debug)] +#[derive(Debug)] +#[cfg_attr(feature = "structopt", derive(StructOpt))] pub struct OutputFile { /// output the key to the given file or to stdout if not provided - #[structopt(name = "OUTPUT_FILE")] + #[cfg_attr(feature = "structopt", structopt(name = "OUTPUT_FILE"))] output: Option, } diff --git a/jcli-lib/src/utils/output_format.rs b/jcli-lib/src/utils/output_format.rs index b0862abfb9..6edfefdf1e 100644 --- a/jcli-lib/src/utils/output_format.rs +++ b/jcli-lib/src/utils/output_format.rs @@ -1,15 +1,19 @@ use gtmpl::Value as GtmplValue; use serde_json::{Map as JsonMap, Number as JsonNumber, Value as JsonValue}; use std::fmt::{self, Display, Formatter}; +#[cfg(feature = "structopt")] use structopt::StructOpt; use thiserror::Error; -#[derive(StructOpt)] +#[cfg_attr(feature = "structopt", derive(StructOpt))] pub struct OutputFormat { /// Format of output data. Possible values: json, yaml. /// Any other value is treated as a custom format using values from output data structure. /// Syntax is Go text template: https://golang.org/pkg/text/template/. - #[structopt(long = "output-format", default_value = "yaml", parse(from_str))] + #[cfg_attr( + feature = "structopt", + structopt(long = "output-format", default_value = "yaml", parse(from_str)) + )] format: FormatVariant, } From 1fdb6b73b4aed4741455eff4b3d8ec6b2591b86b Mon Sep 17 00:00:00 2001 From: Filip Dulic Date: Wed, 14 Apr 2021 14:53:32 -0500 Subject: [PATCH 19/25] feature gate structopt attributes for jcli_lib::vote::* --- .../src/vote/committee/communication_key.rs | 26 +++++++++---- jcli-lib/src/vote/committee/member_key.rs | 39 ++++++++++++------- jcli-lib/src/vote/committee/mod.rs | 8 +++- jcli-lib/src/vote/common_reference_string.rs | 19 ++++++--- jcli-lib/src/vote/encrypting_vote_key.rs | 14 ++++--- jcli-lib/src/vote/mod.rs | 8 +++- jcli-lib/src/vote/tally/decrypt_shares.rs | 18 +++++---- jcli-lib/src/vote/tally/decryption_tally.rs | 21 ++++++---- jcli-lib/src/vote/tally/mod.rs | 8 +++- 9 files changed, 110 insertions(+), 51 deletions(-) diff --git a/jcli-lib/src/vote/committee/communication_key.rs b/jcli-lib/src/vote/committee/communication_key.rs index 08fda2b39f..514a99118a 100644 --- a/jcli-lib/src/vote/committee/communication_key.rs +++ b/jcli-lib/src/vote/committee/communication_key.rs @@ -5,35 +5,45 @@ use rand::rngs::OsRng; use rand_chacha::rand_core::SeedableRng; use rand_chacha::ChaCha20Rng; use std::{io::Write, path::PathBuf}; +#[cfg(feature = "structopt")] use structopt::StructOpt; -#[derive(StructOpt, Debug)] +#[derive(Debug)] +#[cfg_attr(feature = "structopt", derive(StructOpt))] pub struct Generate { - #[structopt(flatten)] + #[cfg_attr(feature = "structopt", structopt(flatten))] output_file: OutputFile, /// optional seed to generate the key, for the same entropy the same key /// will be generated (32 bytes in hexadecimal). This seed will be fed to /// ChaChaRNG and allow pseudo random key generation. Do not use if you /// are not sure. - #[structopt(long = "seed", short = "s", name = "SEED", parse(try_from_str))] + #[cfg_attr( + feature = "structopt", + structopt(long = "seed", short = "s", name = "SEED", parse(try_from_str)) + )] seed: Option, } -#[derive(StructOpt, Debug)] +#[derive(Debug)] +#[cfg_attr(feature = "structopt", derive(StructOpt))] pub struct ToPublic { /// The file with the private key to extract the public key from. /// If no value passed, the private key will be read from the /// standard input. - #[structopt(long = "input")] + #[cfg_attr(feature = "structopt", structopt(long = "input"))] input_key: Option, - #[structopt(flatten)] + #[cfg_attr(feature = "structopt", structopt(flatten))] output_file: OutputFile, } -#[derive(StructOpt, Debug)] -#[structopt(rename_all = "kebab-case")] +#[derive(Debug)] +#[cfg_attr( + feature = "structopt", + derive(StructOpt), + structopt(rename_all = "kebab-case") +)] pub enum CommunicationKey { /// generate a private key Generate(Generate), diff --git a/jcli-lib/src/vote/committee/member_key.rs b/jcli-lib/src/vote/committee/member_key.rs index 23a9899d79..defa1fef20 100644 --- a/jcli-lib/src/vote/committee/member_key.rs +++ b/jcli-lib/src/vote/committee/member_key.rs @@ -6,55 +6,68 @@ use rand::rngs::OsRng; use rand_chacha::rand_core::SeedableRng; use rand_chacha::ChaCha20Rng; use std::{convert::TryInto, io::Write, path::PathBuf}; +#[cfg(feature = "structopt")] use structopt::StructOpt; -#[derive(StructOpt)] +#[cfg_attr(feature = "structopt", derive(StructOpt))] pub struct Generate { /// threshold number of the committee members sufficient for /// decrypting the tally - #[structopt(long, short, name = "THRESHOLD", parse(try_from_str))] + #[cfg_attr( + feature = "structopt", + structopt(long, short, name = "THRESHOLD", parse(try_from_str)) + )] threshold: usize, /// the common reference string - #[structopt(long, name = "CRS", parse(try_from_str = parse_crs))] + #[cfg_attr(feature = "structopt", structopt(long, name = "CRS", parse(try_from_str = parse_crs)))] crs: chain_vote::CRS, /// communication keys of all committee members - #[structopt(long, short, name = "COMMUNICATION_KEYS", + #[cfg_attr(feature = "structopt", structopt(long, short, name = "COMMUNICATION_KEYS", parse(try_from_str = parse_member_communication_key), required = true, - )] + ))] keys: Vec, /// index of the committee member this key is generated for - #[structopt(long, short, name = "INDEX", parse(try_from_str))] + #[cfg_attr( + feature = "structopt", + structopt(long, short, name = "INDEX", parse(try_from_str)) + )] index: u64, /// optional seed to generate the key, for the same entropy the same key /// will be generated (32 bytes in hexadecimal). This seed will be fed to /// ChaChaRNG and allow pseudo random key generation. Do not use if you /// are not sure. - #[structopt(long = "seed", short = "s", name = "SEED", parse(try_from_str))] + #[cfg_attr( + feature = "structopt", + structopt(long = "seed", short = "s", name = "SEED", parse(try_from_str)) + )] seed: Option, - #[structopt(flatten)] + #[cfg_attr(feature = "structopt", structopt(flatten))] output_file: OutputFile, } -#[derive(StructOpt)] +#[cfg_attr(feature = "structopt", derive(StructOpt))] pub struct ToPublic { /// The file with the private key to extract the public key from. /// If no value passed, the private key will be read from the /// standard input. - #[structopt(long = "input")] + #[cfg_attr(feature = "structopt", structopt(long = "input"))] input_key: Option, - #[structopt(flatten)] + #[cfg_attr(feature = "structopt", structopt(flatten))] output_file: OutputFile, } -#[derive(StructOpt)] -#[structopt(rename_all = "kebab-case")] +#[cfg_attr( + feature = "structopt", + derive(StructOpt), + structopt(rename_all = "kebab-case") +)] pub enum MemberKey { /// generate a private key Generate(Generate), diff --git a/jcli-lib/src/vote/committee/mod.rs b/jcli-lib/src/vote/committee/mod.rs index 2984ae17ca..7f479eca1f 100644 --- a/jcli-lib/src/vote/committee/mod.rs +++ b/jcli-lib/src/vote/committee/mod.rs @@ -2,10 +2,14 @@ mod communication_key; mod member_key; use super::Error; +#[cfg(feature = "structopt")] use structopt::StructOpt; -#[derive(StructOpt)] -#[structopt(rename_all = "kebab-case")] +#[cfg_attr( + feature = "structopt", + derive(StructOpt), + structopt(rename_all = "kebab-case") +)] pub enum Committee { /// commands for managing committee member communication keys CommunicationKey(communication_key::CommunicationKey), diff --git a/jcli-lib/src/vote/common_reference_string.rs b/jcli-lib/src/vote/common_reference_string.rs index e4ade02de8..35d934d899 100644 --- a/jcli-lib/src/vote/common_reference_string.rs +++ b/jcli-lib/src/vote/common_reference_string.rs @@ -3,23 +3,32 @@ use rand::rngs::OsRng; use rand_chacha::rand_core::SeedableRng; use rand_chacha::ChaCha20Rng; use std::io::Write; +#[cfg(feature = "structopt")] use structopt::StructOpt; -#[derive(StructOpt, Debug)] +#[derive(Debug)] +#[cfg_attr(feature = "structopt", derive(StructOpt))] pub struct Generate { - #[structopt(flatten)] + #[cfg_attr(feature = "structopt", structopt(flatten))] output_file: OutputFile, /// optional seed to generate the key, for the same entropy the same key /// will be generated (32 bytes in hexadecimal). This seed will be fed to /// ChaChaRNG and allow pseudo random key generation. Do not use if you /// are not sure. - #[structopt(long = "seed", short = "s", name = "SEED", parse(try_from_str))] + #[cfg_attr( + feature = "structopt", + structopt(long = "seed", short = "s", name = "SEED", parse(try_from_str)) + )] seed: Option, } -#[derive(StructOpt, Debug)] -#[structopt(rename_all = "kebab-case")] +#[derive(Debug)] +#[cfg_attr( + feature = "structopt", + derive(StructOpt), + structopt(rename_all = "kebab-case") +)] pub enum Crs { /// generate the common reference string Generate(Generate), diff --git a/jcli-lib/src/vote/encrypting_vote_key.rs b/jcli-lib/src/vote/encrypting_vote_key.rs index 36f9551ac5..ef64a82151 100644 --- a/jcli-lib/src/vote/encrypting_vote_key.rs +++ b/jcli-lib/src/vote/encrypting_vote_key.rs @@ -1,21 +1,25 @@ use crate::vote::{Error, OutputFile}; use bech32::{FromBase32, ToBase32}; use std::io::Write as _; +#[cfg(feature = "structopt")] use structopt::StructOpt; -#[derive(StructOpt)] -#[structopt(rename_all = "kebab-case")] +#[cfg_attr( + feature = "structopt", + derive(StructOpt), + structopt(rename_all = "kebab-case") +)] pub struct EncryptingVoteKey { /// Keys of all committee members - #[structopt( + #[cfg_attr(feature = "structopt", structopt( parse(try_from_str = parse_member_key), required = true, short = "k", long = "keys" - )] + ))] member_keys: Vec, - #[structopt(flatten)] + #[cfg_attr(feature = "structopt", structopt(flatten))] output_file: OutputFile, } diff --git a/jcli-lib/src/vote/mod.rs b/jcli-lib/src/vote/mod.rs index 641ea6dfb8..b6743fa66f 100644 --- a/jcli-lib/src/vote/mod.rs +++ b/jcli-lib/src/vote/mod.rs @@ -7,6 +7,7 @@ mod common_reference_string; mod encrypting_vote_key; mod tally; +#[cfg(feature = "structopt")] use structopt::StructOpt; use thiserror::Error; @@ -57,8 +58,11 @@ pub enum Error { SharesError(#[from] SharesError), } -#[derive(StructOpt)] -#[structopt(rename_all = "kebab-case")] +#[cfg_attr( + feature = "structopt", + derive(StructOpt), + structopt(rename_all = "kebab-case") +)] pub enum Vote { /// Create committee member keys Committee(committee::Committee), diff --git a/jcli-lib/src/vote/tally/decrypt_shares.rs b/jcli-lib/src/vote/tally/decrypt_shares.rs index 0bb5a33431..1165533b1f 100644 --- a/jcli-lib/src/vote/tally/decrypt_shares.rs +++ b/jcli-lib/src/vote/tally/decrypt_shares.rs @@ -8,29 +8,33 @@ use rayon::prelude::*; use serde::Serialize; use std::convert::TryInto; use std::path::PathBuf; +#[cfg(feature = "structopt")] use structopt::StructOpt; -#[derive(StructOpt)] -#[structopt(rename_all = "kebab-case")] +#[cfg_attr( + feature = "structopt", + derive(StructOpt), + structopt(rename_all = "kebab-case") +)] pub struct TallyVotePlanWithAllShares { /// The path to json-encoded vote plan to decrypt. If this parameter is not /// specified, the vote plan will be read from the standard /// input. - #[structopt(long)] + #[cfg_attr(feature = "structopt", structopt(long))] vote_plan: Option, /// The id of the vote plan to decrypt. /// Can be left unspecified if there is only one vote plan in the input - #[structopt(long)] + #[cfg_attr(feature = "structopt", structopt(long))] vote_plan_id: Option, /// The minimum number of shares needed for decryption - #[structopt(long, default_value = "3")] + #[cfg_attr(feature = "structopt", structopt(long, default_value = "3"))] threshold: usize, /// The path to a JSON file containing decryption shares necessary to decrypt /// the vote plan. If this parameter is not specified, the shares will be read /// from the standard input. - #[structopt(long)] + #[cfg_attr(feature = "structopt", structopt(long))] shares: Option, - #[structopt(flatten)] + #[cfg_attr(feature = "structopt", structopt(flatten))] output_format: OutputFormat, } diff --git a/jcli-lib/src/vote/tally/decryption_tally.rs b/jcli-lib/src/vote/tally/decryption_tally.rs index 310a45ed00..999803b50c 100644 --- a/jcli-lib/src/vote/tally/decryption_tally.rs +++ b/jcli-lib/src/vote/tally/decryption_tally.rs @@ -8,25 +8,29 @@ use jormungandr_lib::interfaces::{PrivateTallyState, Tally}; use std::convert::TryFrom; use std::path::Path; use std::path::PathBuf; +#[cfg(feature = "structopt")] use structopt::StructOpt; /// Create decryption shares for all proposals in a vote plan. /// /// The decryption share data will be printed in hexadecimal encoding /// on standard output. -#[derive(StructOpt)] -#[structopt(rename_all = "kebab-case")] +#[cfg_attr( + feature = "structopt", + derive(StructOpt), + structopt(rename_all = "kebab-case") +)] pub struct TallyGenerateVotePlanDecryptionShares { /// The path to json-encoded vote plan to decrypt. If this parameter is not /// specified, the vote plan will be read from standard input. - #[structopt(long)] + #[cfg_attr(feature = "structopt", structopt(long))] vote_plan: Option, /// The id of the vote plan to decrypt. /// Can be left unspecified if there is only one vote plan in the input - #[structopt(long)] + #[cfg_attr(feature = "structopt", structopt(long))] vote_plan_id: Option, /// The path to hex-encoded decryption key. - #[structopt(long)] + #[cfg_attr(feature = "structopt", structopt(long))] key: PathBuf, } @@ -35,8 +39,11 @@ pub struct TallyGenerateVotePlanDecryptionShares { /// /// The data will be printed in hexadecimal encoding /// on standard output. -#[derive(StructOpt)] -#[structopt(rename_all = "kebab-case")] +#[cfg_attr( + feature = "structopt", + derive(StructOpt), + structopt(rename_all = "kebab-case") +)] pub struct MergeShares { /// The path to the shares to merge shares: Vec, diff --git a/jcli-lib/src/vote/tally/mod.rs b/jcli-lib/src/vote/tally/mod.rs index c0b5ceb278..0ce7faebfc 100644 --- a/jcli-lib/src/vote/tally/mod.rs +++ b/jcli-lib/src/vote/tally/mod.rs @@ -2,10 +2,14 @@ mod decrypt_shares; mod decryption_tally; use super::Error; +#[cfg(feature = "structopt")] use structopt::StructOpt; -#[derive(StructOpt)] -#[structopt(rename_all = "kebab-case")] +#[cfg_attr( + feature = "structopt", + derive(StructOpt), + structopt(rename_all = "kebab-case") +)] pub enum Tally { /// Create a decryption share for private voting tally. /// From 48ad2d84b5d236cbe5fe355a1df3086b7221f547 Mon Sep 17 00:00:00 2001 From: Filip Dulic Date: Wed, 14 Apr 2021 14:56:25 -0500 Subject: [PATCH 20/25] feature gate structopt attributes for top-level lib.rs --- jcli-lib/src/lib.rs | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/jcli-lib/src/lib.rs b/jcli-lib/src/lib.rs index 625c1ca213..0572efce13 100644 --- a/jcli-lib/src/lib.rs +++ b/jcli-lib/src/lib.rs @@ -11,29 +11,36 @@ pub mod vote; pub mod utils; use std::error::Error; +#[cfg(feature = "structopt")] use structopt::StructOpt; /// Jormungandr CLI toolkit -#[derive(StructOpt)] -#[structopt(rename_all = "kebab-case")] +#[cfg_attr( + feature = "structopt", + derive(StructOpt), + structopt(rename_all = "kebab-case") +)] pub struct JCli { /// display full version details (software version, source version, targets and compiler used) - #[structopt(long = "full-version")] + #[cfg_attr(feature = "structopt", structopt(long = "full-version"))] full_version: bool, /// display the sources version, allowing to check the source's hash used to compile this executable. /// this option is useful for scripting retrieving the logs of the version of this application. - #[structopt(long = "source-version")] + #[cfg_attr(feature = "structopt", structopt(long = "source-version"))] source_version: bool, - #[structopt(subcommand)] + #[cfg_attr(feature = "structopt", structopt(subcommand))] command: Option, } #[allow(clippy::large_enum_variant)] /// Jormungandr CLI toolkit -#[derive(StructOpt)] -#[structopt(rename_all = "kebab-case")] +#[cfg_attr( + feature = "structopt", + derive(StructOpt), + structopt(rename_all = "kebab-case") +)] pub enum JCliCommand { /// Key Generation Key(key::Key), @@ -49,7 +56,9 @@ pub enum JCliCommand { Debug(debug::Debug), /// Certificate generation tool Certificate(certificate::Certificate), - /// Auto completion + #[cfg(feature = "structopt")] + /// Auto completion. This variant is only present if the `structopt` + /// feature is enabled. AutoCompletion(auto_completion::AutoCompletion), /// Utilities that perform specialized tasks Utils(utils::Utils), @@ -84,6 +93,7 @@ impl JCliCommand { Transaction(transaction) => transaction.exec()?, Debug(debug) => debug.exec()?, Certificate(certificate) => certificate.exec()?, + #[cfg(feature = "structopt")] AutoCompletion(auto_completion) => auto_completion.exec::()?, Utils(utils) => utils.exec()?, Votes(vote) => vote.exec()?, From 0c0a6bb6c82b1b358f59063e21c7cbe8dd1744b4 Mon Sep 17 00:00:00 2001 From: Filip Dulic Date: Thu, 15 Apr 2021 15:27:21 -0500 Subject: [PATCH 21/25] feature gate auto_complete module --- jcli-lib/src/lib.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/jcli-lib/src/lib.rs b/jcli-lib/src/lib.rs index 0572efce13..ffde8ffd10 100644 --- a/jcli-lib/src/lib.rs +++ b/jcli-lib/src/lib.rs @@ -1,4 +1,6 @@ pub mod address; +#[cfg(feature = "structopt")] +// This module doesn't make sense without `structopt`. pub mod auto_completion; pub mod block; pub mod certificate; From 247030bf4886d0e8e03777dbbf722f022afd4bb3 Mon Sep 17 00:00:00 2001 From: Filip Dulic Date: Thu, 15 Apr 2021 15:28:19 -0500 Subject: [PATCH 22/25] add top-level docstrings to modules in crate --- jcli-lib/src/address.rs | 1 + jcli-lib/src/block/mod.rs | 1 + jcli-lib/src/certificate/mod.rs | 1 + jcli-lib/src/lib.rs | 4 ++-- jcli-lib/src/rest/mod.rs | 1 + 5 files changed, 6 insertions(+), 2 deletions(-) diff --git a/jcli-lib/src/address.rs b/jcli-lib/src/address.rs index 2d3bff60d3..aabaff27e7 100644 --- a/jcli-lib/src/address.rs +++ b/jcli-lib/src/address.rs @@ -1,3 +1,4 @@ +//! Bech32 segregated witness address tooling and helper. use crate::utils::key_parser::parse_pub_key; use chain_addr::{AddressReadable, Discrimination, Kind}; use chain_crypto::{bech32::Bech32 as _, AsymmetricPublicKey, Ed25519, PublicKey}; diff --git a/jcli-lib/src/block/mod.rs b/jcli-lib/src/block/mod.rs index 2cf8d21025..367c5afcce 100644 --- a/jcli-lib/src/block/mod.rs +++ b/jcli-lib/src/block/mod.rs @@ -1,3 +1,4 @@ +//! Chain-block tooling and helper. use crate::utils::io; use chain_core::property::{Block as _, Deserialize, Serialize}; use chain_impl_mockchain::{ diff --git a/jcli-lib/src/certificate/mod.rs b/jcli-lib/src/certificate/mod.rs index 66145c64c0..b20d65de00 100644 --- a/jcli-lib/src/certificate/mod.rs +++ b/jcli-lib/src/certificate/mod.rs @@ -1,3 +1,4 @@ +//! Certificate generation tool. mod new_encrypted_vote_tally; mod new_owner_stake_delegation; mod new_stake_delegation; diff --git a/jcli-lib/src/lib.rs b/jcli-lib/src/lib.rs index ffde8ffd10..53cf67b559 100644 --- a/jcli-lib/src/lib.rs +++ b/jcli-lib/src/lib.rs @@ -16,7 +16,7 @@ use std::error::Error; #[cfg(feature = "structopt")] use structopt::StructOpt; -/// Jormungandr CLI toolkit +/// Jormungandr Command-Line Interface (CLI) #[cfg_attr( feature = "structopt", derive(StructOpt), @@ -37,7 +37,7 @@ pub struct JCli { } #[allow(clippy::large_enum_variant)] -/// Jormungandr CLI toolkit +/// Jormungandr CLI sub-commands #[cfg_attr( feature = "structopt", derive(StructOpt), diff --git a/jcli-lib/src/rest/mod.rs b/jcli-lib/src/rest/mod.rs index 2b3607cbad..0d593282f1 100644 --- a/jcli-lib/src/rest/mod.rs +++ b/jcli-lib/src/rest/mod.rs @@ -1,3 +1,4 @@ +//! REST API request tooling. mod config; mod v0; From 004405fdf4ecf2754e65ac5c39c2f021139725ca Mon Sep 17 00:00:00 2001 From: Filip Dulic Date: Fri, 16 Apr 2021 17:01:42 -0500 Subject: [PATCH 23/25] more doc strings for modules and public types --- jcli-lib/src/debug/block.rs | 1 + jcli-lib/src/debug/message.rs | 1 + jcli-lib/src/debug/mod.rs | 3 +++ jcli-lib/src/key.rs | 1 + jcli-lib/src/rest/mod.rs | 3 ++- jcli-lib/src/rest/v0/account/mod.rs | 1 + jcli-lib/src/rest/v0/mod.rs | 2 ++ jcli-lib/src/transaction/mod.rs | 1 + jcli-lib/src/utils/mod.rs | 1 + jcli-lib/src/vote/mod.rs | 1 + 10 files changed, 14 insertions(+), 1 deletion(-) diff --git a/jcli-lib/src/debug/block.rs b/jcli-lib/src/debug/block.rs index fa35918bf3..510c006d28 100644 --- a/jcli-lib/src/debug/block.rs +++ b/jcli-lib/src/debug/block.rs @@ -1,3 +1,4 @@ +//! Decode hex-encoded message and display its contents. use crate::{debug::Error, utils::io}; use chain_core::property::Deserialize as _; use chain_impl_mockchain::block::Block as BlockMock; diff --git a/jcli-lib/src/debug/message.rs b/jcli-lib/src/debug/message.rs index eca2447c69..c442aea228 100644 --- a/jcli-lib/src/debug/message.rs +++ b/jcli-lib/src/debug/message.rs @@ -1,3 +1,4 @@ +//! Inspect hex-encoded fragment messages. use crate::{debug::Error, utils::io}; use chain_core::property::Deserialize as _; use chain_impl_mockchain::fragment::Fragment as MockFragment; diff --git a/jcli-lib/src/debug/mod.rs b/jcli-lib/src/debug/mod.rs index 0dbc7a8fb9..2df1cd56d1 100644 --- a/jcli-lib/src/debug/mod.rs +++ b/jcli-lib/src/debug/mod.rs @@ -1,3 +1,4 @@ +//! Debug tools for inspecting hex-encoded messages and blocks. mod block; mod message; use hex::FromHexError; @@ -11,6 +12,7 @@ use thiserror::Error; derive(StructOpt), structopt(rename_all = "kebab-case") )] +/// Type for inspecting hex-encoded messages and blocks. pub enum Debug { /// Decode hex-encoded message and display its content Message(message::Message), @@ -19,6 +21,7 @@ pub enum Debug { } #[derive(Debug, Error)] +/// Error types when inspecting hex-encoded messages and blocks. pub enum Error { #[error("I/O Error")] Io(#[from] std::io::Error), diff --git a/jcli-lib/src/key.rs b/jcli-lib/src/key.rs index 7b159f74f3..12fa5d02a1 100644 --- a/jcli-lib/src/key.rs +++ b/jcli-lib/src/key.rs @@ -1,3 +1,4 @@ +//! Key generation tools. use crate::utils::io; use crate::utils::output_file::{self, OutputFile}; use bech32::{self, u5, FromBase32, ToBase32}; diff --git a/jcli-lib/src/rest/mod.rs b/jcli-lib/src/rest/mod.rs index 0d593282f1..678c716053 100644 --- a/jcli-lib/src/rest/mod.rs +++ b/jcli-lib/src/rest/mod.rs @@ -9,18 +9,19 @@ use hex::FromHexError; use structopt::StructOpt; use thiserror::Error; -/// Send request to node REST API #[cfg_attr( feature = "structopt", derive(StructOpt), structopt(rename_all = "kebab-case") )] +/// Send request to node REST API pub enum Rest { /// API version 0 V0(v0::V0), } #[derive(Debug, Error)] +/// Error types for REST API calls. pub enum Error { #[error("input is not a valid fragment")] InputFragmentMalformed(#[source] std::io::Error), diff --git a/jcli-lib/src/rest/v0/account/mod.rs b/jcli-lib/src/rest/v0/account/mod.rs index 21155ce8fa..d43d29623b 100644 --- a/jcli-lib/src/rest/v0/account/mod.rs +++ b/jcli-lib/src/rest/v0/account/mod.rs @@ -1,3 +1,4 @@ +//! Account operations use crate::rest::{Error, RestArgs}; use crate::utils::{AccountId, OutputFormat}; #[cfg(feature = "structopt")] diff --git a/jcli-lib/src/rest/v0/mod.rs b/jcli-lib/src/rest/v0/mod.rs index 7320f65083..3bfe0b791c 100644 --- a/jcli-lib/src/rest/v0/mod.rs +++ b/jcli-lib/src/rest/v0/mod.rs @@ -1,3 +1,4 @@ +//! REST API Version 0. mod account; mod block; mod diagnostic; @@ -24,6 +25,7 @@ use structopt::StructOpt; derive(StructOpt), structopt(rename_all = "kebab-case") )] +/// Endpoints for the REST API Version 0. pub enum V0 { /// Account operations Account(account::Account), diff --git a/jcli-lib/src/transaction/mod.rs b/jcli-lib/src/transaction/mod.rs index 765c094906..cab8d3ffce 100644 --- a/jcli-lib/src/transaction/mod.rs +++ b/jcli-lib/src/transaction/mod.rs @@ -1,3 +1,4 @@ +//! Transaction tools for building and viewing offline. mod add_account; mod add_certificate; mod add_input; diff --git a/jcli-lib/src/utils/mod.rs b/jcli-lib/src/utils/mod.rs index 6ca807c205..23c760fc59 100644 --- a/jcli-lib/src/utils/mod.rs +++ b/jcli-lib/src/utils/mod.rs @@ -1,3 +1,4 @@ +//! Helper utilities. mod account_id; pub mod io; diff --git a/jcli-lib/src/vote/mod.rs b/jcli-lib/src/vote/mod.rs index b6743fa66f..5300531169 100644 --- a/jcli-lib/src/vote/mod.rs +++ b/jcli-lib/src/vote/mod.rs @@ -1,3 +1,4 @@ +//! Voting operations. use crate::utils::output_file::{self, OutputFile}; use crate::utils::vote::{SharesError, VotePlanError}; From 192d45ff08389dd4fd577a2f0ddffb5b4f3b6626 Mon Sep 17 00:00:00 2001 From: Filip Dulic Date: Fri, 16 Apr 2021 17:02:05 -0500 Subject: [PATCH 24/25] make crate::rest::v0 module public --- jcli-lib/src/rest/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jcli-lib/src/rest/mod.rs b/jcli-lib/src/rest/mod.rs index 678c716053..7ea4bef4b6 100644 --- a/jcli-lib/src/rest/mod.rs +++ b/jcli-lib/src/rest/mod.rs @@ -1,6 +1,6 @@ //! REST API request tooling. mod config; -mod v0; +pub mod v0; use crate::utils::{io::ReadYamlError, output_format}; use config::RestArgs; From d57f89283b6db197bf8fe7011a6aecb2e0f262be Mon Sep 17 00:00:00 2001 From: Filip Dulic Date: Mon, 19 Apr 2021 14:13:34 -0500 Subject: [PATCH 25/25] remove duplicate Seed structs, make Seed public for library --- jcli-lib/src/key.rs | 3 ++- jcli-lib/src/vote/mod.rs | 19 +------------------ 2 files changed, 3 insertions(+), 19 deletions(-) diff --git a/jcli-lib/src/key.rs b/jcli-lib/src/key.rs index 12fa5d02a1..6c573008df 100644 --- a/jcli-lib/src/key.rs +++ b/jcli-lib/src/key.rs @@ -444,7 +444,8 @@ fn bytes_to_priv_key(bytes: &[u8]) -> Result { } #[derive(Debug)] -struct Seed([u8; 32]); +/// Hexadecimal seed for keys. +pub struct Seed(pub (crate) [u8; 32]); impl std::str::FromStr for Seed { type Err = Error; fn from_str(s: &str) -> Result { diff --git a/jcli-lib/src/vote/mod.rs b/jcli-lib/src/vote/mod.rs index 5300531169..7ec56acd09 100644 --- a/jcli-lib/src/vote/mod.rs +++ b/jcli-lib/src/vote/mod.rs @@ -1,6 +1,7 @@ //! Voting operations. use crate::utils::output_file::{self, OutputFile}; use crate::utils::vote::{SharesError, VotePlanError}; +use crate::key::Seed; pub mod bech32_constants; mod committee; @@ -85,21 +86,3 @@ impl Vote { } } } - -// FIXME: Duplicated with key.rs -#[derive(Debug)] -struct Seed([u8; 32]); -impl std::str::FromStr for Seed { - type Err = Error; - fn from_str(s: &str) -> Result { - let vec = hex::decode(s)?; - if vec.len() != 32 { - return Err(Error::InvalidSeed { - seed_len: vec.len(), - }); - } - let mut bytes = [0; 32]; - bytes.copy_from_slice(&vec); - Ok(Seed(bytes)) - } -}