fix: cdk melt quote track payment method (#1021)

Add payment_method field to MeltQuote struct to track whether quotes use BOLT11 or BOLT12 payment methods. Include database migrations for both SQLite and PostgreSQL to support the new field. Update melt operations to set and use the payment method for proper routing between BOLT11 and BOLT12 endpoints.
This commit is contained in:
thesimplekid
2025-09-01 08:39:51 +01:00
committed by GitHub
parent 7246ea2e10
commit 6067242793
8 changed files with 38 additions and 7 deletions

View File

@@ -2,6 +2,7 @@
/// Auto-generated by build.rs
pub static MIGRATIONS: &[(&str, &str, &str)] = &[
("postgres", "1_initial.sql", include_str!(r#"./migrations/postgres/1_initial.sql"#)),
("postgres", "20250831215438_melt_quote_method.sql", include_str!(r#"./migrations/postgres/20250831215438_melt_quote_method.sql"#)),
("sqlite", "1_fix_sqlx_migration.sql", include_str!(r#"./migrations/sqlite/1_fix_sqlx_migration.sql"#)),
("sqlite", "20240612132920_init.sql", include_str!(r#"./migrations/sqlite/20240612132920_init.sql"#)),
("sqlite", "20240618200350_quote_state.sql", include_str!(r#"./migrations/sqlite/20240618200350_quote_state.sql"#)),
@@ -22,4 +23,5 @@ pub static MIGRATIONS: &[(&str, &str, &str)] = &[
("sqlite", "20250707093445_bolt12.sql", include_str!(r#"./migrations/sqlite/20250707093445_bolt12.sql"#)),
("sqlite", "20250729111701_keyset_v2_u32.sql", include_str!(r#"./migrations/sqlite/20250729111701_keyset_v2_u32.sql"#)),
("sqlite", "20250812084621_keyset_plus_one.sql", include_str!(r#"./migrations/sqlite/20250812084621_keyset_plus_one.sql"#)),
("sqlite", "20250831215438_melt_quote_method.sql", include_str!(r#"./migrations/sqlite/20250831215438_melt_quote_method.sql"#)),
];

View File

@@ -0,0 +1 @@
ALTER TABLE melt_quote ADD COLUMN payment_method TEXT NOT NULL DEFAULT 'bolt11';

View File

@@ -0,0 +1 @@
ALTER TABLE melt_quote ADD COLUMN payment_method TEXT NOT NULL DEFAULT 'bolt11';

View File

@@ -156,7 +156,8 @@ where
fee_reserve,
state,
expiry,
payment_preimage
payment_preimage,
payment_method
FROM
melt_quote
"#,
@@ -579,16 +580,17 @@ ON CONFLICT(id) DO UPDATE SET
query(
r#"
INSERT INTO melt_quote
(id, unit, amount, request, fee_reserve, state, expiry)
(id, unit, amount, request, fee_reserve, state, expiry, payment_method)
VALUES
(:id, :unit, :amount, :request, :fee_reserve, :state, :expiry)
(:id, :unit, :amount, :request, :fee_reserve, :state, :expiry, :payment_method)
ON CONFLICT(id) DO UPDATE SET
unit = excluded.unit,
amount = excluded.amount,
request = excluded.request,
fee_reserve = excluded.fee_reserve,
state = excluded.state,
expiry = excluded.expiry
expiry = excluded.expiry,
payment_method = excluded.payment_method
;
"#,
)?
@@ -599,6 +601,7 @@ ON CONFLICT(id) DO UPDATE SET
.bind("fee_reserve", u64::from(quote.fee_reserve) as i64)
.bind("state", quote.state.to_string())
.bind("expiry", quote.expiry as i64)
.bind("payment_method", quote.payment_method.to_string())
.execute(&*conn)
.await?;
@@ -618,7 +621,8 @@ ON CONFLICT(id) DO UPDATE SET
fee_reserve,
state,
expiry,
payment_preimage
payment_preimage,
payment_method
FROM
melt_quote
WHERE
@@ -1124,13 +1128,17 @@ fn sql_row_to_melt_quote(row: Vec<Column>) -> Result<wallet::MeltQuote, Error> {
fee_reserve,
state,
expiry,
payment_preimage
payment_preimage,
row_method
) = row
);
let amount: u64 = column_as_number!(amount);
let fee_reserve: u64 = column_as_number!(fee_reserve);
let payment_method =
PaymentMethod::from_str(&column_as_string!(row_method)).map_err(Error::from)?;
Ok(wallet::MeltQuote {
id: column_as_string!(id),
amount: Amount::from(amount),
@@ -1140,6 +1148,7 @@ fn sql_row_to_melt_quote(row: Vec<Column>) -> Result<wallet::MeltQuote, Error> {
state: column_as_string!(state, MeltQuoteState::from_str),
expiry: column_as_number!(expiry),
payment_preimage: column_as_nullable_string!(payment_preimage),
payment_method,
})
}