Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[golemsp] make status to display network group instead first net name #1737

Merged
merged 1 commit into from
Dec 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions agent/provider/src/provider_agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
4 changes: 0 additions & 4 deletions golem_cli/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
}
Expand Down
2 changes: 1 addition & 1 deletion golem_cli/src/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub struct ConfigAccount {
#[structopt(long, env = "YA_ACCOUNT")]
pub account: Option<NodeId>,
/// 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,
}

Expand Down
26 changes: 14 additions & 12 deletions golem_cli/src/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,7 @@ async fn payment_status(
) -> anyhow::Result<BTreeMap<String, StatusResult>> {
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) = {
Expand Down Expand Up @@ -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</*exit code*/ i32> {
let size = crossterm::terminal::size().ok().unwrap_or_else(|| (80, 50));
let cmd = YaCommand::new()?;
Expand Down Expand Up @@ -131,6 +133,7 @@ pub async fn run() -> Result</*exit code*/ i32> {

if is_running {
let (_offers_cnt, network) = get_payment_network().await?;
let network_group = get_network_group(&network);

let payments = {
let (id, invoice_status) =
Expand All @@ -154,15 +157,14 @@ pub async fn run() -> Result</*exit code*/ i32> {
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();
Expand Down