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

feat: bolt12 #370

Closed
wants to merge 27 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
0848ad4
feat: pay bolt12 (backends not impl)
thesimplekid Sep 27, 2024
b1b6d4c
feat: phd pay offer
thesimplekid Oct 1, 2024
1c2c7a3
feat: cdk-cli melt bolt12
thesimplekid Oct 1, 2024
880fcc5
chore: update phd-rs
thesimplekid Oct 2, 2024
cd591ab
fix: check phd has valid payment id
thesimplekid Oct 2, 2024
f1494c5
fix: add unknown state to sql
thesimplekid Oct 2, 2024
113a449
feat: cln fetch invoice
thesimplekid Oct 2, 2024
fc046b7
feat: cln pay bolt12
thesimplekid Oct 2, 2024
de6e75e
feat: logging amoints
thesimplekid Oct 3, 2024
0933111
fix: phd fee
thesimplekid Oct 3, 2024
0b1464a
feat: bolt12 mint endpoints
thesimplekid Oct 3, 2024
d249f65
chore: clippy
thesimplekid Oct 4, 2024
bed9543
feat: cln mint via bolt12
thesimplekid Oct 4, 2024
25d8fde
feat: cdk-cli mint bolt12
thesimplekid Oct 4, 2024
98d7489
feat: mint cli
thesimplekid Oct 4, 2024
aa0ccab
feat: bolt12 info
thesimplekid Oct 4, 2024
f364fad
feat: wait any invoice, use offer id
thesimplekid Oct 5, 2024
2ac7c08
feat: add bolt12 router
thesimplekid Oct 6, 2024
bc2d114
feat: add cancel to wait invoice
thesimplekid Oct 6, 2024
590ad0d
feat: nut18/19 settings
thesimplekid Oct 7, 2024
122130e
feat: nut18/19 mint melt settings
thesimplekid Oct 7, 2024
10d8435
refactor: ln backend set up helpers
thesimplekid Oct 8, 2024
b34aa44
refactor: ln routers
thesimplekid Oct 8, 2024
24b637e
fix: rename cdk-mintd bin
thesimplekid Oct 8, 2024
baee4ea
fix: itest kill script
thesimplekid Oct 8, 2024
6bbfd56
feat: mint builder
thesimplekid Oct 8, 2024
54b783a
feat: use mintbuilder
thesimplekid Oct 9, 2024
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
Prev Previous commit
Next Next commit
feat: add bolt12 router
thesimplekid committed Oct 6, 2024
commit 2ac7c08eb2c3bcec81d6f7d12000e773bc122801
33 changes: 31 additions & 2 deletions crates/cdk-axum/src/lib.rs
Original file line number Diff line number Diff line change
@@ -23,7 +23,12 @@ pub struct MintState {
}

