compatibility for migrating Nutshell Mints quote ids (#984)

This commit is contained in:
lollerfirst
2025-08-27 18:12:35 +02:00
committed by GitHub
parent 971957b839
commit f1118b1c7b
33 changed files with 446 additions and 187 deletions

View File

@@ -26,6 +26,7 @@ use cdk_common::mint::{
};
use cdk_common::nut00::ProofsMethods;
use cdk_common::payment::PaymentIdentifier;
use cdk_common::quote_id::QuoteId;
use cdk_common::secret::Secret;
use cdk_common::state::check_state_transition;
use cdk_common::util::unix_time;
@@ -309,7 +310,7 @@ where
#[inline(always)]
async fn get_mint_quote_payments<C>(
conn: &C,
quote_id: &Uuid,
quote_id: &QuoteId,
) -> Result<Vec<IncomingPayment>, Error>
where
C: DatabaseExecutor + Send + Sync,
@@ -327,7 +328,13 @@ where
quote_id=:quote_id
"#,
)?
.bind("quote_id", quote_id.as_hyphenated().to_string())
.bind(
"quote_id",
match quote_id {
QuoteId::UUID(u) => u.as_hyphenated().to_string(),
QuoteId::BASE64(s) => s.to_string(),
},
)
.fetch_all(conn)
.await?
.into_iter()
@@ -344,7 +351,7 @@ where
}
#[inline(always)]
async fn get_mint_quote_issuance<C>(conn: &C, quote_id: &Uuid) -> Result<Vec<Issuance>, Error>
async fn get_mint_quote_issuance<C>(conn: &C, quote_id: &QuoteId) -> Result<Vec<Issuance>, Error>
where
C: DatabaseExecutor + Send + Sync,
{
@@ -356,7 +363,13 @@ FROM mint_quote_issued
WHERE quote_id=:quote_id
"#,
)?
.bind("quote_id", quote_id.as_hyphenated().to_string())
.bind(
"quote_id",
match quote_id {
QuoteId::UUID(u) => u.as_hyphenated().to_string(),
QuoteId::BASE64(s) => s.to_string(),
},
)
.fetch_all(conn)
.await?
.into_iter()
@@ -542,7 +555,7 @@ where
#[instrument(skip(self))]
async fn increment_mint_quote_amount_paid(
&mut self,
quote_id: &Uuid,
quote_id: &QuoteId,
amount_paid: Amount,
payment_id: String,
) -> Result<Amount, Self::Err> {
@@ -578,7 +591,13 @@ where
FOR UPDATE
"#,
)?
.bind("quote_id", quote_id.as_hyphenated().to_string())
.bind(
"quote_id",
match quote_id {
QuoteId::UUID(u) => u.as_hyphenated().to_string(),
QuoteId::BASE64(s) => s.to_string(),
},
)
.fetch_one(&self.inner)
.await
.inspect_err(|err| {
@@ -613,7 +632,13 @@ where
"#,
)?
.bind("amount_paid", new_amount_paid.to_i64())
.bind("quote_id", quote_id.as_hyphenated().to_string())
.bind(
"quote_id",
match quote_id {
QuoteId::UUID(u) => u.as_hyphenated().to_string(),
QuoteId::BASE64(s) => s.to_string(),
},
)
.execute(&self.inner)
.await
.inspect_err(|err| {
@@ -628,7 +653,13 @@ where
VALUES (:quote_id, :payment_id, :amount, :timestamp)
"#,
)?
.bind("quote_id", quote_id.as_hyphenated().to_string())
.bind(
"quote_id",
match quote_id {
QuoteId::UUID(u) => u.as_hyphenated().to_string(),
QuoteId::BASE64(s) => s.to_string(),
},
)
.bind("payment_id", payment_id)
.bind("amount", amount_paid.to_i64())
.bind("timestamp", unix_time() as i64)
@@ -645,7 +676,7 @@ where
#[instrument(skip_all)]
async fn increment_mint_quote_amount_issued(
&mut self,
quote_id: &Uuid,
quote_id: &QuoteId,
amount_issued: Amount,
) -> Result<Amount, Self::Err> {
// Get current amount_issued from quote
@@ -657,7 +688,13 @@ where
FOR UPDATE
"#,
)?
.bind("quote_id", quote_id.as_hyphenated().to_string())
.bind(
"quote_id",
match quote_id {
QuoteId::UUID(u) => u.as_hyphenated().to_string(),
QuoteId::BASE64(s) => s.to_string(),
},
)
.fetch_one(&self.inner)
.await
.inspect_err(|err| {
@@ -685,7 +722,13 @@ where
"#,
)?
.bind("amount_issued", new_amount_issued.to_i64())
.bind("quote_id", quote_id.as_hyphenated().to_string())
.bind(
"quote_id",
match quote_id {
QuoteId::UUID(u) => u.as_hyphenated().to_string(),
QuoteId::BASE64(s) => s.to_string(),
},
)
.execute(&self.inner)
.await
.inspect_err(|err| {
@@ -701,7 +744,13 @@ INSERT INTO mint_quote_issued
VALUES (:quote_id, :amount, :timestamp);
"#,
)?
.bind("quote_id", quote_id.as_hyphenated().to_string())
.bind(
"quote_id",
match quote_id {
QuoteId::UUID(u) => u.as_hyphenated().to_string(),
QuoteId::BASE64(s) => s.to_string(),
},
)
.bind("amount", amount_issued.to_i64())
.bind("timestamp", current_time as i64)
.execute(&self.inner)
@@ -741,9 +790,15 @@ VALUES (:quote_id, :amount, :timestamp);
Ok(())
}
async fn remove_mint_quote(&mut self, quote_id: &Uuid) -> Result<(), Self::Err> {
async fn remove_mint_quote(&mut self, quote_id: &QuoteId) -> Result<(), Self::Err> {
query(r#"DELETE FROM mint_quote WHERE id=:id"#)?
.bind("id", quote_id.as_hyphenated().to_string())
.bind(
"id",
match quote_id {
QuoteId::UUID(u) => u.as_hyphenated().to_string(),
QuoteId::BASE64(s) => s.to_string(),
},
)
.execute(&self.inner)
.await?;
Ok(())
@@ -800,13 +855,16 @@ VALUES (:quote_id, :amount, :timestamp);
async fn update_melt_quote_request_lookup_id(
&mut self,
quote_id: &Uuid,
quote_id: &QuoteId,
new_request_lookup_id: &PaymentIdentifier,
) -> Result<(), Self::Err> {
query(r#"UPDATE melt_quote SET request_lookup_id = :new_req_id, request_lookup_id_kind = :new_kind WHERE id = :id"#)?
.bind("new_req_id", new_request_lookup_id.to_string())
.bind("new_kind",new_request_lookup_id.kind() )
.bind("id", quote_id.as_hyphenated().to_string())
.bind("id", match quote_id {
QuoteId::BASE64(s) => s.to_string(),
QuoteId::UUID(u) => u.as_hyphenated().to_string(),
})
.execute(&self.inner)
.await?;
Ok(())
@@ -814,7 +872,7 @@ VALUES (:quote_id, :amount, :timestamp);
async fn update_melt_quote_state(
&mut self,
quote_id: &Uuid,
quote_id: &QuoteId,
state: MeltQuoteState,
payment_proof: Option<String>,
) -> Result<(MeltQuoteState, mint::MeltQuote), Self::Err> {
@@ -842,7 +900,13 @@ VALUES (:quote_id, :amount, :timestamp);
AND state != :state
"#,
)?
.bind("id", quote_id.as_hyphenated().to_string())
.bind(
"id",
match quote_id {
QuoteId::UUID(u) => u.as_hyphenated().to_string(),
QuoteId::BASE64(s) => s.to_string(),
},
)
.bind("state", state.to_string())
.fetch_one(&self.inner)
.await?
@@ -856,13 +920,22 @@ VALUES (:quote_id, :amount, :timestamp);
.bind("state", state.to_string())
.bind("paid_time", current_time as i64)
.bind("payment_preimage", payment_proof)
.bind("id", quote_id.as_hyphenated().to_string())
.bind("id", match quote_id {
QuoteId::UUID(u) => u.as_hyphenated().to_string(),
QuoteId::BASE64(s) => s.to_string(),
})
.execute(&self.inner)
.await
} else {
query(r#"UPDATE melt_quote SET state = :state WHERE id = :id"#)?
.bind("state", state.to_string())
.bind("id", quote_id.as_hyphenated().to_string())
.bind(
"id",
match quote_id {
QuoteId::UUID(u) => u.as_hyphenated().to_string(),
QuoteId::BASE64(s) => s.to_string(),
},
)
.execute(&self.inner)
.await
};
@@ -895,7 +968,7 @@ VALUES (:quote_id, :amount, :timestamp);
Ok(())
}
async fn get_mint_quote(&mut self, quote_id: &Uuid) -> Result<Option<MintQuote>, Self::Err> {
async fn get_mint_quote(&mut self, quote_id: &QuoteId) -> Result<Option<MintQuote>, Self::Err> {
let payments = get_mint_quote_payments(&self.inner, quote_id).await?;
let issuance = get_mint_quote_issuance(&self.inner, quote_id).await?;
@@ -920,7 +993,13 @@ VALUES (:quote_id, :amount, :timestamp);
FOR UPDATE
"#,
)?
.bind("id", quote_id.as_hyphenated().to_string())
.bind(
"id",
match quote_id {
QuoteId::UUID(u) => u.as_hyphenated().to_string(),
QuoteId::BASE64(s) => s.to_string(),
},
)
.fetch_one(&self.inner)
.await?
.map(|row| sql_row_to_mint_quote(row, payments, issuance))
@@ -1053,7 +1132,7 @@ where
{
type Err = Error;
async fn get_mint_quote(&self, quote_id: &Uuid) -> Result<Option<MintQuote>, Self::Err> {
async fn get_mint_quote(&self, quote_id: &QuoteId) -> Result<Option<MintQuote>, Self::Err> {
let conn = self.pool.get().map_err(|e| Error::Database(Box::new(e)))?;
let payments = get_mint_quote_payments(&*conn, quote_id).await?;
@@ -1078,7 +1157,13 @@ where
mint_quote
WHERE id = :id"#,
)?
.bind("id", quote_id.as_hyphenated().to_string())
.bind(
"id",
match quote_id {
QuoteId::UUID(u) => u.as_hyphenated().to_string(),
QuoteId::BASE64(s) => s.to_string(),
},
)
.fetch_one(&*conn)
.await?
.map(|row| sql_row_to_mint_quote(row, payments, issuance))
@@ -1206,7 +1291,10 @@ where
Ok(mint_quotes)
}
async fn get_melt_quote(&self, quote_id: &Uuid) -> Result<Option<mint::MeltQuote>, Self::Err> {
async fn get_melt_quote(
&self,
quote_id: &QuoteId,
) -> Result<Option<mint::MeltQuote>, Self::Err> {
let conn = self.pool.get().map_err(|e| Error::Database(Box::new(e)))?;
Ok(query(
r#"
@@ -1231,7 +1319,13 @@ where
id=:id
"#,
)?
.bind("id", quote_id.as_hyphenated().to_string())
.bind(
"id",
match quote_id {
QuoteId::BASE64(s) => s.to_string(),
QuoteId::UUID(u) => u.as_hyphenated().to_string(),
},
)
.fetch_one(&*conn)
.await?
.map(sql_row_to_melt_quote)
@@ -1386,7 +1480,7 @@ where
&mut self,
blinded_messages: &[PublicKey],
blind_signatures: &[BlindSignature],
quote_id: Option<Uuid>,
quote_id: Option<QuoteId>,
) -> Result<(), Self::Err> {
let current_time = unix_time();
@@ -1403,7 +1497,10 @@ where
.bind("amount", u64::from(signature.amount) as i64)
.bind("keyset_id", signature.keyset_id.to_string())
.bind("c", signature.c.to_bytes().to_vec())
.bind("quote_id", quote_id.map(|q| q.hyphenated().to_string()))
.bind("quote_id", quote_id.as_ref().map(|q| match q {
QuoteId::BASE64(s) => s.to_string(),
QuoteId::UUID(u) => u.hyphenated().to_string(),
}))
.bind(
"dleq_e",
signature.dleq.as_ref().map(|dleq| dleq.e.to_secret_hex()),
@@ -1547,7 +1644,7 @@ where
/// Get [`BlindSignature`]s for quote
async fn get_blind_signatures_for_quote(
&self,
quote_id: &Uuid,
quote_id: &QuoteId,
) -> Result<Vec<BlindSignature>, Self::Err> {
let conn = self.pool.get().map_err(|e| Error::Database(Box::new(e)))?;
Ok(query(
@@ -1564,7 +1661,13 @@ where
quote_id=:quote_id
"#,
)?
.bind("quote_id", quote_id.to_string())
.bind(
"quote_id",
match quote_id {
QuoteId::BASE64(s) => s.to_string(),
QuoteId::UUID(u) => u.as_hyphenated().to_string(),
},
)
.fetch_all(&*conn)
.await?
.into_iter()
@@ -1658,7 +1761,7 @@ fn sql_row_to_mint_quote(
let payment_method = column_as_string!(payment_method, PaymentMethod::from_str);
Ok(MintQuote::new(
Some(Uuid::parse_str(&id).map_err(|_| Error::InvalidUuid(id))?),
Some(QuoteId::from_str(&id)?),
request_str,
column_as_string!(unit, CurrencyUnit::from_str),
amount.map(Amount::from),
@@ -1745,7 +1848,7 @@ fn sql_row_to_melt_quote(row: Vec<Column>) -> Result<mint::MeltQuote, Error> {
};
Ok(MeltQuote {
id: Uuid::parse_str(&id).map_err(|_| Error::InvalidUuid(id))?,
id: QuoteId::from_str(&id)?,
unit: CurrencyUnit::from_str(&unit)?,
amount: Amount::from(amount),
request,