From 6575e1477af1313ffb6bab7c940453e330da02e8 Mon Sep 17 00:00:00 2001 From: thesimplekid Date: Fri, 27 Dec 2024 21:45:46 -0500 Subject: [PATCH] fix: examples --- crates/cdk/examples/mint-token.rs | 7 +++++-- crates/cdk/examples/p2pk.rs | 7 +++++-- crates/cdk/examples/proof-selection.rs | 13 ++++++++----- crates/cdk/examples/wallet.rs | 5 ++--- 4 files changed, 20 insertions(+), 12 deletions(-) diff --git a/crates/cdk/examples/mint-token.rs b/crates/cdk/examples/mint-token.rs index fc6adb4e..71421843 100644 --- a/crates/cdk/examples/mint-token.rs +++ b/crates/cdk/examples/mint-token.rs @@ -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 diff --git a/crates/cdk/examples/p2pk.rs b/crates/cdk/examples/p2pk.rs index 2406a33d..85112d06 100644 --- a/crates/cdk/examples/p2pk.rs +++ b/crates/cdk/examples/p2pk.rs @@ -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 diff --git a/crates/cdk/examples/proof-selection.rs b/crates/cdk/examples/proof-selection.rs index 2a09d6d8..c03d02c0 100644 --- a/crates/cdk/examples/proof-selection.rs +++ b/crates/cdk/examples/proof-selection.rs @@ -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> { @@ -28,14 +27,16 @@ async fn main() -> Result<(), Box> { // 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> { 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); } diff --git a/crates/cdk/examples/wallet.rs b/crates/cdk/examples/wallet.rs index ff973e40..7f8e62e3 100644 --- a/crates/cdk/examples/wallet.rs +++ b/crates/cdk/examples/wallet.rs @@ -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> { } // Mint the received amount - let receive_amount = wallet - .mint("e.id, SplitTarget::default(), None) - .await?; + let receive_amount = wallet.mint("e.id, SplitTarget::default(), None).await?; println!("Minted {}", receive_amount);