fix: examples

This commit is contained in:
thesimplekid
2024-12-27 21:45:46 -05:00
parent 8ab08c7fce
commit 6575e1477a
4 changed files with 20 additions and 12 deletions

View File

@@ -1,4 +1,5 @@
use std::sync::Arc;
use cdk::amount::SplitTarget;
use cdk::cdk_database::WalletMemoryDatabase;
use cdk::error::Error;
@@ -12,7 +13,7 @@ use rand::Rng;
async fn main() -> Result<(), Error> {
// Initialize the memory store for the wallet
let localstore = WalletMemoryDatabase::default();
// Generate a random seed for the wallet
let seed = rand::thread_rng().gen::<[u8; 32]>();
@@ -30,7 +31,9 @@ async fn main() -> Result<(), Error> {
// Subscribe to updates on the mint quote state
let mut subscription = wallet
.subscribe(WalletSubscription::Bolt11MintQuoteState(vec![quote.id.clone()]))
.subscribe(WalletSubscription::Bolt11MintQuoteState(vec![quote
.id
.clone()]))
.await;
// Wait for the mint quote to be paid

View File

@@ -1,4 +1,5 @@
use std::sync::Arc;
use cdk::amount::SplitTarget;
use cdk::cdk_database::WalletMemoryDatabase;
use cdk::error::Error;
@@ -12,7 +13,7 @@ use rand::Rng;
async fn main() -> Result<(), Error> {
// Initialize the memory store for the wallet
let localstore = WalletMemoryDatabase::default();
// Generate a random seed for the wallet
let seed = rand::thread_rng().gen::<[u8; 32]>();
@@ -31,7 +32,9 @@ async fn main() -> Result<(), Error> {
// Subscribe to updates on the mint quote state
let mut subscription = wallet
.subscribe(WalletSubscription::Bolt11MintQuoteState(vec![quote.id.clone()]))
.subscribe(WalletSubscription::Bolt11MintQuoteState(vec![quote
.id
.clone()]))
.await;
// Wait for the mint quote to be paid

View File

@@ -1,14 +1,13 @@
//! Wallet example with memory store
use std::sync::Arc;
use cdk::amount::SplitTarget;
use cdk::cdk_database::WalletMemoryDatabase;
use cdk::nuts::{CurrencyUnit, MintQuoteState, NotificationPayload};
use cdk::wallet::{Wallet, WalletSubscription};
use cdk::Amount;
use rand::Rng;
use tokio::sync::mpsc;
use tokio::time::timeout;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
@@ -28,14 +27,16 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Amount to mint
for amount in [64] {
let amount = Amount::from(amount);
// Request a mint quote from the wallet
let quote = wallet.mint_quote(amount, None).await?;
println!("Pay request: {}", quote.request);
// Subscribe to the wallet for updates on the mint quote state
let mut subscription = wallet
.subscribe(WalletSubscription::Bolt11MintQuoteState(vec![quote.id.clone()]))
.subscribe(WalletSubscription::Bolt11MintQuoteState(vec![quote
.id
.clone()]))
.await;
// Wait for the mint quote to be paid
@@ -56,7 +57,9 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
let proofs = wallet.get_unspent_proofs().await?;
// Select proofs to send
let selected = wallet.select_proofs_to_send(Amount::from(64), proofs, false).await?;
let selected = wallet
.select_proofs_to_send(Amount::from(64), proofs, false)
.await?;
for (i, proof) in selected.iter().enumerate() {
println!("{}: {}", i, proof.amount);
}

View File

@@ -1,5 +1,6 @@
use std::sync::Arc;
use std::time::Duration;
use cdk::amount::SplitTarget;
use cdk::cdk_database::WalletMemoryDatabase;
use cdk::nuts::{CurrencyUnit, MintQuoteState};
@@ -52,9 +53,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
}
// Mint the received amount
let receive_amount = wallet
.mint(&quote.id, SplitTarget::default(), None)
.await?;
let receive_amount = wallet.mint(&quote.id, SplitTarget::default(), None).await?;
println!("Minted {}", receive_amount);