Skip to content

Commit 397ed33

Browse files
committed
chore/fix(cdk-cli): get mint info from wallets without specify mint_url
1 parent c22285a commit 397ed33

2 files changed

Lines changed: 47 additions & 6 deletions

File tree

crates/cdk-cli/src/main.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,8 @@ async fn main() -> Result<()> {
302302
sub_commands::check_requests::check_requests(&wallet_repository).await
303303
}
304304
Commands::MintInfo(sub_command_args) => {
305-
sub_commands::mint_info::mint_info(&wallet_repository, sub_command_args).await
305+
sub_commands::mint_info::mint_info(&wallet_repository, args.proxy, sub_command_args)
306+
.await
306307
}
307308
Commands::Mint(sub_command_args) => {
308309
sub_commands::mint::mint(&wallet_repository, sub_command_args, &default_unit).await
Lines changed: 45 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,61 @@
11
use anyhow::Result;
22
use cdk::mint_url::MintUrl;
3-
use cdk::wallet::WalletRepository;
3+
use cdk::wallet::{MintConnector, WalletRepository};
4+
use cdk::HttpClient;
45
use clap::Args;
6+
use url::Url;
57

68
#[derive(Args)]
79
pub struct MintInfoSubcommand {
8-
mint_url: MintUrl,
10+
mint_url: Option<MintUrl>,
911
}
1012

1113
pub async fn mint_info(
1214
wallet_repository: &WalletRepository,
15+
proxy: Option<Url>,
1316
sub_command_args: &MintInfoSubcommand,
1417
) -> 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+
};
1723

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+
}
1959

2060
Ok(())
2161
}

0 commit comments

Comments
 (0)