/// Create mint [`Router`] with required endpoints for cashu mint
pub async fn create_mint_router(mint: Arc<Mint>, cache_ttl: u64, cache_tti: u64) -> Result<Router> {
pub async fn create_mint_router(
mint: Arc<Mint>,
cache_ttl: u64,
cache_tti: u64,
include_bolt12: bool,
) -> Result<Router> {
let state = MintState {
mint,
cache: Cache::builder()
@@ -33,7 +38,7 @@ pub async fn create_mint_router(mint: Arc<Mint>, cache_ttl: u64, cache_tti: u64)
.build(),
};

let v1_router = Router::new()
let mut v1_router = Router::new()
.route("/keys", get(get_keys))
.route("/keysets", get(get_keysets))
.route("/keys/:keyset_id", get(get_keyset_pubkeys))
@@ -54,7 +59,31 @@ pub async fn create_mint_router(mint: Arc<Mint>, cache_ttl: u64, cache_tti: u64)
.route("/info", get(get_mint_info))
.route("/restore", post(post_restore));

// Conditionally create and merge bolt12_router
if include_bolt12 {
let bolt12_router = create_bolt12_router(state.clone());
v1_router = v1_router.merge(bolt12_router);
}

// Nest the combined router under "/v1"
let mint_router = Router::new().nest("/v1", v1_router).with_state(state);

Ok(mint_router)
}

fn create_bolt12_router(state: MintState) -> Router<MintState> {
Router::new()
.route("/melt/quote/bolt12", post(get_melt_bolt12_quote))
.route(
"/melt/quote/bolt12/:quote_id",
get(get_check_melt_bolt11_quote),
)
.route("/melt/bolt12", post(post_melt_bolt12))
.route("/mint/quote/bolt12", post(get_mint_bolt12_quote))
.route(
"/mint/quote/bolt12/:quote_id",
get(get_check_mint_bolt11_quote),
)
.route("/mint/bolt12", post(post_mint_bolt12))
.with_state(state)
}
7 changes: 4 additions & 3 deletions crates/cdk-integration-tests/src/init_fake_wallet.rs
Original file line number Diff line number Diff line change
@@ -65,9 +65,10 @@ where
let cache_tti = 3600;
let mint_arc = Arc::new(mint);

let v1_service = cdk_axum::create_mint_router(Arc::clone(&mint_arc), cache_ttl, cache_tti)
.await
.unwrap();
let v1_service =
cdk_axum::create_mint_router(Arc::clone(&mint_arc), cache_ttl, cache_tti, false)
.await
.unwrap();

let mint_service = Router::new()
.merge(v1_service)
1 change: 1 addition & 0 deletions crates/cdk-integration-tests/src/init_regtest.rs
Original file line number Diff line number Diff line change
@@ -222,6 +222,7 @@ where
Arc::clone(&mint_arc),
cache_time_to_live,
cache_time_to_idle,
false,
)
.await
.unwrap();
2 changes: 1 addition & 1 deletion crates/cdk-integration-tests/src/lib.rs
Original file line number Diff line number Diff line change
@@ -88,11 +88,11 @@ pub async fn start_mint(
let cache_time_to_idle = 3600;

let mint_arc = Arc::new(mint);

let v1_service = cdk_axum::create_mint_router(
Arc::clone(&mint_arc),
cache_time_to_live,
cache_time_to_idle,
false,
)
.await?;

2 changes: 2 additions & 0 deletions crates/cdk-mintd/src/config.rs
Original file line number Diff line number Diff line change
@@ -53,6 +53,7 @@ pub struct LNbits {
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct Cln {
pub rpc_path: PathBuf,
pub bolt12: bool,
}

#[derive(Debug, Clone, Serialize, Deserialize, Default)]
@@ -66,6 +67,7 @@ pub struct Lnd {
pub struct Phoenixd {
pub api_password: String,
pub api_url: String,
pub bolt12: bool,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
62 changes: 45 additions & 17 deletions crates/cdk-mintd/src/main.rs
Original file line number Diff line number Diff line change
@@ -140,12 +140,15 @@ async fn main() -> anyhow::Result<()> {

let mint_url: MintUrl = settings.info.url.parse()?;

let include_bolt12;

let ln_routers: Vec<Router> = match settings.ln.ln_backend {
LnBackend::Cln => {
let cln_settings = settings
.cln
.expect("Config checked at load that cln is some");
let cln_socket = expand_path(
settings
.cln
.expect("Config checked at load that cln is some")
cln_settings
.rpc_path
.to_str()
.ok_or(anyhow!("cln socket not defined"))?,
@@ -165,7 +168,15 @@ async fn main() -> anyhow::Result<()> {
LnKey::new(CurrencyUnit::Sat, PaymentMethod::Bolt11),
cln.clone(),
);
ln_backends.insert(LnKey::new(CurrencyUnit::Sat, PaymentMethod::Bolt12), cln);

if cln_settings.bolt12 {
ln_backends.insert(LnKey::new(CurrencyUnit::Sat, PaymentMethod::Bolt12), cln);

include_bolt12 = true;
} else {
include_bolt12 = false;
}

supported_units.insert(CurrencyUnit::Sat, (input_fee_ppk, 64));
vec![]
}
@@ -208,6 +219,8 @@ async fn main() -> anyhow::Result<()> {
supported_units.insert(unit, (input_fee_ppk, 64));
}

include_bolt12 = false;

routers
}
LnBackend::LNbits => {
@@ -244,20 +257,14 @@ async fn main() -> anyhow::Result<()> {
ln_backends.insert(ln_key, Arc::new(lnbits));

supported_units.insert(unit, (input_fee_ppk, 64));
include_bolt12 = false;
vec![router]
}
LnBackend::Phoenixd => {
let api_password = settings
.clone()
.phoenixd
.expect("Checked at config load")
.api_password;

let api_url = settings
.clone()
.phoenixd
.expect("Checked at config load")
.api_url;
let phd_settings = settings.phoenixd.expect("Checked at config load");
let api_password = phd_settings.api_password;

let api_url = phd_settings.api_url;

if fee_reserve.percent_fee_reserve < 0.04 {
bail!("Fee reserve is too low needs to be at least 0.02");
@@ -286,14 +293,30 @@ async fn main() -> anyhow::Result<()> {
.await?;

supported_units.insert(CurrencyUnit::Sat, (input_fee_ppk, 64));

let phd = Arc::new(phoenixd);
ln_backends.insert(
LnKey {
unit: CurrencyUnit::Sat,
method: PaymentMethod::Bolt11,
},
Arc::new(phoenixd),
phd.clone(),
);

if phd_settings.bolt12 {
ln_backends.insert(
LnKey {
unit: CurrencyUnit::Sat,
method: PaymentMethod::Bolt12,
},
phd,
);

include_bolt12 = true;
} else {
include_bolt12 = false;
}

vec![router]
}
LnBackend::Lnd => {
@@ -322,6 +345,8 @@ async fn main() -> anyhow::Result<()> {
Arc::new(lnd),
);

include_bolt12 = false;

vec![]
}
LnBackend::FakeWallet => {
@@ -344,6 +369,8 @@ async fn main() -> anyhow::Result<()> {
supported_units.insert(unit, (input_fee_ppk, 64));
}

include_bolt12 = false;

vec![]
}
};
@@ -473,7 +500,8 @@ async fn main() -> anyhow::Result<()> {
.seconds_to_extend_cache_by
.unwrap_or(DEFAULT_CACHE_TTI_SECS);

let v1_service = cdk_axum::create_mint_router(Arc::clone(&mint), cache_ttl, cache_tti).await?;
let v1_service =
cdk_axum::create_mint_router(Arc::clone(&mint), cache_ttl, cache_tti, false).await?;

let mut mint_service = Router::new()
.merge(v1_service)