Skip to content

Commit

Permalink
feat: mint builder to cdk
Browse files Browse the repository at this point in the history
  • Loading branch information
thesimplekid committed Nov 6, 2024
1 parent a0e0899 commit 05b8bb1
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
1 change: 0 additions & 1 deletion crates/cdk-mintd/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use std::path::PathBuf;

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

fn expand_path(path: &str) -> Option<PathBuf> {
Expand Down
2 changes: 1 addition & 1 deletion crates/cdk-mintd/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ use cdk::cdk_database::{self, MintDatabase};
use cdk::cdk_lightning;
use cdk::cdk_lightning::MintLightning;
use cdk::mint::{MeltQuote, Mint};
use cdk::mint::{MintBuilder, MintMeltLimits};
use cdk::nuts::{ContactInfo, CurrencyUnit, MeltQuoteState, MintVersion, PaymentMethod};
use cdk::types::LnKey;
use cdk_mintd::mint::{MintBuilder, MintMeltLimits};
use cdk_mintd::setup::LnBackendSetup;
use cdk_redb::MintRedbDatabase;
use cdk_sqlite::MintSqliteDatabase;
Expand Down
18 changes: 13 additions & 5 deletions crates/cdk-mintd/src/mint.rs → crates/cdk/src/mint/builder.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
use core::panic;
//! Mint Builder
use std::{collections::HashMap, sync::Arc};

use anyhow::anyhow;
use cdk::{

use crate::{
amount::Amount,
cdk_database::{self, MintDatabase},
cdk_lightning::{self, MintLightning},
Expand Down Expand Up @@ -31,6 +33,7 @@ pub struct MintBuilder {
}

impl MintBuilder {
/// New mint builder
pub fn new() -> MintBuilder {
MintBuilder::default()
}
Expand All @@ -44,7 +47,7 @@ impl MintBuilder {
self
}

// Set mint url
/// Set mint url
pub fn with_mint_url(mut self, mint_url: String) -> Self {
self.mint_url = Some(mint_url);
self
Expand Down Expand Up @@ -181,7 +184,6 @@ impl MintBuilder {

self.mint_info.nuts.nut19 = Some(nut19_settings);
}
_ => panic!("Unsupported unit"),
}

ln.insert(ln_key.clone(), ln_backend);
Expand All @@ -206,12 +208,13 @@ impl MintBuilder {
}

/// Set pubkey
pub fn with_pubkey(mut self, pubkey: cdk::nuts::PublicKey) -> Self {
pub fn with_pubkey(mut self, pubkey: crate::nuts::PublicKey) -> Self {
self.mint_info.pubkey = Some(pubkey);

self
}

/// Build mint
pub async fn build(&self) -> anyhow::Result<Mint> {
Ok(Mint::new(
self.mint_url.as_ref().ok_or(anyhow!("Mint url not set"))?,
Expand All @@ -231,10 +234,15 @@ impl MintBuilder {
}
}

/// Mint Melt Limits
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
pub struct MintMeltLimits {
/// Min mint amount
pub mint_min: Amount,
/// Max mint amount
pub mint_max: Amount,
/// Min melt amount
pub melt_min: Amount,
/// Max melt amount
pub melt_max: Amount,
}
2 changes: 2 additions & 0 deletions crates/cdk/src/mint/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ use crate::types::{LnKey, QuoteTTL};
use crate::util::unix_time;
use crate::Amount;

mod builder;
mod check_spendable;
mod info;
mod keysets;
Expand All @@ -34,6 +35,7 @@ mod mint_nut04;
mod swap;
pub mod types;

pub use builder::{MintBuilder, MintMeltLimits};
pub use types::{MeltQuote, MintQuote};

/// Cashu Mint
Expand Down
8 changes: 4 additions & 4 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
description = "CDK Flake";

inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.05";
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";

rust-overlay = {
url = "github:oxalica/rust-overlay";
Expand Down

0 comments on commit 05b8bb1

Please sign in to comment.