Skip to content

Commit

Permalink
feat: use defaults for ln fee-config
Browse files Browse the repository at this point in the history
  • Loading branch information
ngutech21 committed Dec 22, 2023
1 parent f872a9b commit 6c94150
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 27 deletions.
16 changes: 6 additions & 10 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,19 @@ services:
POSTGRES_PASSWORD: postgres
POSTGRES_DB: moksha-mint
app:
#image: "docker.io/ngutech21/moksha-mint:latest"
image: "moksha-mint:latest"
image: "docker.io/ngutech21/moksha-mint:latest"
#image: "moksha-mint:latest"
ports:
- 3338:3338
volumes:
- /Users/steffen/projects/moksha/data/mutinynet/admin.macaroon:/app/admin.macaroon
- /Users/steffen/projects/moksha/data/mutinynet/tls.cert:/app/tls.cert
- ./data/mutinynet/admin.macaroon:/app/admin.macaroon
- ./data/mutinynet/tls.cert:/app/tls.cert
environment:
- DATABASE_URL=postgres://postgres:postgres@database/moksha-mint
- MINT_APP_ENV=prod
- MINT_DB_URL=postgres://postgres:postgres@database/moksha-mint
- MINT_LIGHTNING_BACKEND=Lnd
- LND_MACAROON_PATH=/app/admin.macaroon
- LND_TLS_CERT_PATH=/app/tls.cert
- LND_GRPC_HOST=https://mutinynet.moksha.cash:10009
- MINT_PRIVATE_KEY=ajszwuelakszetdh
- MINT_DB_URL=postgres://postgres:postgres@database/moksha-mint
- LIGHTNING_FEE_PERCENT=0.01
- LIGHTNING_RESERVE_FEE_MIN=10
- MINT_PRIVATE_KEY=supersecretkey
profiles:
- app
24 changes: 19 additions & 5 deletions moksha-mint/src/bin/moksha-mint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use mokshamint::{
AlbyLightningSettings, LightningType, LnbitsLightningSettings, LndLightningSettings,
StrikeLightningSettings,
},
mint::MintBuilder,
mint::{LightningFeeConfig, MintBuilder},
};
use std::{env, fmt, net::SocketAddr, path::PathBuf};

Expand Down Expand Up @@ -65,15 +65,22 @@ pub async fn main() -> anyhow::Result<()> {
.from_env::<MintInfoSettings>()
.expect("Please provide mint info");

let fee_config_default = LightningFeeConfig::default();

let fee_config = LightningFeeConfig {
fee_percent: env_or_default("LIGHTNING_FEE_PERCENT", fee_config_default.fee_percent),
fee_reserve_min: env_or_default(
"LIGHTNING_RESERVE_FEE_MIN",
fee_config_default.fee_reserve_min,
),
};

let mint = MintBuilder::new()
.with_mint_info(mint_info_settings)
.with_private_key(get_env("MINT_PRIVATE_KEY"))
.with_db(get_env("MINT_DB_URL"))
.with_lightning(ln_type)
.with_fee(
get_env("LIGHTNING_FEE_PERCENT").parse()?,
get_env("LIGHTNING_RESERVE_FEE_MIN").parse()?,
)
.with_fee(fee_config)
.build()
.await;

Expand All @@ -86,6 +93,13 @@ pub async fn main() -> anyhow::Result<()> {
mokshamint::server::run_server(mint?, host_port, serve_wallet_path, api_prefix).await
}

fn env_or_default<T: std::str::FromStr>(key: &str, default: T) -> T {
env::var(key)
.ok()
.and_then(|v| v.parse().ok())
.unwrap_or(default)
}

#[derive(Debug, PartialEq)]
pub enum AppEnv {
Dev,
Expand Down
16 changes: 4 additions & 12 deletions moksha-mint/src/mint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,7 @@ pub struct MintBuilder {
private_key: Option<String>,
lightning_type: Option<LightningType>,
db_url: Option<String>,
fee_percent: Option<f32>,
fee_reserve_min: Option<u64>,
fee_config: Option<LightningFeeConfig>,
mint_info_settings: Option<MintInfoSettings>,
}

Expand Down Expand Up @@ -257,9 +256,8 @@ impl MintBuilder {
self
}

pub fn with_fee(mut self, fee_percent: f32, fee_reserve_min: u64) -> MintBuilder {
self.fee_percent = Some(fee_percent);
self.fee_reserve_min = Some(fee_reserve_min);
pub fn with_fee(mut self, fee_config: LightningFeeConfig) -> MintBuilder {
self.fee_config = Some(fee_config);
self
}

Expand Down Expand Up @@ -298,19 +296,13 @@ impl MintBuilder {
);
db.migrate().await;

let fee_config = LightningFeeConfig::new(
self.fee_percent.expect("LIGHTNING_FEE_PERCENT not set"),
self.fee_reserve_min
.expect("LIGHTNING_RESERVE_FEE_MIN not set"),
);

Ok(Mint::new(
self.private_key.expect("MINT_PRIVATE_KEY not set"),
"".to_string(),
ln,
self.lightning_type.expect("Lightning backend not set"),
db,
fee_config,
self.fee_config.expect("fee-config not set"),
self.mint_info_settings.unwrap_or_default(),
))
}
Expand Down
1 change: 1 addition & 0 deletions moksha-mint/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ pub async fn run_server(
}
info!("listening on: {}", addr);
info!("mint-info (legacy): {:?}", mint.mint_info);
info!("lightning fee-reserve: {:?}", mint.lightning_fee_config);
info!("lightning-backend: {}", mint.lightning_type);

let listener = tokio::net::TcpListener::bind(&addr).await.unwrap();
Expand Down

0 comments on commit 6c94150

Please sign in to comment.