|
@@ -37,7 +37,6 @@ use cdk_common::{
|
|
|
use lightning_invoice::Bolt11Invoice;
|
|
use lightning_invoice::Bolt11Invoice;
|
|
|
use migrations::MIGRATIONS;
|
|
use migrations::MIGRATIONS;
|
|
|
use tracing::instrument;
|
|
use tracing::instrument;
|
|
|
-use uuid::Uuid;
|
|
|
|
|
|
|
|
|
|
use crate::common::migrate;
|
|
use crate::common::migrate;
|
|
|
use crate::database::{ConnectionWithTransaction, DatabaseExecutor};
|
|
use crate::database::{ConnectionWithTransaction, DatabaseExecutor};
|
|
@@ -170,7 +169,7 @@ where
|
|
|
async fn add_proofs(
|
|
async fn add_proofs(
|
|
|
&mut self,
|
|
&mut self,
|
|
|
proofs: Proofs,
|
|
proofs: Proofs,
|
|
|
- quote_id: Option<Uuid>,
|
|
|
|
|
|
|
+ quote_id: Option<QuoteId>,
|
|
|
) -> Result<(), Self::Err> {
|
|
) -> Result<(), Self::Err> {
|
|
|
let current_time = unix_time();
|
|
let current_time = unix_time();
|
|
|
|
|
|
|
@@ -213,7 +212,7 @@ where
|
|
|
proof.witness.map(|w| serde_json::to_string(&w).unwrap()),
|
|
proof.witness.map(|w| serde_json::to_string(&w).unwrap()),
|
|
|
)
|
|
)
|
|
|
.bind("state", "UNSPENT".to_string())
|
|
.bind("state", "UNSPENT".to_string())
|
|
|
- .bind("quote_id", quote_id.map(|q| q.hyphenated().to_string()))
|
|
|
|
|
|
|
+ .bind("quote_id", quote_id.clone().map(|q| q.to_string()))
|
|
|
.bind("created_time", current_time as i64)
|
|
.bind("created_time", current_time as i64)
|
|
|
.execute(&self.inner)
|
|
.execute(&self.inner)
|
|
|
.await?;
|
|
.await?;
|
|
@@ -254,7 +253,7 @@ where
|
|
|
async fn remove_proofs(
|
|
async fn remove_proofs(
|
|
|
&mut self,
|
|
&mut self,
|
|
|
ys: &[PublicKey],
|
|
ys: &[PublicKey],
|
|
|
- _quote_id: Option<Uuid>,
|
|
|
|
|
|
|
+ _quote_id: Option<QuoteId>,
|
|
|
) -> Result<(), Self::Err> {
|
|
) -> Result<(), Self::Err> {
|
|
|
if ys.is_empty() {
|
|
if ys.is_empty() {
|
|
|
return Ok(());
|
|
return Ok(());
|
|
@@ -328,13 +327,7 @@ where
|
|
|
quote_id=:quote_id
|
|
quote_id=:quote_id
|
|
|
"#,
|
|
"#,
|
|
|
)?
|
|
)?
|
|
|
- .bind(
|
|
|
|
|
- "quote_id",
|
|
|
|
|
- match quote_id {
|
|
|
|
|
- QuoteId::UUID(u) => u.as_hyphenated().to_string(),
|
|
|
|
|
- QuoteId::BASE64(s) => s.to_string(),
|
|
|
|
|
- },
|
|
|
|
|
- )
|
|
|
|
|
|
|
+ .bind("quote_id", quote_id.to_string())
|
|
|
.fetch_all(conn)
|
|
.fetch_all(conn)
|
|
|
.await?
|
|
.await?
|
|
|
.into_iter()
|
|
.into_iter()
|
|
@@ -363,13 +356,7 @@ FROM mint_quote_issued
|
|
|
WHERE quote_id=:quote_id
|
|
WHERE quote_id=:quote_id
|
|
|
"#,
|
|
"#,
|
|
|
)?
|
|
)?
|
|
|
- .bind(
|
|
|
|
|
- "quote_id",
|
|
|
|
|
- match quote_id {
|
|
|
|
|
- QuoteId::UUID(u) => u.as_hyphenated().to_string(),
|
|
|
|
|
- QuoteId::BASE64(s) => s.to_string(),
|
|
|
|
|
- },
|
|
|
|
|
- )
|
|
|
|
|
|
|
+ .bind("quote_id", quote_id.to_string())
|
|
|
.fetch_all(conn)
|
|
.fetch_all(conn)
|
|
|
.await?
|
|
.await?
|
|
|
.into_iter()
|
|
.into_iter()
|
|
@@ -591,13 +578,7 @@ where
|
|
|
FOR UPDATE
|
|
FOR UPDATE
|
|
|
"#,
|
|
"#,
|
|
|
)?
|
|
)?
|
|
|
- .bind(
|
|
|
|
|
- "quote_id",
|
|
|
|
|
- match quote_id {
|
|
|
|
|
- QuoteId::UUID(u) => u.as_hyphenated().to_string(),
|
|
|
|
|
- QuoteId::BASE64(s) => s.to_string(),
|
|
|
|
|
- },
|
|
|
|
|
- )
|
|
|
|
|
|
|
+ .bind("quote_id", quote_id.to_string())
|
|
|
.fetch_one(&self.inner)
|
|
.fetch_one(&self.inner)
|
|
|
.await
|
|
.await
|
|
|
.inspect_err(|err| {
|
|
.inspect_err(|err| {
|
|
@@ -632,13 +613,7 @@ where
|
|
|
"#,
|
|
"#,
|
|
|
)?
|
|
)?
|
|
|
.bind("amount_paid", new_amount_paid.to_i64())
|
|
.bind("amount_paid", new_amount_paid.to_i64())
|
|
|
- .bind(
|
|
|
|
|
- "quote_id",
|
|
|
|
|
- match quote_id {
|
|
|
|
|
- QuoteId::UUID(u) => u.as_hyphenated().to_string(),
|
|
|
|
|
- QuoteId::BASE64(s) => s.to_string(),
|
|
|
|
|
- },
|
|
|
|
|
- )
|
|
|
|
|
|
|
+ .bind("quote_id", quote_id.to_string())
|
|
|
.execute(&self.inner)
|
|
.execute(&self.inner)
|
|
|
.await
|
|
.await
|
|
|
.inspect_err(|err| {
|
|
.inspect_err(|err| {
|
|
@@ -653,13 +628,7 @@ where
|
|
|
VALUES (:quote_id, :payment_id, :amount, :timestamp)
|
|
VALUES (:quote_id, :payment_id, :amount, :timestamp)
|
|
|
"#,
|
|
"#,
|
|
|
)?
|
|
)?
|
|
|
- .bind(
|
|
|
|
|
- "quote_id",
|
|
|
|
|
- match quote_id {
|
|
|
|
|
- QuoteId::UUID(u) => u.as_hyphenated().to_string(),
|
|
|
|
|
- QuoteId::BASE64(s) => s.to_string(),
|
|
|
|
|
- },
|
|
|
|
|
- )
|
|
|
|
|
|
|
+ .bind("quote_id", quote_id.to_string())
|
|
|
.bind("payment_id", payment_id)
|
|
.bind("payment_id", payment_id)
|
|
|
.bind("amount", amount_paid.to_i64())
|
|
.bind("amount", amount_paid.to_i64())
|
|
|
.bind("timestamp", unix_time() as i64)
|
|
.bind("timestamp", unix_time() as i64)
|
|
@@ -688,13 +657,7 @@ where
|
|
|
FOR UPDATE
|
|
FOR UPDATE
|
|
|
"#,
|
|
"#,
|
|
|
)?
|
|
)?
|
|
|
- .bind(
|
|
|
|
|
- "quote_id",
|
|
|
|
|
- match quote_id {
|
|
|
|
|
- QuoteId::UUID(u) => u.as_hyphenated().to_string(),
|
|
|
|
|
- QuoteId::BASE64(s) => s.to_string(),
|
|
|
|
|
- },
|
|
|
|
|
- )
|
|
|
|
|
|
|
+ .bind("quote_id", quote_id.to_string())
|
|
|
.fetch_one(&self.inner)
|
|
.fetch_one(&self.inner)
|
|
|
.await
|
|
.await
|
|
|
.inspect_err(|err| {
|
|
.inspect_err(|err| {
|
|
@@ -722,13 +685,7 @@ where
|
|
|
"#,
|
|
"#,
|
|
|
)?
|
|
)?
|
|
|
.bind("amount_issued", new_amount_issued.to_i64())
|
|
.bind("amount_issued", new_amount_issued.to_i64())
|
|
|
- .bind(
|
|
|
|
|
- "quote_id",
|
|
|
|
|
- match quote_id {
|
|
|
|
|
- QuoteId::UUID(u) => u.as_hyphenated().to_string(),
|
|
|
|
|
- QuoteId::BASE64(s) => s.to_string(),
|
|
|
|
|
- },
|
|
|
|
|
- )
|
|
|
|
|
|
|
+ .bind("quote_id", quote_id.to_string())
|
|
|
.execute(&self.inner)
|
|
.execute(&self.inner)
|
|
|
.await
|
|
.await
|
|
|
.inspect_err(|err| {
|
|
.inspect_err(|err| {
|
|
@@ -744,13 +701,7 @@ INSERT INTO mint_quote_issued
|
|
|
VALUES (:quote_id, :amount, :timestamp);
|
|
VALUES (:quote_id, :amount, :timestamp);
|
|
|
"#,
|
|
"#,
|
|
|
)?
|
|
)?
|
|
|
- .bind(
|
|
|
|
|
- "quote_id",
|
|
|
|
|
- match quote_id {
|
|
|
|
|
- QuoteId::UUID(u) => u.as_hyphenated().to_string(),
|
|
|
|
|
- QuoteId::BASE64(s) => s.to_string(),
|
|
|
|
|
- },
|
|
|
|
|
- )
|
|
|
|
|
|
|
+ .bind("quote_id", quote_id.to_string())
|
|
|
.bind("amount", amount_issued.to_i64())
|
|
.bind("amount", amount_issued.to_i64())
|
|
|
.bind("timestamp", current_time as i64)
|
|
.bind("timestamp", current_time as i64)
|
|
|
.execute(&self.inner)
|
|
.execute(&self.inner)
|
|
@@ -792,13 +743,7 @@ VALUES (:quote_id, :amount, :timestamp);
|
|
|
|
|
|
|
|
async fn remove_mint_quote(&mut self, quote_id: &QuoteId) -> 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"#)?
|
|
query(r#"DELETE FROM mint_quote WHERE id=:id"#)?
|
|
|
- .bind(
|
|
|
|
|
- "id",
|
|
|
|
|
- match quote_id {
|
|
|
|
|
- QuoteId::UUID(u) => u.as_hyphenated().to_string(),
|
|
|
|
|
- QuoteId::BASE64(s) => s.to_string(),
|
|
|
|
|
- },
|
|
|
|
|
- )
|
|
|
|
|
|
|
+ .bind("id", quote_id.to_string())
|
|
|
.execute(&self.inner)
|
|
.execute(&self.inner)
|
|
|
.await?;
|
|
.await?;
|
|
|
Ok(())
|
|
Ok(())
|
|
@@ -861,10 +806,7 @@ VALUES (:quote_id, :amount, :timestamp);
|
|
|
query(r#"UPDATE melt_quote SET request_lookup_id = :new_req_id, request_lookup_id_kind = :new_kind WHERE id = :id"#)?
|
|
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_req_id", new_request_lookup_id.to_string())
|
|
|
.bind("new_kind",new_request_lookup_id.kind() )
|
|
.bind("new_kind",new_request_lookup_id.kind() )
|
|
|
- .bind("id", match quote_id {
|
|
|
|
|
- QuoteId::BASE64(s) => s.to_string(),
|
|
|
|
|
- QuoteId::UUID(u) => u.as_hyphenated().to_string(),
|
|
|
|
|
- })
|
|
|
|
|
|
|
+ .bind("id", quote_id.to_string())
|
|
|
.execute(&self.inner)
|
|
.execute(&self.inner)
|
|
|
.await?;
|
|
.await?;
|
|
|
Ok(())
|
|
Ok(())
|
|
@@ -900,13 +842,7 @@ VALUES (:quote_id, :amount, :timestamp);
|
|
|
AND state != :state
|
|
AND state != :state
|
|
|
"#,
|
|
"#,
|
|
|
)?
|
|
)?
|
|
|
- .bind(
|
|
|
|
|
- "id",
|
|
|
|
|
- match quote_id {
|
|
|
|
|
- QuoteId::UUID(u) => u.as_hyphenated().to_string(),
|
|
|
|
|
- QuoteId::BASE64(s) => s.to_string(),
|
|
|
|
|
- },
|
|
|
|
|
- )
|
|
|
|
|
|
|
+ .bind("id", quote_id.to_string())
|
|
|
.bind("state", state.to_string())
|
|
.bind("state", state.to_string())
|
|
|
.fetch_one(&self.inner)
|
|
.fetch_one(&self.inner)
|
|
|
.await?
|
|
.await?
|
|
@@ -920,22 +856,13 @@ VALUES (:quote_id, :amount, :timestamp);
|
|
|
.bind("state", state.to_string())
|
|
.bind("state", state.to_string())
|
|
|
.bind("paid_time", current_time as i64)
|
|
.bind("paid_time", current_time as i64)
|
|
|
.bind("payment_preimage", payment_proof)
|
|
.bind("payment_preimage", payment_proof)
|
|
|
- .bind("id", match quote_id {
|
|
|
|
|
- QuoteId::UUID(u) => u.as_hyphenated().to_string(),
|
|
|
|
|
- QuoteId::BASE64(s) => s.to_string(),
|
|
|
|
|
- })
|
|
|
|
|
|
|
+ .bind("id", quote_id.to_string())
|
|
|
.execute(&self.inner)
|
|
.execute(&self.inner)
|
|
|
.await
|
|
.await
|
|
|
} else {
|
|
} else {
|
|
|
query(r#"UPDATE melt_quote SET state = :state WHERE id = :id"#)?
|
|
query(r#"UPDATE melt_quote SET state = :state WHERE id = :id"#)?
|
|
|
.bind("state", state.to_string())
|
|
.bind("state", state.to_string())
|
|
|
- .bind(
|
|
|
|
|
- "id",
|
|
|
|
|
- match quote_id {
|
|
|
|
|
- QuoteId::UUID(u) => u.as_hyphenated().to_string(),
|
|
|
|
|
- QuoteId::BASE64(s) => s.to_string(),
|
|
|
|
|
- },
|
|
|
|
|
- )
|
|
|
|
|
|
|
+ .bind("id", quote_id.to_string())
|
|
|
.execute(&self.inner)
|
|
.execute(&self.inner)
|
|
|
.await
|
|
.await
|
|
|
};
|
|
};
|
|
@@ -954,14 +881,14 @@ VALUES (:quote_id, :amount, :timestamp);
|
|
|
Ok((old_state, quote))
|
|
Ok((old_state, quote))
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- async fn remove_melt_quote(&mut self, quote_id: &Uuid) -> Result<(), Self::Err> {
|
|
|
|
|
|
|
+ async fn remove_melt_quote(&mut self, quote_id: &QuoteId) -> Result<(), Self::Err> {
|
|
|
query(
|
|
query(
|
|
|
r#"
|
|
r#"
|
|
|
DELETE FROM melt_quote
|
|
DELETE FROM melt_quote
|
|
|
WHERE id=?
|
|
WHERE id=?
|
|
|
"#,
|
|
"#,
|
|
|
)?
|
|
)?
|
|
|
- .bind("id", quote_id.as_hyphenated().to_string())
|
|
|
|
|
|
|
+ .bind("id", quote_id.to_string())
|
|
|
.execute(&self.inner)
|
|
.execute(&self.inner)
|
|
|
.await?;
|
|
.await?;
|
|
|
|
|
|
|
@@ -993,13 +920,7 @@ VALUES (:quote_id, :amount, :timestamp);
|
|
|
FOR UPDATE
|
|
FOR UPDATE
|
|
|
"#,
|
|
"#,
|
|
|
)?
|
|
)?
|
|
|
- .bind(
|
|
|
|
|
- "id",
|
|
|
|
|
- match quote_id {
|
|
|
|
|
- QuoteId::UUID(u) => u.as_hyphenated().to_string(),
|
|
|
|
|
- QuoteId::BASE64(s) => s.to_string(),
|
|
|
|
|
- },
|
|
|
|
|
- )
|
|
|
|
|
|
|
+ .bind("id", quote_id.to_string())
|
|
|
.fetch_one(&self.inner)
|
|
.fetch_one(&self.inner)
|
|
|
.await?
|
|
.await?
|
|
|
.map(|row| sql_row_to_mint_quote(row, payments, issuance))
|
|
.map(|row| sql_row_to_mint_quote(row, payments, issuance))
|
|
@@ -1008,7 +929,7 @@ VALUES (:quote_id, :amount, :timestamp);
|
|
|
|
|
|
|
|
async fn get_melt_quote(
|
|
async fn get_melt_quote(
|
|
|
&mut self,
|
|
&mut self,
|
|
|
- quote_id: &Uuid,
|
|
|
|
|
|
|
+ quote_id: &QuoteId,
|
|
|
) -> Result<Option<mint::MeltQuote>, Self::Err> {
|
|
) -> Result<Option<mint::MeltQuote>, Self::Err> {
|
|
|
Ok(query(
|
|
Ok(query(
|
|
|
r#"
|
|
r#"
|
|
@@ -1033,7 +954,7 @@ VALUES (:quote_id, :amount, :timestamp);
|
|
|
id=:id
|
|
id=:id
|
|
|
"#,
|
|
"#,
|
|
|
)?
|
|
)?
|
|
|
- .bind("id", quote_id.as_hyphenated().to_string())
|
|
|
|
|
|
|
+ .bind("id", quote_id.to_string())
|
|
|
.fetch_one(&self.inner)
|
|
.fetch_one(&self.inner)
|
|
|
.await?
|
|
.await?
|
|
|
.map(sql_row_to_melt_quote)
|
|
.map(sql_row_to_melt_quote)
|
|
@@ -1157,13 +1078,7 @@ where
|
|
|
mint_quote
|
|
mint_quote
|
|
|
WHERE id = :id"#,
|
|
WHERE id = :id"#,
|
|
|
)?
|
|
)?
|
|
|
- .bind(
|
|
|
|
|
- "id",
|
|
|
|
|
- match quote_id {
|
|
|
|
|
- QuoteId::UUID(u) => u.as_hyphenated().to_string(),
|
|
|
|
|
- QuoteId::BASE64(s) => s.to_string(),
|
|
|
|
|
- },
|
|
|
|
|
- )
|
|
|
|
|
|
|
+ .bind("id", quote_id.to_string())
|
|
|
.fetch_one(&*conn)
|
|
.fetch_one(&*conn)
|
|
|
.await?
|
|
.await?
|
|
|
.map(|row| sql_row_to_mint_quote(row, payments, issuance))
|
|
.map(|row| sql_row_to_mint_quote(row, payments, issuance))
|
|
@@ -1319,13 +1234,7 @@ where
|
|
|
id=:id
|
|
id=:id
|
|
|
"#,
|
|
"#,
|
|
|
)?
|
|
)?
|
|
|
- .bind(
|
|
|
|
|
- "id",
|
|
|
|
|
- match quote_id {
|
|
|
|
|
- QuoteId::BASE64(s) => s.to_string(),
|
|
|
|
|
- QuoteId::UUID(u) => u.as_hyphenated().to_string(),
|
|
|
|
|
- },
|
|
|
|
|
- )
|
|
|
|
|
|
|
+ .bind("id", quote_id.to_string())
|
|
|
.fetch_one(&*conn)
|
|
.fetch_one(&*conn)
|
|
|
.await?
|
|
.await?
|
|
|
.map(sql_row_to_melt_quote)
|
|
.map(sql_row_to_melt_quote)
|
|
@@ -1406,7 +1315,10 @@ where
|
|
|
Ok(ys.iter().map(|y| proofs.remove(y)).collect())
|
|
Ok(ys.iter().map(|y| proofs.remove(y)).collect())
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- async fn get_proof_ys_by_quote_id(&self, quote_id: &Uuid) -> Result<Vec<PublicKey>, Self::Err> {
|
|
|
|
|
|
|
+ async fn get_proof_ys_by_quote_id(
|
|
|
|
|
+ &self,
|
|
|
|
|
+ quote_id: &QuoteId,
|
|
|
|
|
+ ) -> Result<Vec<PublicKey>, Self::Err> {
|
|
|
let conn = self.pool.get().map_err(|e| Error::Database(Box::new(e)))?;
|
|
let conn = self.pool.get().map_err(|e| Error::Database(Box::new(e)))?;
|
|
|
Ok(query(
|
|
Ok(query(
|
|
|
r#"
|
|
r#"
|
|
@@ -1422,7 +1334,7 @@ where
|
|
|
quote_id = :quote_id
|
|
quote_id = :quote_id
|
|
|
"#,
|
|
"#,
|
|
|
)?
|
|
)?
|
|
|
- .bind("quote_id", quote_id.as_hyphenated().to_string())
|
|
|
|
|
|
|
+ .bind("quote_id", quote_id.to_string())
|
|
|
.fetch_all(&*conn)
|
|
.fetch_all(&*conn)
|
|
|
.await?
|
|
.await?
|
|
|
.into_iter()
|
|
.into_iter()
|
|
@@ -1661,13 +1573,7 @@ where
|
|
|
quote_id=:quote_id
|
|
quote_id=:quote_id
|
|
|
"#,
|
|
"#,
|
|
|
)?
|
|
)?
|
|
|
- .bind(
|
|
|
|
|
- "quote_id",
|
|
|
|
|
- match quote_id {
|
|
|
|
|
- QuoteId::BASE64(s) => s.to_string(),
|
|
|
|
|
- QuoteId::UUID(u) => u.as_hyphenated().to_string(),
|
|
|
|
|
- },
|
|
|
|
|
- )
|
|
|
|
|
|
|
+ .bind("quote_id", quote_id.to_string())
|
|
|
.fetch_all(&*conn)
|
|
.fetch_all(&*conn)
|
|
|
.await?
|
|
.await?
|
|
|
.into_iter()
|
|
.into_iter()
|