diff --git a/core/model/src/payment.rs b/core/model/src/payment.rs index 45c3e0ec7..be4f2a21b 100644 --- a/core/model/src/payment.rs +++ b/core/model/src/payment.rs @@ -469,7 +469,9 @@ pub mod local { } #[derive(Clone, Debug, Serialize, Deserialize)] - pub struct GetDrivers {} + pub struct GetDrivers { + pub ignore_legacy_networks: bool, + } #[derive(Clone, Debug, Serialize, Deserialize, thiserror::Error)] pub enum GetDriversError { diff --git a/core/payment/src/cli.rs b/core/payment/src/cli.rs index cae16ce05..70a0984bd 100644 --- a/core/payment/src/cli.rs +++ b/core/payment/src/cli.rs @@ -1,13 +1,14 @@ mod rpc; +use std::collections::HashMap; // External crates use bigdecimal::BigDecimal; use chrono::{DateTime, Utc}; -use serde_json::to_value; +use serde_json::{to_value, Value}; use std::str::FromStr; use std::time::UNIX_EPOCH; use structopt::*; -use ya_client_model::payment::DriverStatusProperty; +use ya_client_model::payment::{DriverDetails, DriverStatusProperty}; use ya_core_model::payment::local::NetworkName; // Workspace uses @@ -553,41 +554,56 @@ Typically operation should take less than 1 minute. ))) } DriverSubcommand::List => { - let drivers = bus::service(pay::BUS_ID).call(pay::GetDrivers {}).await??; + let drivers: HashMap = bus::service(pay::BUS_ID) + .call(pay::GetDrivers { + ignore_legacy_networks: false, + }) + .await??; if ctx.json_output { return CommandOutput::object(drivers); } - Ok(ResponseTable { - columns: vec![ - "driver".to_owned(), - "network".to_owned(), - "default?".to_owned(), - "token".to_owned(), - "platform".to_owned(), - ], - values: drivers - .iter() - .flat_map(|(driver, dd)| { - dd.networks - .iter() - .flat_map(|(network, n)| { - n.tokens - .iter() - .map(|(token, platform)| - serde_json::json! {[ + + let mut values: Vec = drivers + .iter() + .flat_map(|(driver, dd)| { + dd.networks + .iter() + .flat_map(|(network, n)| { + n.tokens + .iter() + .map(|(token, platform)| + serde_json::json! {[ driver, network, if &dd.default_network == network { "X" } else { "" }, token, platform, ]} - ) - .collect::>() - }) - .collect::>() - }) - .collect(), - }.into()) + ) + .collect::>() + }) + .collect::>() + }) + .collect(); + + values.sort_by(|a, b| { + //sort by index 4 (which means platform, be careful when changing these values) + let left_str = a.as_array().unwrap()[4].as_str().unwrap(); + let right_str = b.as_array().unwrap()[4].as_str().unwrap(); + left_str.cmp(right_str) + }); + + Ok(ResponseTable { + columns: vec![ + "driver".to_owned(), //index 0 + "network".to_owned(), //index 1 + "default?".to_owned(), //index 2 + "token".to_owned(), //index 3 + "platform".to_owned(), //index 4 - we are sorting by platform, be careful when changing these values + ], + values, + } + .into()) } }, PaymentCli::ReleaseAllocations => { diff --git a/core/payment/src/processor.rs b/core/payment/src/processor.rs index 17b74ccca..275734b9f 100644 --- a/core/payment/src/processor.rs +++ b/core/payment/src/processor.rs @@ -230,8 +230,18 @@ impl DriverRegistry { } } - pub fn get_drivers(&self) -> HashMap { - self.drivers.clone() + pub fn get_drivers(&self, ignore_legacy_networks: bool) -> HashMap { + let mut drivers = self.drivers.clone(); + + let legacy_networks = ["mumbai", "goerli", "rinkeby"]; + if ignore_legacy_networks { + drivers.values_mut().for_each(|driver| { + driver + .networks + .retain(|name, _| !legacy_networks.contains(&name.as_str())) + }) + } + drivers } pub fn get_network( @@ -381,11 +391,14 @@ impl PaymentProcessor { .map_err(|_| GetAccountsError::InternalTimeout) } - pub async fn get_drivers(&self) -> Result, GetDriversError> { + pub async fn get_drivers( + &self, + ignore_legacy_networks: bool, + ) -> Result, GetDriversError> { self.registry .timeout_read(REGISTRY_LOCK_TIMEOUT) .await - .map(|registry| registry.get_drivers()) + .map(|registry| registry.get_drivers(ignore_legacy_networks)) .map_err(|_| GetDriversError::InternalTimeout) } diff --git a/core/payment/src/service.rs b/core/payment/src/service.rs index aa7d3c726..ebf5428b7 100644 --- a/core/payment/src/service.rs +++ b/core/payment/src/service.rs @@ -492,7 +492,7 @@ mod local { _caller: String, msg: GetDrivers, ) -> Result, GetDriversError> { - processor.get_drivers().await + processor.get_drivers(msg.ignore_legacy_networks).await } async fn payment_driver_status( @@ -506,7 +506,12 @@ mod local { None => { #[allow(clippy::iter_kv_map)] // Unwrap is provably safe because NoError can't be instanciated - match service(PAYMENT_BUS_ID).call(GetDrivers {}).await { + match service(PAYMENT_BUS_ID) + .call(GetDrivers { + ignore_legacy_networks: false, + }) + .await + { Ok(drivers) => drivers, Err(e) => return Err(PaymentDriverStatusError::Internal(e.to_string())), }