Handle wallets command to show all saved wallet configurations
(datadir: &Path, pretty: bool)
| 1063 | |
| 1064 | /// Handle wallets command to show all saved wallet configurations |
| 1065 | pub fn handle_wallets_subcommand(datadir: &Path, pretty: bool) -> Result<String, Error> { |
| 1066 | let load_config = WalletConfig::load(datadir)?; |
| 1067 | |
| 1068 | let config = match load_config { |
| 1069 | Some(c) if !c.wallets.is_empty() => c, |
| 1070 | _ => { |
| 1071 | return Ok(if pretty { |
| 1072 | "No wallet configurations found.".to_string() |
| 1073 | } else { |
| 1074 | serde_json::to_string_pretty(&json!({ |
| 1075 | "wallets": [] |
| 1076 | }))? |
| 1077 | }); |
| 1078 | } |
| 1079 | }; |
| 1080 | |
| 1081 | if pretty { |
| 1082 | let mut rows: Vec<Vec<CellStruct>> = vec![]; |
| 1083 | |
| 1084 | for (name, wallet_config) in config.wallets.iter() { |
| 1085 | let mut row = vec![name.cell(), wallet_config.network.clone().cell()]; |
| 1086 | |
| 1087 | #[cfg(any(feature = "sqlite", feature = "redb"))] |
| 1088 | row.push(wallet_config.database_type.clone().cell()); |
| 1089 | |
| 1090 | #[cfg(any( |
| 1091 | feature = "electrum", |
| 1092 | feature = "esplora", |
| 1093 | feature = "rpc", |
| 1094 | feature = "cbf" |
| 1095 | ))] |
| 1096 | { |
| 1097 | let client_str = wallet_config.client_type.as_deref().unwrap_or("N/A"); |
| 1098 | row.push(client_str.cell()); |
| 1099 | } |
| 1100 | |
| 1101 | #[cfg(any(feature = "electrum", feature = "esplora", feature = "rpc"))] |
| 1102 | { |
| 1103 | let url_str = wallet_config.server_url.as_deref().unwrap_or("N/A"); |
| 1104 | let display_url = if url_str.len() > 20 { |
| 1105 | shorten(url_str, 15, 10) |
| 1106 | } else { |
| 1107 | url_str.to_string() |
| 1108 | }; |
| 1109 | row.push(display_url.cell()); |
| 1110 | } |
| 1111 | |
| 1112 | let ext_desc_display = if wallet_config.ext_descriptor.len() > 40 { |
| 1113 | shorten(&wallet_config.ext_descriptor, 20, 15) |
| 1114 | } else { |
| 1115 | wallet_config.ext_descriptor.clone() |
| 1116 | }; |
| 1117 | row.push(ext_desc_display.cell()); |
| 1118 | |
| 1119 | let has_int_desc = if wallet_config.int_descriptor.is_some() { |
| 1120 | "Yes" |
| 1121 | } else { |
| 1122 | "No" |
no test coverage detected