Skip to content

Commit

Permalink
chore: make delay time in fake wallet configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
mubarak23 committed Nov 8, 2024
1 parent 0523892 commit ab3172a
Show file tree
Hide file tree
Showing 3 changed files with 12 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"]
8 changes: 8 additions & 0 deletions crates/cdk-mintd/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::path::PathBuf;
use cdk::nuts::{CurrencyUnit, PublicKey};
use cdk::Amount;
use config::{Config, ConfigError, File};
use rand::Rng;
use serde::{Deserialize, Serialize};

#[derive(Debug, Clone, Serialize, Deserialize, Default)]
Expand Down Expand Up @@ -104,14 +105,21 @@ 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 {
fn default() -> Self {
let mut rng = rand::thread_rng();
let min_rang = rng.gen_range(1..=1000);
let max_rang = rng.gen_range(1..=1000);
Self {
supported_units: vec![CurrencyUnit::Sat],
fee_percent: 0.02,
reserve_fee_min: 2.into(),
min_delay_time: min_rang,
max_delay_time: max_rang,
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion crates/cdk-mintd/src/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,12 +216,14 @@ impl LnBackendSetup for config::FakeWallet {
min_fee_reserve: self.reserve_fee_min,
percent_fee_reserve: self.fee_percent,
};
// calculate
let delay_time = (self.min_delay_time + self.max_delay_time) / 2;

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 ab3172a

Please sign in to comment.