From 065b4e248fab5aa5849cd75145d547d9ee6431c1 Mon Sep 17 00:00:00 2001 From: thesimplekid Date: Sun, 6 Oct 2024 19:58:22 +0200 Subject: [PATCH] feat: fake wallet --- crates/cdk-fake-wallet/Cargo.toml | 1 + crates/cdk-fake-wallet/src/lib.rs | 10 ++++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/crates/cdk-fake-wallet/Cargo.toml b/crates/cdk-fake-wallet/Cargo.toml index 0cf03b83..8d1b5dff 100644 --- a/crates/cdk-fake-wallet/Cargo.toml +++ b/crates/cdk-fake-wallet/Cargo.toml @@ -15,6 +15,7 @@ bitcoin = { version = "0.32.2", default-features = false } cdk = { path = "../cdk", version = "0.4.0", default-features = false, features = ["mint"] } futures = { version = "0.3.28", default-features = false } tokio = { version = "1", default-features = false } +tokio-util = { version = "0.7.11", default-features = false } tracing = { version = "0.1", default-features = false, features = ["attributes", "log"] } thiserror = "1" serde = "1" diff --git a/crates/cdk-fake-wallet/src/lib.rs b/crates/cdk-fake-wallet/src/lib.rs index fae9b90f..e0fba072 100644 --- a/crates/cdk-fake-wallet/src/lib.rs +++ b/crates/cdk-fake-wallet/src/lib.rs @@ -8,6 +8,7 @@ use std::collections::{HashMap, HashSet}; use std::pin::Pin; use std::str::FromStr; +use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::Arc; use async_trait::async_trait; @@ -33,6 +34,7 @@ use serde::{Deserialize, Serialize}; use tokio::sync::Mutex; use tokio::time; use tokio_stream::wrappers::ReceiverStream; +use tokio_util::sync::CancellationToken; pub mod error; @@ -47,6 +49,8 @@ pub struct FakeWallet { payment_states: Arc>>, failed_payment_check: Arc>>, payment_delay: u64, + wait_invoice_cancel_token: CancellationToken, + wait_invoice_is_active: Arc, } impl FakeWallet { @@ -70,6 +74,8 @@ impl FakeWallet { payment_states: Arc::new(Mutex::new(payment_states)), failed_payment_check: Arc::new(Mutex::new(fail_payment_check)), payment_delay, + wait_invoice_cancel_token: CancellationToken::new(), + wait_invoice_is_active: Arc::new(AtomicBool::new(false)), } } } @@ -113,11 +119,11 @@ impl MintLightning for FakeWallet { } fn is_wait_invoice_active(&self) -> bool { - todo!() + self.wait_invoice_is_active.load(Ordering::SeqCst) } fn cancel_wait_invoice(&self) { - todo!() + self.wait_invoice_cancel_token.cancel() } async fn wait_any_invoice(