Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .cdk-cli/cdk-wallet
Binary file not shown.
20 changes: 16 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{fs, sync::Arc};
use std::{fs, path::PathBuf, str::FromStr, sync::Arc};

use bip39::Mnemonic;
use cdk::{
Expand Down Expand Up @@ -102,7 +102,12 @@ async fn main() -> anyhow::Result<()> {
}

async fn create_localstore() -> Arc<dyn WalletDatabase<Err = cdk_database::Error> + Send + Sync> {
todo!()
let path = PathBuf::from_str(DEFAULT_WORK_DIR)
.unwrap()
.join("cdk-wallet");
let local = cdk_redb::WalletRedbDatabase::new(&path).unwrap();

Arc::new(local)
}

async fn create_multimint_wallet(
Expand All @@ -112,11 +117,18 @@ async fn create_multimint_wallet(
let mut wallets: Vec<Wallet> = Vec::new();

// TODO: Get mints from localstore
let mints = todo!();
let mints = localstore.get_mints().await?;

// TODO: For mint in store create wallet
for (mint, _) in mints {
let wallet = todo!();
let wallet = Wallet::new(
&mint.to_string(),
CurrencyUnit::Sat,
localstore.clone(),
seed,
None,
)
.unwrap();
wallets.push(wallet);
}

Expand Down
7 changes: 7 additions & 0 deletions src/sub_commands/balance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,17 @@ pub async fn balance(multi_mint_wallet: &MultiMintWallet) -> Result<()> {

pub async fn mint_balances(multi_mint_wallet: &MultiMintWallet) -> Result<Vec<(MintUrl, Amount)>> {
// TODO: Get balances of wallets in multimint wallet
let wallets: BTreeMap<MintUrl, Amount> =
multi_mint_wallet.get_balances(&CurrencyUnit::Sat).await?;

let mut wallets_vec = Vec::new();

// TODO: Print balance of each mint in multimint wallet
for (i, (mint_url, amount)) in wallets.iter().enumerate() {
let mint_url = mint_url.clone();
println!("{i}: {mint_url} {amount}");
wallets_vec.push((mint_url, *amount))
}

Ok(wallets_vec)
}
13 changes: 9 additions & 4 deletions src/sub_commands/melt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,18 @@ pub async fn pay(
}

// TODO: Get melt quote
let melt = wallet.melt_quote(bolt11.to_string(), None).await?;

println!("{:#?}", melt);

// TODO: Melt with melt quote

// println!("Paid invoice: {}", melt.state);
// if let Some(preimage) = melt.preimage {
// println!("Payment preimage: {}", preimage);
// }
let melt = wallet.melt(&melt.id).await?;

println!("Paid invoice: {}", melt.state);
if let Some(preimage) = melt.preimage {
println!("Payment preimage: {}", preimage);
}

Ok(())
}
19 changes: 15 additions & 4 deletions src/sub_commands/mint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,24 @@ pub async fn mint(
)
.await?;

// TODO: Get mint qoute
// TODO: Get mint quote
let mint_quote = wallet.mint_quote(10.into(), None).await?;

// loop {
// // TODO: Check mint quote status
// }
println!("{:#?}", mint_quote);

loop {
// TODO: Check mint quote status
let state = wallet.mint_quote_state(&mint_quote.id).await?;

if state.state == MintQuoteState::Paid {
break;
}
}

// TODO: Mint once quote has been paid
let mint = wallet.mint(&mint_quote.id, SplitTarget::None, None).await?;

println!("{}", mint);

Ok(())
}
4 changes: 2 additions & 2 deletions src/sub_commands/receive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ pub async fn receive(

// TODO: Call receive on multi mint wallet

let amount = todo!();
let amount = multi_mint_wallet.receive(&token_str, &[], &[]).await?;

// println!("Received: {}", amount);
println!("Received: {}", amount);

Ok(())
}
11 changes: 10 additions & 1 deletion src/sub_commands/send.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,16 @@ pub async fn send(
.expect("Known wallet");

// TODO: Use wallet.send to create token
let token: Token = todo!();
let token: Token = wallet
.send(
5.into(),
None,
None,
&SplitTarget::None,
&SendKind::OnlineExact,
false,
)
.await?;

match sub_command_args.v3 {
true => {
Expand Down