Skip to content

Commit

Permalink
feat: fake wallet
Browse files Browse the repository at this point in the history
  • Loading branch information
thesimplekid committed Oct 6, 2024
1 parent c82e6bd commit 065b4e2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
1 change: 1 addition & 0 deletions crates/cdk-fake-wallet/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
10 changes: 8 additions & 2 deletions crates/cdk-fake-wallet/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand All @@ -47,6 +49,8 @@ pub struct FakeWallet {
payment_states: Arc<Mutex<HashMap<String, MeltQuoteState>>>,
failed_payment_check: Arc<Mutex<HashSet<String>>>,
payment_delay: u64,
wait_invoice_cancel_token: CancellationToken,
wait_invoice_is_active: Arc<AtomicBool>,
}

impl FakeWallet {
Expand All @@ -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)),
}
}
}
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 065b4e2

Please sign in to comment.