feature cleanup + added the capability to few nym-cli commands

This commit is contained in:
Jędrzej Stuczyński
2023-03-30 16:07:22 +01:00
parent ac9290de27
commit 696f6c399c
14 changed files with 48 additions and 15 deletions
Generated
+1
View File
@@ -3216,6 +3216,7 @@ dependencies = [
"humantime-serde",
"k256",
"log",
"nym-bin-common",
"nym-coconut-bandwidth-contract-common",
"nym-coconut-dkg-common",
"nym-contracts-common",
+1 -1
View File
@@ -34,7 +34,7 @@ tokio = { version = "1.24.1", features = ["rt-multi-thread", "net", "signal"] }
tokio-tungstenite = "0.14" # websocket
## internal
nym-bin-common = { path = "../../common/bin-common", features = ["serde_json"] }
nym-bin-common = { path = "../../common/bin-common", features = ["output_format"] }
client-core = { path = "../../common/client-core", features = ["fs-surb-storage"] }
nym-coconut-interface = { path = "../../common/coconut-interface" }
nym-config = { path = "../../common/config" }
+1 -1
View File
@@ -19,7 +19,7 @@ tokio = { version = "1.24.1", features = ["rt-multi-thread", "net", "signal"] }
url = "2.2"
# internal
nym-bin-common = { path = "../../common/bin-common", features = ["serde_json"] }
nym-bin-common = { path = "../../common/bin-common", features = ["output_format"] }
client-core = { path = "../../common/client-core", features = ["fs-surb-storage"] }
nym-coconut-interface = { path = "../../common/coconut-interface" }
nym-config = { path = "../../common/config" }
+1
View File
@@ -22,3 +22,4 @@ vergen = { version = "=7.4.3", default-features = false, features = ["build", "g
[features]
default = []
output_format = ["serde", "serde_json"]
+2 -3
View File
@@ -2,7 +2,6 @@
// SPDX-License-Identifier: Apache-2.0
use clap::ValueEnum;
use serde::Serialize;
use std::fmt::{Display, Formatter};
#[derive(Default, Copy, Debug, Clone, ValueEnum)]
@@ -26,8 +25,8 @@ impl OutputFormat {
matches!(self, OutputFormat::Text)
}
#[cfg(feature = "serde_json")]
pub fn format<T: Serialize + ToString>(&self, data: &T) -> String {
#[cfg(feature = "output_format")]
pub fn format<T: serde::Serialize + ToString>(&self, data: &T) -> String {
match self {
OutputFormat::Text => data.to_string(),
OutputFormat::Json => serde_json::to_string(data).unwrap(),
+1
View File
@@ -29,6 +29,7 @@ cosmrs = { git = "https://github.com/neacsu/cosmos-rust", branch = "neacsu/feegr
cosmwasm-std = { workspace = true }
validator-client = { path = "../client-libs/validator-client", features = ["nyxd-client"] }
nym-bin-common = { path = "../../common/bin-common", features = ["output_format"] }
nym-crypto = { path = "../../common/crypto", features = ["asymmetric"] }
nym-network-defaults = { path = "../network-defaults" }
nym-contracts-common = { path = "../cosmwasm-smart-contracts/contracts-common" }
+22 -1
View File
@@ -4,8 +4,9 @@
use cosmrs::AccountId;
use cosmwasm_std::{Addr, Coin as CosmWasmCoin, Decimal};
use log::error;
use serde::Serialize;
use std::error::Error;
use std::fmt::Display;
use std::fmt::{Display, Formatter};
use validator_client::nyxd::Coin;
// TODO: perhaps it should be moved to some global common crate?
@@ -54,3 +55,23 @@ where
error!("{}", e);
e
}
#[derive(Serialize)]
pub(crate) struct DataWrapper<T> {
data: T,
}
impl<T> Display for DataWrapper<T>
where
T: Display,
{
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.data)
}
}
impl<T> DataWrapper<T> {
pub(crate) fn new(data: T) -> Self {
DataWrapper { data }
}
}
@@ -2,10 +2,11 @@
// SPDX-License-Identifier: Apache-2.0
use crate::context::QueryClient;
use crate::utils::account_id_to_cw_addr;
use crate::utils::{account_id_to_cw_addr, DataWrapper};
use clap::Parser;
use cosmrs::AccountId;
use log::info;
use nym_bin_common::output_format::OutputFormat;
use nym_crypto::asymmetric::identity;
use nym_mixnet_contract_common::construct_family_join_permit;
use nym_mixnet_contract_common::families::FamilyHead;
@@ -25,6 +26,9 @@ pub struct Args {
/// Identity of the member for whom we're issuing the permit
#[arg(long)]
pub member: identity::PublicKey,
#[clap(short, long, default_value_t = OutputFormat::default())]
output: OutputFormat,
}
pub async fn create_family_join_permit_sign_payload(args: Args, client: QueryClient) {
@@ -68,5 +72,6 @@ pub async fn create_family_join_permit_sign_payload(args: Args, client: QueryCli
let head = FamilyHead::new(mixnode.bond_information.identity());
let payload = construct_family_join_permit(nonce, head, proxy, args.member.to_base58_string());
println!("{}", payload.to_base58_string().unwrap())
let wrapper = DataWrapper::new(payload.to_base58_string().unwrap());
println!("{}", args.output.format(&wrapper))
}
@@ -2,9 +2,10 @@
// SPDX-License-Identifier: Apache-2.0
use crate::context::SigningClient;
use crate::utils::account_id_to_cw_addr;
use crate::utils::{account_id_to_cw_addr, DataWrapper};
use clap::Parser;
use cosmwasm_std::{Coin, Uint128};
use nym_bin_common::output_format::OutputFormat;
use nym_contracts_common::Percent;
use nym_mixnet_contract_common::{construct_mixnode_bonding_sign_payload, MixNodeCostParams};
use nym_network_defaults::{
@@ -54,6 +55,9 @@ pub struct Args {
/// Indicates whether the mixnode is going to get bonded via a vesting account
#[arg(long)]
pub with_vesting_account: bool,
#[clap(short, long, default_value_t = OutputFormat::default())]
output: OutputFormat,
}
pub async fn create_payload(args: Args, client: SigningClient) {
@@ -104,5 +108,6 @@ pub async fn create_payload(args: Args, client: SigningClient) {
let payload =
construct_mixnode_bonding_sign_payload(nonce, address, proxy, coin, mixnode, cost_params);
println!("{}", payload.to_base58_string().unwrap())
let wrapper = DataWrapper::new(payload.to_base58_string().unwrap());
println!("{}", args.output.format(&wrapper))
}
+1 -1
View File
@@ -56,7 +56,7 @@ nym-coconut-interface = { path = "../common/coconut-interface" }
nym-credentials = { path = "../common/credentials" }
nym-config = { path = "../common/config" }
nym-crypto = { path = "../common/crypto" }
nym-bin-common = { path = "../common/bin-common", features = ["serde_json"] }
nym-bin-common = { path = "../common/bin-common", features = ["output_format"] }
gateway-requests = { path = "gateway-requests" }
mixnet-client = { path = "../common/client-libs/mixnet-client" }
mixnode-common = { path = "../common/mixnode-common" }
+1 -1
View File
@@ -51,7 +51,7 @@ nym-task = { path = "../common/task" }
nym-types = { path = "../common/types" }
nym-topology = { path = "../common/topology" }
validator-client = { path = "../common/client-libs/validator-client" }
nym-bin-common = { path = "../common/bin-common", features = ["serde_json"] }
nym-bin-common = { path = "../common/bin-common", features = ["output_format"] }
cpu-cycles = { path = "../cpu-cycles", optional = true }
[dev-dependencies]
+1 -1
View File
@@ -62,7 +62,7 @@ struct OverrideConfig {
pub(crate) async fn execute(args: Cli) {
let bin_name = "nym-mixnode";
match args.command {
Commands::Describe(m) => describe::execute(m),
Commands::Init(m) => init::execute(&m),
+1 -1
View File
@@ -6,9 +6,9 @@ use crate::commands::{override_config, version_check};
use crate::config::Config;
use crate::node::MixNode;
use clap::Args;
use nym_bin_common::output_format::OutputFormat;
use nym_config::NymConfig;
use std::net::IpAddr;
use nym_bin_common::output_format::OutputFormat;
use validator_client::nyxd;
#[derive(Args, Clone)]
@@ -34,7 +34,7 @@ url = { workspace = true }
client-core = { path = "../../common/client-core" }
nym-config = { path = "../../common/config" }
nym-crypto = { path = "../../common/crypto" }
nym-bin-common = { path = "../../common/bin-common", features = ["serde_json"] }
nym-bin-common = { path = "../../common/bin-common", features = ["output_format"] }
nym-network-defaults = { path = "../../common/network-defaults" }
nym-sdk = { path = "../../sdk/rust/nym-sdk" }
nym-sphinx = { path = "../../common/nymsphinx" }