use std::str::FromStr;
use std::sync::Arc;
use std::time::Duration;
use cdk::mint_url::MintUrl;
use cdk::nuts::CurrencyUnit;
use cdk::wallet::{WalletBuilder, WalletConfig, WalletRepositoryBuilder};
use cdk_sqlite::wallet::memory;
use rand::random;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let seed = random::<[u8; 64]>();
let unit = CurrencyUnit::Sat;
let localstore = Arc::new(memory::empty().await?);
println!("\n=== Single Wallet Configuration ===");
let mint_url = MintUrl::from_str("https://fake.thesimplekid.dev")?;
let wallet = WalletBuilder::new()
.mint_url(mint_url.clone())
.unit(unit.clone())
.localstore(localstore.clone())
.seed(seed)
.set_metadata_cache_ttl(Some(Duration::from_secs(600))) .build()?;
println!("Created wallet with 10 minute metadata cache TTL");
wallet.set_metadata_cache_ttl(Some(Duration::from_secs(300))); println!("Updated wallet TTL to 5 minutes");
println!("\n=== WalletRepository Configuration ===");
let multi_wallet = WalletRepositoryBuilder::new()
.localstore(localstore.clone())
.seed(seed)
.build()
.await?;
let config = WalletConfig::new().with_metadata_cache_ttl(Some(Duration::from_secs(60)));
let mint_url_2 = MintUrl::from_str("https://testnut.cashu.space")?;
multi_wallet
.add_wallet_with_config(mint_url_2.clone(), Some(config.clone()))
.await?;
println!("Added mint {} with 1 minute TTL", mint_url_2);
let no_refresh_config = WalletConfig::new().with_metadata_cache_ttl(None);
multi_wallet.add_wallet(mint_url.clone()).await?; multi_wallet
.set_mint_config(mint_url.clone(), unit.clone(), no_refresh_config)
.await?;
println!("Updated mint {} to never expire metadata cache", mint_url);
Ok(())
}