mirror of
https://github.com/aljazceru/cdk.git
synced 2025-12-23 15:44:50 +01:00
fix(cdk-cli/restore): create wallet if not in multimit wallet
This commit is contained in:
@@ -201,7 +201,13 @@ async fn main() -> Result<()> {
|
|||||||
sub_commands::burn::burn(&multi_mint_wallet, sub_command_args).await
|
sub_commands::burn::burn(&multi_mint_wallet, sub_command_args).await
|
||||||
}
|
}
|
||||||
Commands::Restore(sub_command_args) => {
|
Commands::Restore(sub_command_args) => {
|
||||||
sub_commands::restore::restore(&multi_mint_wallet, sub_command_args).await
|
sub_commands::restore::restore(
|
||||||
|
&multi_mint_wallet,
|
||||||
|
&mnemonic.to_seed_normalized(""),
|
||||||
|
localstore,
|
||||||
|
sub_command_args,
|
||||||
|
)
|
||||||
|
.await
|
||||||
}
|
}
|
||||||
Commands::UpdateMintUrl(sub_command_args) => {
|
Commands::UpdateMintUrl(sub_command_args) => {
|
||||||
sub_commands::update_mint_url::update_mint_url(&multi_mint_wallet, sub_command_args)
|
sub_commands::update_mint_url::update_mint_url(&multi_mint_wallet, sub_command_args)
|
||||||
|
|||||||
@@ -1,10 +1,12 @@
|
|||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
use anyhow::{anyhow, Result};
|
use anyhow::Result;
|
||||||
|
use cdk::cdk_database::{Error, WalletDatabase};
|
||||||
use cdk::mint_url::MintUrl;
|
use cdk::mint_url::MintUrl;
|
||||||
use cdk::nuts::CurrencyUnit;
|
use cdk::nuts::CurrencyUnit;
|
||||||
use cdk::wallet::multi_mint_wallet::WalletKey;
|
use cdk::wallet::multi_mint_wallet::WalletKey;
|
||||||
use cdk::wallet::MultiMintWallet;
|
use cdk::wallet::{MultiMintWallet, Wallet};
|
||||||
use clap::Args;
|
use clap::Args;
|
||||||
|
|
||||||
#[derive(Args)]
|
#[derive(Args)]
|
||||||
@@ -18,13 +20,25 @@ pub struct RestoreSubCommand {
|
|||||||
|
|
||||||
pub async fn restore(
|
pub async fn restore(
|
||||||
multi_mint_wallet: &MultiMintWallet,
|
multi_mint_wallet: &MultiMintWallet,
|
||||||
|
seed: &[u8],
|
||||||
|
localstore: Arc<dyn WalletDatabase<Err = Error> + Sync + Send>,
|
||||||
sub_command_args: &RestoreSubCommand,
|
sub_command_args: &RestoreSubCommand,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let unit = CurrencyUnit::from_str(&sub_command_args.unit)?;
|
let unit = CurrencyUnit::from_str(&sub_command_args.unit)?;
|
||||||
let wallet = multi_mint_wallet
|
let mint_url = sub_command_args.mint_url.clone();
|
||||||
.get_wallet(&WalletKey::new(sub_command_args.mint_url.clone(), unit))
|
|
||||||
|
let wallet = match multi_mint_wallet
|
||||||
|
.get_wallet(&WalletKey::new(mint_url.clone(), unit.clone()))
|
||||||
.await
|
.await
|
||||||
.ok_or(anyhow!("Unknown mint url"))?;
|
{
|
||||||
|
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?;
|
let amount = wallet.restore().await?;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user