From 06538b3c590f596d15fd23994b885719b19e92e0 Mon Sep 17 00:00:00 2001 From: Piotr Chromiec Date: Wed, 1 Dec 2021 13:53:58 +0100 Subject: [PATCH] [golemsp] make status to display network group instead first net name --- agent/provider/src/provider_agent.rs | 1 + golem_cli/src/command.rs | 4 ---- golem_cli/src/setup.rs | 2 +- golem_cli/src/status.rs | 26 ++++++++++++++------------ 4 files changed, 16 insertions(+), 17 deletions(-) diff --git a/agent/provider/src/provider_agent.rs b/agent/provider/src/provider_agent.rs index e562b18e5b..fda13b56f8 100644 --- a/agent/provider/src/provider_agent.rs +++ b/agent/provider/src/provider_agent.rs @@ -135,6 +135,7 @@ impl ProviderAgent { NetworkName::Polygon => yansi::Color::Magenta, NetworkName::Rinkeby => yansi::Color::Cyan, NetworkName::Mumbai => yansi::Color::Cyan, + NetworkName::Goerli => yansi::Color::Cyan, _ => yansi::Color::Red, }; log::info!("Using payment network: {}", net_color.paint(&n)); diff --git a/golem_cli/src/command.rs b/golem_cli/src/command.rs index deb5c09c73..16b8d074cc 100644 --- a/golem_cli/src/command.rs +++ b/golem_cli/src/command.rs @@ -46,10 +46,6 @@ impl YaCommand { cmd.env("EXE_UNIT_PATH", plugins_dir.join("ya-*.json")); } } - // YA_PAYMENT_NETWORK is used in different context in golemsp - // and in ya-provider. golemsp always passes commandline - // --payment-network arg, so it's safe to just remove it here. - cmd.env_remove("YA_PAYMENT_NETWORK"); Ok(YaProviderCommand { cmd }) } diff --git a/golem_cli/src/setup.rs b/golem_cli/src/setup.rs index b664a4b686..73f1442508 100644 --- a/golem_cli/src/setup.rs +++ b/golem_cli/src/setup.rs @@ -23,7 +23,7 @@ pub struct ConfigAccount { #[structopt(long, env = "YA_ACCOUNT")] pub account: Option, /// Payment network. - #[structopt(long = "payment-network", env = "YA_PAYMENT_NETWORK", possible_values = NetworkGroup::VARIANTS, default_value = NetworkGroup::Mainnet.into())] + #[structopt(long = "payment-network", env = "YA_PAYMENT_NETWORK_GROUP", possible_values = NetworkGroup::VARIANTS, default_value = NetworkGroup::Mainnet.into())] pub network: NetworkGroup, } diff --git a/golem_cli/src/status.rs b/golem_cli/src/status.rs index b2e334dcfa..c12f58125a 100644 --- a/golem_cli/src/status.rs +++ b/golem_cli/src/status.rs @@ -24,13 +24,7 @@ async fn payment_status( ) -> anyhow::Result> { let address = payment_account(&cmd, account).await?; - let network_group = { - if NETWORK_GROUP_MAP[&NetworkGroup::Mainnet].contains(network) { - NetworkGroup::Mainnet - } else { - NetworkGroup::Testnet - } - }; + let network_group = get_network_group(network); let mut result = BTreeMap::new(); let (futures, labels) = { @@ -65,6 +59,14 @@ async fn payment_status( Ok(result) } +fn get_network_group(network: &NetworkName) -> NetworkGroup { + if NETWORK_GROUP_MAP[&NetworkGroup::Mainnet].contains(network) { + NetworkGroup::Mainnet + } else { + NetworkGroup::Testnet + } +} + pub async fn run() -> Result { let size = crossterm::terminal::size().ok().unwrap_or_else(|| (80, 50)); let cmd = YaCommand::new()?; @@ -131,6 +133,7 @@ pub async fn run() -> Result { if is_running { let (_offers_cnt, network) = get_payment_network().await?; + let network_group = get_network_group(&network); let payments = { let (id, invoice_status) = @@ -154,15 +157,14 @@ pub async fn run() -> Result { table.add_row(row![H2->Style::new().fg(Colour::Fixed(63)).paint(&account)]); table.add_empty_row(); - let net_color = match network { - NetworkName::Mainnet => Colour::Purple, - NetworkName::Rinkeby => Colour::Cyan, - _ => Colour::Red, + let net_color = match network_group { + NetworkGroup::Mainnet => Colour::Purple, + NetworkGroup::Testnet => Colour::Cyan, }; table.add_row(row![ "network", - Style::new().fg(net_color).paint(network.to_string()) + Style::new().fg(net_color).paint(network_group.to_string()) ]); let total_amount: BigDecimal = payment_statuses.values().cloned().map(|ps| ps.amount).sum();