diff --git a/Cargo.lock b/Cargo.lock index f00cc44be4..2f1a94fe61 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -603,6 +603,7 @@ dependencies = [ "pemstore", "rand 0.7.3", "serde", + "serde_json", "sled", "tap", "task", @@ -3372,6 +3373,7 @@ dependencies = [ "proxy-helpers", "rand 0.7.3", "serde", + "serde_json", "snafu 0.6.10", "socks5-requests", "tap", @@ -5005,9 +5007,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.83" +version = "1.0.89" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38dd04e3c8279e75b31ef29dbdceebfe5ad89f4d0937213c53f7d49d01b3d5a7" +checksum = "020ff22c755c2ed3f8cf162dbb41a7268d934702f3ed3631656ea597e08fc3db" dependencies = [ "itoa 1.0.1", "ryu", @@ -6537,7 +6539,7 @@ checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" [[package]] name = "vesting-contract" -version = "1.1.0" +version = "1.1.2" dependencies = [ "contracts-common", "cosmwasm-std", diff --git a/clients/client-core/Cargo.toml b/clients/client-core/Cargo.toml index 7b0ecc9c97..7c23dc5785 100644 --- a/clients/client-core/Cargo.toml +++ b/clients/client-core/Cargo.toml @@ -32,6 +32,7 @@ pemstore = { path = "../../common/pemstore" } topology = { path = "../../common/topology" } validator-client = { path = "../../common/client-libs/validator-client", default-features = false } task = { path = "../../common/task" } +serde_json = "1.0.89" [target."cfg(not(target_arch = \"wasm32\"))".dependencies.tokio-stream] version = "0.1.9" diff --git a/clients/client-core/src/init.rs b/clients/client-core/src/init.rs index 44c20a7597..dac7e99a9a 100644 --- a/clients/client-core/src/init.rs +++ b/clients/client-core/src/init.rs @@ -9,11 +9,12 @@ use config::NymConfig; use crypto::asymmetric::{encryption, identity}; use gateway_client::GatewayClient; use gateway_requests::registration::handshake::SharedKeys; -use nymsphinx::addressing::clients::Recipient; +use nymsphinx::addressing::clients::{ClientIdentity, Recipient}; use nymsphinx::addressing::nodes::NodeIdentity; use rand::rngs::OsRng; use rand::seq::SliceRandom; use rand::thread_rng; +use serde::Serialize; use tap::TapFallible; use topology::{filter::VersionFilterable, gateway}; use url::Url; @@ -24,6 +25,32 @@ use crate::{ error::ClientCoreError, }; +#[derive(Debug, Serialize)] +pub struct InitResults { + version: String, + id: String, + identity_key: String, + sphinx_key: String, + gateway_id: String, + gateway_listener: String, +} + +impl InitResults { + pub fn new(config: &Config, address: &Recipient) -> Self + where + T: NymConfig, + { + Self { + version: config.get_version().to_string(), + id: config.get_id(), + identity_key: address.identity().to_base58_string(), + sphinx_key: address.encryption_key().to_base58_string(), + gateway_id: config.get_gateway_id(), + gateway_listener: config.get_gateway_listener(), + } + } +} + pub async fn query_gateway_details( validator_servers: Vec, chosen_gateway_id: Option<&str>, @@ -102,7 +129,7 @@ async fn register_with_gateway( Ok(shared_keys) } -pub fn show_address(config: &Config) -> Result<(), ClientCoreError> +pub fn get_client_address(config: &Config) -> Result where T: config::NymConfig, { @@ -143,5 +170,6 @@ where ); println!("\nThe address of this client is: {}", client_recipient); - Ok(()) + + Ok(client_recipient) } diff --git a/clients/native/src/commands/init.rs b/clients/native/src/commands/init.rs index dfcd98bab2..e1d8329316 100644 --- a/clients/native/src/commands/init.rs +++ b/clients/native/src/commands/init.rs @@ -126,7 +126,7 @@ pub(crate) async fn execute(args: &Init) { ); println!("Client configuration completed."); - client_core::init::show_address(config.get_base()).unwrap_or_else(|err| { + client_core::init::get_client_address(config.get_base()).unwrap_or_else(|err| { eprintln!("Failed to show address\nError: {err}"); std::process::exit(1) }); diff --git a/clients/socks5/Cargo.toml b/clients/socks5/Cargo.toml index cd00e23262..6560b1cad1 100644 --- a/clients/socks5/Cargo.toml +++ b/clients/socks5/Cargo.toml @@ -47,6 +47,7 @@ topology = { path = "../../common/topology" } validator-client = { path = "../../common/client-libs/validator-client", features = ["nymd-client"] } version-checker = { path = "../../common/version-checker" } tap = "1.0.1" +serde_json = "1.0.89" [features] coconut = ["coconut-interface", "credentials", "gateway-requests/coconut", "gateway-client/coconut", "credentials/coconut", "client-core/coconut"] diff --git a/clients/socks5/src/commands/init.rs b/clients/socks5/src/commands/init.rs index a727d0d8e9..0080199644 100644 --- a/clients/socks5/src/commands/init.rs +++ b/clients/socks5/src/commands/init.rs @@ -4,10 +4,13 @@ use clap::Args; use client_core::{config::GatewayEndpointConfig, error::ClientCoreError}; use config::NymConfig; +use nymsphinx::addressing::clients::Recipient; +use serde::Serialize; use crate::{ client::config::Config, commands::{override_config, OverrideConfig}, + error::Socks5ClientError, }; #[derive(Args, Clone)] @@ -71,6 +74,22 @@ impl From for OverrideConfig { } } +#[derive(Debug, Serialize)] +pub struct InitResults { + #[serde(flatten)] + client_core: client_core::init::InitResults, + socks5_listening_port: String, +} + +impl InitResults { + pub fn new(config: &Config, address: &Recipient) -> Self { + Self { + client_core: client_core::init::InitResults::new(config.get_base(), address), + socks5_listening_port: config.get_listening_port().to_string(), + } + } +} + pub(crate) async fn execute(args: &Init) { println!("Initialising client..."); @@ -125,10 +144,16 @@ pub(crate) async fn execute(args: &Init) { ); println!("Client configuration completed."); - client_core::init::show_address(config.get_base()).unwrap_or_else(|err| { + let address = client_core::init::get_client_address(config.get_base()).unwrap_or_else(|err| { eprintln!("Failed to show address\nError: {err}"); std::process::exit(1) }); + + let init_results = InitResults::new(&config, &address); + let init_results_json = serde_json::to_string_pretty(&init_results); + if let Ok(init_results) = init_results_json { + println!("{}", init_results); + } } async fn setup_gateway(