Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mint builder #441

Merged
merged 2 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .helix/languages.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[language-server.rust-analyzer.config]
cargo = { features = ["wallet", "mint"] }
cargo = { features = ["wallet", "mint", "swagger"] }
18 changes: 2 additions & 16 deletions crates/cdk-cln/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@ use cdk::cdk_lightning::{
self, CreateInvoiceResponse, MintLightning, PayInvoiceResponse, PaymentQuoteResponse, Settings,
};
use cdk::mint::FeeReserve;
use cdk::nuts::{
CurrencyUnit, MeltMethodSettings, MeltQuoteBolt11Request, MeltQuoteState, MintMethodSettings,
MintQuoteState,
};
use cdk::nuts::{CurrencyUnit, MeltQuoteBolt11Request, MeltQuoteState, MintQuoteState};
use cdk::util::{hex, unix_time};
use cdk::{mint, Bolt11Invoice};
use cln_rpc::model::requests::{
Expand All @@ -45,28 +42,19 @@ pub struct Cln {
rpc_socket: PathBuf,
cln_client: Arc<Mutex<cln_rpc::ClnRpc>>,
fee_reserve: FeeReserve,
mint_settings: MintMethodSettings,
melt_settings: MeltMethodSettings,
wait_invoice_cancel_token: CancellationToken,
wait_invoice_is_active: Arc<AtomicBool>,
}

impl Cln {
/// Create new [`Cln`]
pub async fn new(
rpc_socket: PathBuf,
fee_reserve: FeeReserve,
mint_settings: MintMethodSettings,
melt_settings: MeltMethodSettings,
) -> Result<Self, Error> {
pub async fn new(rpc_socket: PathBuf, fee_reserve: FeeReserve) -> Result<Self, Error> {
let cln_client = cln_rpc::ClnRpc::new(&rpc_socket).await?;

Ok(Self {
rpc_socket,
cln_client: Arc::new(Mutex::new(cln_client)),
fee_reserve,
mint_settings,
melt_settings,
wait_invoice_cancel_token: CancellationToken::new(),
wait_invoice_is_active: Arc::new(AtomicBool::new(false)),
})
Expand All @@ -81,8 +69,6 @@ impl MintLightning for Cln {
Settings {
mpp: true,
unit: CurrencyUnit::Msat,
mint_settings: self.mint_settings.clone(),
melt_settings: self.melt_settings.clone(),
invoice_description: true,
}
}
Expand Down
13 changes: 1 addition & 12 deletions crates/cdk-fake-wallet/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@ use cdk::cdk_lightning::{
};
use cdk::mint;
use cdk::mint::FeeReserve;
use cdk::nuts::{
CurrencyUnit, MeltMethodSettings, MeltQuoteBolt11Request, MeltQuoteState, MintMethodSettings,
MintQuoteState,
};
use cdk::nuts::{CurrencyUnit, MeltQuoteBolt11Request, MeltQuoteState, MintQuoteState};
use cdk::util::unix_time;
use error::Error;
use futures::stream::StreamExt;
Expand All @@ -44,8 +41,6 @@ pub struct FakeWallet {
fee_reserve: FeeReserve,
sender: tokio::sync::mpsc::Sender<String>,
receiver: Arc<Mutex<Option<tokio::sync::mpsc::Receiver<String>>>>,
mint_settings: MintMethodSettings,
melt_settings: MeltMethodSettings,
payment_states: Arc<Mutex<HashMap<String, MeltQuoteState>>>,
failed_payment_check: Arc<Mutex<HashSet<String>>>,
payment_delay: u64,
Expand All @@ -57,8 +52,6 @@ impl FakeWallet {
/// Creat new [`FakeWallet`]
pub fn new(
fee_reserve: FeeReserve,
mint_settings: MintMethodSettings,
melt_settings: MeltMethodSettings,
payment_states: HashMap<String, MeltQuoteState>,
fail_payment_check: HashSet<String>,
payment_delay: u64,
Expand All @@ -69,8 +62,6 @@ impl FakeWallet {
fee_reserve,
sender,
receiver: Arc::new(Mutex::new(Some(receiver))),
mint_settings,
melt_settings,
payment_states: Arc::new(Mutex::new(payment_states)),
failed_payment_check: Arc::new(Mutex::new(fail_payment_check)),
payment_delay,
Expand Down Expand Up @@ -112,8 +103,6 @@ impl MintLightning for FakeWallet {
Settings {
mpp: true,
unit: CurrencyUnit::Msat,
mint_settings: self.mint_settings.clone(),
melt_settings: self.melt_settings.clone(),
invoice_description: true,
}
}
Expand Down
11 changes: 2 additions & 9 deletions crates/cdk-integration-tests/src/init_fake_wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use cdk::{
cdk_database::{self, MintDatabase},
cdk_lightning::MintLightning,
mint::FeeReserve,
nuts::{CurrencyUnit, MeltMethodSettings, MintMethodSettings},
nuts::CurrencyUnit,
types::LnKey,
};
use cdk_fake_wallet::FakeWallet;
Expand Down Expand Up @@ -46,14 +46,7 @@ where
percent_fee_reserve: 1.0,
};

let fake_wallet = FakeWallet::new(
fee_reserve,
MintMethodSettings::default(),
MeltMethodSettings::default(),
HashMap::default(),
HashSet::default(),
0,
);
let fake_wallet = FakeWallet::new(fee_reserve, HashMap::default(), HashSet::default(), 0);

ln_backends.insert(
LnKey::new(CurrencyUnit::Sat, cdk::nuts::PaymentMethod::Bolt11),
Expand Down
10 changes: 2 additions & 8 deletions crates/cdk-integration-tests/src/init_regtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use cdk::{
cdk_database::{self, MintDatabase},
cdk_lightning::MintLightning,
mint::{FeeReserve, Mint},
nuts::{CurrencyUnit, MeltMethodSettings, MintInfo, MintMethodSettings},
nuts::{CurrencyUnit, MintInfo},
types::{LnKey, QuoteTTL},
};
use cdk_cln::Cln as CdkCln;
Expand Down Expand Up @@ -131,13 +131,7 @@ pub async fn create_cln_backend(cln_client: &ClnClient) -> Result<CdkCln> {
percent_fee_reserve: 1.0,
};

Ok(CdkCln::new(
rpc_path,
fee_reserve,
MintMethodSettings::default(),
MeltMethodSettings::default(),
)
.await?)
Ok(CdkCln::new(rpc_path, fee_reserve).await?)
}

pub async fn create_mint<D>(
Expand Down
6 changes: 2 additions & 4 deletions crates/cdk-integration-tests/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ use cdk::cdk_lightning::MintLightning;
use cdk::dhke::construct_proofs;
use cdk::mint::FeeReserve;
use cdk::nuts::{
CurrencyUnit, Id, KeySet, MeltMethodSettings, MintBolt11Request, MintInfo, MintMethodSettings,
MintQuoteBolt11Request, MintQuoteState, Nuts, PaymentMethod, PreMintSecrets, Proofs, State,
CurrencyUnit, Id, KeySet, MintBolt11Request, MintInfo, MintQuoteBolt11Request, MintQuoteState,
Nuts, PaymentMethod, PreMintSecrets, Proofs, State,
};
use cdk::types::{LnKey, QuoteTTL};
use cdk::wallet::client::{HttpClient, HttpClientMethods};
Expand Down Expand Up @@ -40,8 +40,6 @@ pub fn create_backends_fake_wallet(

let wallet = Arc::new(FakeWallet::new(
fee_reserve.clone(),
MintMethodSettings::default(),
MeltMethodSettings::default(),
HashMap::default(),
HashSet::default(),
0,
Expand Down
13 changes: 1 addition & 12 deletions crates/cdk-lnbits/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@ use cdk::cdk_lightning::{
self, CreateInvoiceResponse, MintLightning, PayInvoiceResponse, PaymentQuoteResponse, Settings,
};
use cdk::mint::FeeReserve;
use cdk::nuts::{
CurrencyUnit, MeltMethodSettings, MeltQuoteBolt11Request, MeltQuoteState, MintMethodSettings,
MintQuoteState,
};
use cdk::nuts::{CurrencyUnit, MeltQuoteBolt11Request, MeltQuoteState, MintQuoteState};
use cdk::util::unix_time;
use cdk::{mint, Bolt11Invoice};
use error::Error;
Expand All @@ -35,8 +32,6 @@ pub mod error;
#[derive(Clone)]
pub struct LNbits {
lnbits_api: LNBitsClient,
mint_settings: MintMethodSettings,
melt_settings: MeltMethodSettings,
fee_reserve: FeeReserve,
receiver: Arc<Mutex<Option<tokio::sync::mpsc::Receiver<String>>>>,
webhook_url: String,
Expand All @@ -51,8 +46,6 @@ impl LNbits {
admin_api_key: String,
invoice_api_key: String,
api_url: String,
mint_settings: MintMethodSettings,
melt_settings: MeltMethodSettings,
fee_reserve: FeeReserve,
receiver: Arc<Mutex<Option<tokio::sync::mpsc::Receiver<String>>>>,
webhook_url: String,
Expand All @@ -61,8 +54,6 @@ impl LNbits {

Ok(Self {
lnbits_api,
mint_settings,
melt_settings,
receiver,
fee_reserve,
webhook_url,
Expand All @@ -80,8 +71,6 @@ impl MintLightning for LNbits {
Settings {
mpp: false,
unit: CurrencyUnit::Sat,
mint_settings: self.mint_settings.clone(),
melt_settings: self.melt_settings.clone(),
invoice_description: true,
}
}
Expand Down
13 changes: 1 addition & 12 deletions crates/cdk-lnd/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@ use cdk::cdk_lightning::{
self, CreateInvoiceResponse, MintLightning, PayInvoiceResponse, PaymentQuoteResponse, Settings,
};
use cdk::mint::FeeReserve;
use cdk::nuts::{
CurrencyUnit, MeltMethodSettings, MeltQuoteBolt11Request, MeltQuoteState, MintMethodSettings,
MintQuoteState,
};
use cdk::nuts::{CurrencyUnit, MeltQuoteBolt11Request, MeltQuoteState, MintQuoteState};
use cdk::util::{hex, unix_time};
use cdk::{mint, Bolt11Invoice};
use error::Error;
Expand All @@ -43,8 +40,6 @@ pub struct Lnd {
macaroon_file: PathBuf,
client: Arc<Mutex<Client>>,
fee_reserve: FeeReserve,
mint_settings: MintMethodSettings,
melt_settings: MeltMethodSettings,
wait_invoice_cancel_token: CancellationToken,
wait_invoice_is_active: Arc<AtomicBool>,
}
Expand All @@ -56,8 +51,6 @@ impl Lnd {
cert_file: PathBuf,
macaroon_file: PathBuf,
fee_reserve: FeeReserve,
mint_settings: MintMethodSettings,
melt_settings: MeltMethodSettings,
) -> Result<Self, Error> {
let client = fedimint_tonic_lnd::connect(address.to_string(), &cert_file, &macaroon_file)
.await
Expand All @@ -72,8 +65,6 @@ impl Lnd {
macaroon_file,
client: Arc::new(Mutex::new(client)),
fee_reserve,
mint_settings,
melt_settings,
wait_invoice_cancel_token: CancellationToken::new(),
wait_invoice_is_active: Arc::new(AtomicBool::new(false)),
})
Expand All @@ -88,8 +79,6 @@ impl MintLightning for Lnd {
Settings {
mpp: true,
unit: CurrencyUnit::Msat,
mint_settings: self.mint_settings.clone(),
melt_settings: self.melt_settings.clone(),
invoice_description: true,
}
}
Expand Down
35 changes: 32 additions & 3 deletions crates/cdk-mintd/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,27 @@ pub enum LnBackend {
Lnd,
}

#[derive(Debug, Clone, Serialize, Deserialize, Default)]
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Ln {
pub ln_backend: LnBackend,
pub invoice_description: Option<String>,
pub fee_percent: f32,
pub reserve_fee_min: Amount,
pub min_mint: Amount,
pub max_mint: Amount,
pub min_melt: Amount,
pub max_melt: Amount,
}

impl Default for Ln {
fn default() -> Self {
Ln {
ln_backend: LnBackend::default(),
invoice_description: None,
min_mint: 1.into(),
max_mint: 500_000.into(),
min_melt: 1.into(),
max_melt: 500_000.into(),
}
}
}

#[derive(Debug, Clone, Serialize, Deserialize, Default)]
Expand All @@ -54,35 +69,49 @@ pub struct LNbits {
pub admin_api_key: String,
pub invoice_api_key: String,
pub lnbits_api: String,
pub fee_percent: f32,
pub reserve_fee_min: Amount,
}

#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct Cln {
pub rpc_path: PathBuf,
pub bolt12: bool,
pub fee_percent: f32,
pub reserve_fee_min: Amount,
}

#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct Lnd {
pub address: String,
pub cert_file: PathBuf,
pub macaroon_file: PathBuf,
pub fee_percent: f32,
pub reserve_fee_min: Amount,
}

#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct Phoenixd {
pub api_password: String,
pub api_url: String,
pub bolt12: bool,
pub fee_percent: f32,
pub reserve_fee_min: Amount,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct FakeWallet {
pub supported_units: Vec<CurrencyUnit>,
pub fee_percent: f32,
pub reserve_fee_min: Amount,
}

impl Default for FakeWallet {
fn default() -> Self {
Self {
supported_units: vec![CurrencyUnit::Sat],
fee_percent: 0.02,
reserve_fee_min: 2.into(),
}
}
}
Expand Down
22 changes: 22 additions & 0 deletions crates/cdk-mintd/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//! Cdk mintd lib

use std::path::PathBuf;

pub mod cli;
pub mod config;
pub mod setup;

fn expand_path(path: &str) -> Option<PathBuf> {
if path.starts_with('~') {
if let Some(home_dir) = home::home_dir().as_mut() {
let remainder = &path[2..];
home_dir.push(remainder);
let expanded_path = home_dir;
Some(expanded_path.clone())
} else {
None
}
} else {
Some(PathBuf::from(path))
}
}
Loading
Loading