diff --git a/crates/cdk-sqlite/src/mint/migrations/20241117101725_bolt12_migration.sql b/crates/cdk-sqlite/src/mint/migrations/20241117101725_bolt12_migration.sql new file mode 100644 index 00000000..94e48f21 --- /dev/null +++ b/crates/cdk-sqlite/src/mint/migrations/20241117101725_bolt12_migration.sql @@ -0,0 +1,6 @@ +ALTER TABLE mint_quote ADD single_use INTEGER; +ALTER TABLE mint_quote ADD payment_method TEXT; +ALTER TABLE mint_quote ADD payment_ids TEXT; +ALTER TABLE mint_quote ADD amount_paid INTEGER; +ALTER TABLE mint_quote ADD amount_issued INTEGER; + diff --git a/crates/cdk-sqlite/src/mint/mod.rs b/crates/cdk-sqlite/src/mint/mod.rs index ba5d14df..bb2033a6 100644 --- a/crates/cdk-sqlite/src/mint/mod.rs +++ b/crates/cdk-sqlite/src/mint/mod.rs @@ -206,8 +206,8 @@ WHERE active = 1 let res = sqlx::query( r#" INSERT OR REPLACE INTO mint_quote -(id, mint_url, amount, unit, request, state, expiry, request_lookup_id) -VALUES (?, ?, ?, ?, ?, ?, ?, ?); +(id, mint_url, amount, unit, request, state, expiry, request_lookup_id, single_use, payment_method, payment_ids, amount_paid, amount_issued) +VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?); "#, ) .bind(quote.id.to_string()) @@ -219,6 +219,11 @@ VALUES (?, ?, ?, ?, ?, ?, ?, ?); .bind(quote.state.to_string()) .bind(quote.expiry as i64) .bind(quote.request_lookup_id) + .bind(quote.single_use) + .bind(quote.payment_method.to_string()) + .bind(serde_json::to_string("e.payment_ids)?) + .bind(u64::from(quote.amount_paid) as i64) + .bind(u64::from(quote.amount_issued) as i64 ) .execute(&mut transaction) .await; @@ -1279,6 +1284,11 @@ fn sqlite_row_to_mint_quote(row: SqliteRow) -> Result { let row_expiry: i64 = row.try_get("expiry").map_err(Error::from)?; let row_request_lookup_id: Option = row.try_get("request_lookup_id").map_err(Error::from)?; + let row_single_use: Option = row.try_get("single_use").map_err(Error::from)?; + let row_amount_paid: Option = row.try_get("amount_paid").map_err(Error::from)?; + let row_amount_issued: Option = row.try_get("amount_issued").map_err(Error::from)?; + let row_payment_method: Option = row.try_get("payment_method").map_err(Error::from)?; + let row_payment_ids: Option = row.try_get("payment_ids").map_err(Error::from)?; let request_lookup_id = match row_request_lookup_id { Some(id) => id, @@ -1288,6 +1298,16 @@ fn sqlite_row_to_mint_quote(row: SqliteRow) -> Result { }, }; + let payment_method = match row_payment_method { + Some(method) => PaymentMethod::from_str(&method)?, + None => PaymentMethod::Bolt11, + }; + + let payment_ids: Vec = match row_payment_ids { + Some(ids) => serde_json::from_str(&ids)?, + None => vec![], + }; + Ok(MintQuote { id: row_id, mint_url: MintUrl::from_str(&row_mint_url)?, @@ -1297,12 +1317,11 @@ fn sqlite_row_to_mint_quote(row: SqliteRow) -> Result { state: MintQuoteState::from_str(&row_state).map_err(Error::from)?, expiry: row_expiry as u64, request_lookup_id, - // TODO: Get these values - amount_paid: Amount::ZERO, - amount_issued: Amount::ZERO, - single_use: true, - payment_method: PaymentMethod::Bolt11, - payment_ids: Vec::new(), + amount_paid: (row_amount_paid.unwrap_or_default() as u64).into(), + amount_issued: (row_amount_issued.unwrap_or_default() as u64).into(), + single_use: row_single_use.unwrap_or(true), + payment_method, + payment_ids, }) }