|
1 | 1 | use anyhow::Result; |
2 | 2 | use cdk::mint_url::MintUrl; |
3 | | -use cdk::wallet::WalletRepository; |
| 3 | +use cdk::wallet::{MintConnector, WalletRepository}; |
| 4 | +use cdk::HttpClient; |
4 | 5 | use clap::Args; |
| 6 | +use url::Url; |
5 | 7 |
|
6 | 8 | #[derive(Args)] |
7 | 9 | pub struct MintInfoSubcommand { |
8 | | - mint_url: MintUrl, |
| 10 | + mint_url: Option<MintUrl>, |
9 | 11 | } |
10 | 12 |
|
11 | 13 | pub async fn mint_info( |
12 | 14 | wallet_repository: &WalletRepository, |
| 15 | + proxy: Option<Url>, |
13 | 16 | sub_command_args: &MintInfoSubcommand, |
14 | 17 | ) -> Result<()> { |
15 | | - let mint_url = sub_command_args.mint_url.clone(); |
16 | | - let info = wallet_repository.fetch_mint_info(&mint_url).await?; |
| 18 | + if let Some(mint_url) = &sub_command_args.mint_url { |
| 19 | + let client = match proxy { |
| 20 | + Some(proxy) => HttpClient::with_proxy(mint_url.clone(), proxy, None, true)?, |
| 21 | + None => HttpClient::new(mint_url.clone(), None), |
| 22 | + }; |
17 | 23 |
|
18 | | - println!("{}", serde_json::to_string_pretty(&info)?); |
| 24 | + match client.get_mint_info().await { |
| 25 | + Ok(info) => { |
| 26 | + println!("{}", serde_json::to_string_pretty(&info)?); |
| 27 | + } |
| 28 | + Err(_) => { |
| 29 | + let wallets = wallet_repository.get_wallets_for_mint(mint_url).await; |
| 30 | + |
| 31 | + for (i, wallet) in wallets.iter().enumerate() { |
| 32 | + match wallet.load_mint_info().await { |
| 33 | + Ok(mint_info) => { |
| 34 | + println!("{i}: {mint_url}"); |
| 35 | + println!("{}", serde_json::to_string_pretty(&mint_info)?); |
| 36 | + } |
| 37 | + Err(e) => { |
| 38 | + println!("Cannot fetch mint info {mint_url}: {e}") |
| 39 | + } |
| 40 | + } |
| 41 | + } |
| 42 | + } |
| 43 | + }; |
| 44 | + } else { |
| 45 | + let wallets = wallet_repository.get_wallets().await; |
| 46 | + for (i, wallet) in wallets.iter().enumerate() { |
| 47 | + let mint_url = wallet.mint_url.clone(); |
| 48 | + match wallet.load_mint_info().await { |
| 49 | + Ok(info) => { |
| 50 | + println!("{i}: {mint_url}"); |
| 51 | + println!("{}", serde_json::to_string_pretty(&info)?); |
| 52 | + } |
| 53 | + Err(e) => { |
| 54 | + println!("Cannot fetch mint info {mint_url}: {e}"); |
| 55 | + } |
| 56 | + }; |
| 57 | + } |
| 58 | + } |
19 | 59 |
|
20 | 60 | Ok(()) |
21 | 61 | } |
0 commit comments