Skip to content

Commit

Permalink
Make delay time in fake wallet configurable (#445)
Browse files Browse the repository at this point in the history
  • Loading branch information
mubarak23 authored Nov 9, 2024
1 parent 0523892 commit 2239c22
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions crates/cdk-mintd/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ home = "0.5.5"
url = "2.3"
utoipa = { version = "4", optional = true }
utoipa-swagger-ui = { version = "4", features = ["axum"], optional = true }
rand = "0.8.5"

[features]
swagger = ["cdk-axum/swagger", "dep:utoipa", "dep:utoipa-swagger-ui"]
4 changes: 4 additions & 0 deletions crates/cdk-mintd/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ pub struct FakeWallet {
pub supported_units: Vec<CurrencyUnit>,
pub fee_percent: f32,
pub reserve_fee_min: Amount,
pub min_delay_time: u64,
pub max_delay_time: u64,
}

impl Default for FakeWallet {
Expand All @@ -112,6 +114,8 @@ impl Default for FakeWallet {
supported_units: vec![CurrencyUnit::Sat],
fee_percent: 0.02,
reserve_fee_min: 2.into(),
min_delay_time: 1,
max_delay_time: 3,
}
}
}
Expand Down
7 changes: 6 additions & 1 deletion crates/cdk-mintd/src/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use std::{

use anyhow::{anyhow, bail};
use axum::{async_trait, Router};
use rand::Rng;

use cdk::{cdk_lightning::MintLightning, mint::FeeReserve, mint_url::MintUrl, nuts::CurrencyUnit};
use tokio::sync::Mutex;
Expand Down Expand Up @@ -217,11 +218,15 @@ impl LnBackendSetup for config::FakeWallet {
percent_fee_reserve: self.fee_percent,
};

// calculate random delay time
let mut rng = rand::thread_rng();
let delay_time = rng.gen_range(self.min_delay_time..=self.max_delay_time);

let fake_wallet = cdk_fake_wallet::FakeWallet::new(
fee_reserve,
HashMap::default(),
HashSet::default(),
3,
delay_time,
);

Ok(fake_wallet)
Expand Down

0 comments on commit 2239c22

Please sign in to comment.