Amount and unit nut04/05 (#635)

* feat: return amount and unit in mint response


Co-authored-by: callebtc <93376500+callebtc@users.noreply.github.com>
This commit is contained in:
thesimplekid
2025-03-08 22:41:21 +00:00
committed by GitHub
parent b7380dc858
commit 22beade553
5 changed files with 46 additions and 0 deletions

View File

@@ -15,6 +15,8 @@
- cdk-sqlite: In memory sqlite database ([crodas]).
- Add `tos_url` to `MintInfo` ([nodlAndHodl]).
- cdk: Add tos_url setter to `MintBuilder` ([thesimplekid]).
- Added optional "request" and "unit" fields to MeltQuoteBolt11Response [NUT Change](https://github.com/cashubtc/nuts/pull/235) ([thesimplekid]).
- Added optional "amount" and "unit" fields to MintQuoteBolt11Response [NUT Change](https://github.com/cashubtc/nuts/pull/235) ([thesimplekid]).
### Removed
- Remove support for Memory Database in cdk ([crodas]).
- Remove `AmountStr` ([crodas]).

View File

@@ -94,6 +94,12 @@ pub struct MintQuoteBolt11Response<Q> {
pub quote: Q,
/// Payment request to fulfil
pub request: String,
/// Amount
// REVIEW: This is now required in the spec, we should remove the option once all mints update
pub amount: Option<Amount>,
/// Unit
// REVIEW: This is now required in the spec, we should remove the option once all mints update
pub unit: Option<CurrencyUnit>,
/// Quote State
pub state: MintQuoteState,
/// Unix timestamp until the quote is valid
@@ -112,6 +118,8 @@ impl<Q: ToString> MintQuoteBolt11Response<Q> {
state: self.state,
expiry: self.expiry,
pubkey: self.pubkey,
amount: self.amount,
unit: self.unit.clone(),
}
}
}
@@ -125,6 +133,8 @@ impl From<MintQuoteBolt11Response<Uuid>> for MintQuoteBolt11Response<String> {
state: value.state,
expiry: value.expiry,
pubkey: value.pubkey,
amount: value.amount,
unit: value.unit.clone(),
}
}
}
@@ -138,6 +148,8 @@ impl From<crate::mint::MintQuote> for MintQuoteBolt11Response<Uuid> {
state: mint_quote.state,
expiry: Some(mint_quote.expiry),
pubkey: mint_quote.pubkey,
amount: Some(mint_quote.amount),
unit: Some(mint_quote.unit.clone()),
}
}
}

View File

@@ -175,6 +175,14 @@ pub struct MeltQuoteBolt11Response<Q> {
/// Change
#[serde(skip_serializing_if = "Option::is_none")]
pub change: Option<Vec<BlindSignature>>,
/// Payment request to fulfill
// REVIEW: This is now required in the spec, we should remove the option once all mints update
#[serde(skip_serializing_if = "Option::is_none")]
pub request: Option<String>,
/// Unit
// REVIEW: This is now required in the spec, we should remove the option once all mints update
#[serde(skip_serializing_if = "Option::is_none")]
pub unit: Option<CurrencyUnit>,
}
impl<Q: ToString> MeltQuoteBolt11Response<Q> {
@@ -190,6 +198,8 @@ impl<Q: ToString> MeltQuoteBolt11Response<Q> {
expiry: self.expiry,
payment_preimage: self.payment_preimage,
change: self.change,
request: self.request,
unit: self.unit,
}
}
}
@@ -206,6 +216,8 @@ impl From<MeltQuoteBolt11Response<Uuid>> for MeltQuoteBolt11Response<String> {
expiry: value.expiry,
payment_preimage: value.payment_preimage,
change: value.change,
request: value.request,
unit: value.unit,
}
}
}
@@ -222,6 +234,8 @@ impl From<&MeltQuote> for MeltQuoteBolt11Response<Uuid> {
expiry: melt_quote.expiry,
amount: melt_quote.amount,
fee_reserve: melt_quote.fee_reserve,
request: None,
unit: Some(melt_quote.unit.clone()),
}
}
}
@@ -297,6 +311,14 @@ impl<'de, Q: DeserializeOwned> Deserialize<'de> for MeltQuoteBolt11Response<Q> {
.get("change")
.and_then(|b| serde_json::from_value(b.clone()).ok());
let request: Option<String> = value
.get("request")
.and_then(|r| serde_json::from_value(r.clone()).ok());
let unit: Option<CurrencyUnit> = value
.get("unit")
.and_then(|u| serde_json::from_value(u.clone()).ok());
Ok(Self {
quote,
amount,
@@ -306,6 +328,8 @@ impl<'de, Q: DeserializeOwned> Deserialize<'de> for MeltQuoteBolt11Response<Q> {
expiry,
payment_preimage,
change,
request,
unit,
})
}
}
@@ -323,6 +347,8 @@ impl From<mint::MeltQuote> for MeltQuoteBolt11Response<Uuid> {
expiry: melt_quote.expiry,
payment_preimage: melt_quote.payment_preimage,
change: None,
request: Some(melt_quote.request.clone()),
unit: Some(melt_quote.unit.clone()),
}
}
}

View File

@@ -186,6 +186,8 @@ impl Mint {
fee_reserve: quote.fee_reserve,
payment_preimage: quote.payment_preimage,
change,
request: Some(quote.request.clone()),
unit: Some(quote.unit.clone()),
})
}
@@ -696,6 +698,8 @@ impl Mint {
fee_reserve: quote.fee_reserve,
state: MeltQuoteState::Paid,
expiry: quote.expiry,
request: Some(quote.request.clone()),
unit: Some(quote.unit.clone()),
})
}
}

View File

@@ -147,6 +147,8 @@ impl Mint {
state,
expiry: Some(quote.expiry),
pubkey: quote.pubkey,
amount: Some(quote.amount),
unit: Some(quote.unit.clone()),
})
}