123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- use std::str::FromStr;
- use std::sync::Arc;
- use anyhow::Result;
- use cdk::cdk_database::{Error, WalletDatabase};
- use cdk::mint_url::MintUrl;
- use cdk::nuts::CurrencyUnit;
- use cdk::wallet::types::WalletKey;
- use cdk::wallet::{MultiMintWallet, Wallet};
- use clap::Args;
- #[derive(Args)]
- pub struct RestoreSubCommand {
- /// Mint Url
- mint_url: MintUrl,
- /// Currency unit e.g. sat
- #[arg(default_value = "sat")]
- unit: String,
- }
- pub async fn restore(
- multi_mint_wallet: &MultiMintWallet,
- seed: &[u8],
- localstore: Arc<dyn WalletDatabase<Err = Error> + Sync + Send>,
- sub_command_args: &RestoreSubCommand,
- ) -> Result<()> {
- let unit = CurrencyUnit::from_str(&sub_command_args.unit)?;
- let mint_url = sub_command_args.mint_url.clone();
- let wallet = match multi_mint_wallet
- .get_wallet(&WalletKey::new(mint_url.clone(), unit.clone()))
- .await
- {
- Some(wallet) => wallet.clone(),
- None => {
- let wallet = Wallet::new(&mint_url.to_string(), unit, localstore, seed, None)?;
- multi_mint_wallet.add_wallet(wallet.clone()).await;
- wallet
- }
- };
- let amount = wallet.restore().await?;
- println!("Restored {}", amount);
- Ok(())
- }
|