diff --git a/agent/provider/src/provider_agent.rs b/agent/provider/src/provider_agent.rs index 0a801ff8ed..e562b18e5b 100644 --- a/agent/provider/src/provider_agent.rs +++ b/agent/provider/src/provider_agent.rs @@ -69,7 +69,7 @@ pub struct ProviderAgent { hardware: hardware::Manager, accounts: Vec, log_handler: LoggerHandle, - network: NetworkName, + networks: Vec, } impl ProviderAgent { @@ -128,15 +128,17 @@ impl ProviderAgent { args.runner.session_id = args.market.session_id.clone(); args.payment.session_id = args.market.session_id.clone(); - let network = args.node.account.network.clone(); - let net_color = match network { - NetworkName::Mainnet => yansi::Color::Magenta, - NetworkName::Polygon => yansi::Color::Magenta, - NetworkName::Rinkeby => yansi::Color::Cyan, - NetworkName::Mumbai => yansi::Color::Cyan, - _ => yansi::Color::Red, - }; - log::info!("Using payment network: {}", net_color.paint(&network)); + let networks = args.node.account.networks.clone(); + for n in networks.iter() { + let net_color = match n { + NetworkName::Mainnet => yansi::Color::Magenta, + NetworkName::Polygon => yansi::Color::Magenta, + NetworkName::Rinkeby => yansi::Color::Cyan, + NetworkName::Mumbai => yansi::Color::Cyan, + _ => yansi::Color::Red, + }; + log::info!("Using payment network: {}", net_color.paint(&n)); + } let mut globals = GlobalsManager::try_new(&config.globals_file, args.node)?; globals.spawn_monitor(&config.globals_file)?; let mut presets = PresetManager::load_or_create(&config.presets_file)?; @@ -159,7 +161,7 @@ impl ProviderAgent { hardware, accounts, log_handler, - network, + networks, }) } @@ -249,18 +251,18 @@ impl ProviderAgent { } } - fn accounts(&self, network: &NetworkName) -> anyhow::Result> { + fn accounts(&self, networks: &Vec) -> anyhow::Result> { let globals = self.globals.get_state(); if let Some(address) = &globals.account { log::info!( - "Filtering payment accounts by address={} and network={}", + "Filtering payment accounts by address={} and networks={:?}", address, - network + networks, ); let accounts: Vec = self .accounts .iter() - .filter(|acc| &acc.address == address && &acc.network == network) + .filter(|acc| &acc.address == address && networks.contains(&acc.network)) .cloned() .collect(); @@ -270,21 +272,21 @@ impl ProviderAgent { \t`yagna payment init --receiver --network {} --account {}`\n\ for all drivers you want to use.", address, - network, + networks[0], address, ) } Ok(accounts) } else { - log::debug!("Filtering payment accounts by network={}", network); + log::debug!("Filtering payment accounts by networks={:?}", networks); let accounts: Vec = self .accounts .iter() // FIXME: this is dirty fix -- we can get more that one address from this filter // FIXME: use /me endpoint and filter out only accounts bound to given app-key // FIXME: or introduce param to getProviderAccounts to filter out external account above - .filter(|acc| &acc.network == network) + .filter(|acc| networks.contains(&acc.network)) .cloned() .collect(); @@ -293,7 +295,7 @@ impl ProviderAgent { "Default payment account not initialized. Please run\n\ \t`yagna payment init --receiver --network {}`\n\ for all drivers you want to use.", - network, + networks[0], ) } @@ -471,7 +473,7 @@ impl Handler for ProviderAgent { let runner = self.runner.clone(); let market = self.market.clone(); let node_info = self.create_node_info(); - let accounts = match self.accounts(&self.network) { + let accounts = match self.accounts(&self.networks) { Ok(acc) => acc, Err(e) => return future::err(e).boxed_local(), }; diff --git a/agent/provider/src/startup_config.rs b/agent/provider/src/startup_config.rs index 645aeac266..6f11cc0b31 100644 --- a/agent/provider/src/startup_config.rs +++ b/agent/provider/src/startup_config.rs @@ -105,9 +105,9 @@ impl ProviderConfig { #[derive(StructOpt, Clone, Debug, Serialize, Deserialize, derive_more::Display)] #[display( - fmt = "{}Network: {}", + fmt = "{}Networks: {:?}", "account.map(|a| format!(\"Address: {}\n\", a)).unwrap_or(\"\".into())", - network + networks )] pub struct ReceiverAccount { /// Account for payments. @@ -115,7 +115,7 @@ pub struct ReceiverAccount { pub account: Option, /// Payment network. #[structopt(long = "payment-network", env = "YA_PAYMENT_NETWORK", possible_values = NetworkName::VARIANTS, default_value = NetworkName::Mainnet.into())] - pub network: NetworkName, + pub networks: Vec, } #[derive(StructOpt, Clone, Debug)] diff --git a/golem_cli/src/command.rs b/golem_cli/src/command.rs index 16b8d074cc..deb5c09c73 100644 --- a/golem_cli/src/command.rs +++ b/golem_cli/src/command.rs @@ -46,6 +46,10 @@ 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/command/provider.rs b/golem_cli/src/command/provider.rs index 95cffcff25..f6e16a7482 100644 --- a/golem_cli/src/command/provider.rs +++ b/golem_cli/src/command/provider.rs @@ -50,7 +50,7 @@ impl YaProviderCommand { pub async fn set_config( self, config: &ProviderConfig, - network: &NetworkName, + networks: &Vec, ) -> anyhow::Result<()> { let mut cmd = self.cmd; @@ -66,7 +66,9 @@ impl YaProviderCommand { if let Some(account) = &config.account { cmd.args(&["--account", &account.to_string()]); } - cmd.args(&["--payment-network", &network.to_string()]); + for n in networks.iter() { + cmd.args(&["--payment-network", &n.to_string()]); + } log::debug!("executing: {:?}", cmd); @@ -273,7 +275,6 @@ impl YaProviderCommand { for nn in NETWORK_GROUP_MAP[&run_cfg.account.network].iter() { self.cmd.arg("--payment-network").arg(nn.to_string()); - break; // ya-provider doesn't support many payment networks yet } if let Some(node_name) = &run_cfg.node_name { self.cmd.arg("--node-name").arg(node_name); diff --git a/golem_cli/src/command/yagna.rs b/golem_cli/src/command/yagna.rs index 46ea6d2970..e743d883d4 100644 --- a/golem_cli/src/command/yagna.rs +++ b/golem_cli/src/command/yagna.rs @@ -114,6 +114,8 @@ impl PaymentDriver { PartialEq, Serialize, )] +#[strum(serialize_all = "lowercase")] +#[serde(rename_all = "lowercase")] pub enum NetworkGroup { Mainnet, Testnet, diff --git a/golem_cli/src/settings.rs b/golem_cli/src/settings.rs index 9fb599be5c..defbcc0fa4 100644 --- a/golem_cli/src/settings.rs +++ b/golem_cli/src/settings.rs @@ -50,7 +50,7 @@ pub async fn run(settings: Settings) -> Result { node_name: settings.node_name, ..ProviderConfig::default() }, - &settings.account.network, + &settings.account.networks, ) .await?; } @@ -62,7 +62,7 @@ pub async fn run(settings: Settings) -> Result { account: settings.account.account, ..ProviderConfig::default() }, - &settings.account.network, + &settings.account.networks, ) .await?; } diff --git a/golem_cli/src/setup.rs b/golem_cli/src/setup.rs index 1682add072..b664a4b686 100644 --- a/golem_cli/src/setup.rs +++ b/golem_cli/src/setup.rs @@ -146,9 +146,9 @@ pub async fn setup(run_config: &RunConfig, force: bool) -> Result { config.node_name = Some(node_name); config.subnet = Some(subnet); - for nn in NETWORK_GROUP_MAP[&run_config.account.network].iter() { - cmd.ya_provider()?.set_config(&config, &nn).await?; - } + cmd.ya_provider()? + .set_config(&config, &NETWORK_GROUP_MAP[&run_config.account.network]) + .await?; } let is_configured = {