mirror of
https://github.com/aljazceru/cdk.git
synced 2026-02-05 21:26:13 +01:00
Make delay time in fake wallet configurable (#445)
This commit is contained in:
committed by
GitHub
parent
0523892b4d
commit
2239c22da5
@@ -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"]
|
||||
@@ -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 {
|
||||
@@ -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,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user