nut04.rs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. //! Mint Tokens
  2. // https://github.com/cashubtc/nuts/blob/main/04.md
  3. use serde::{Deserialize, Serialize};
  4. use super::{BlindedMessage, BlindedSignature, CurrencyUnit, PaymentMethod};
  5. use crate::Amount;
  6. /// Mint quote request [NUT-04]
  7. #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
  8. pub struct MintQuoteBolt11Request {
  9. /// Amount
  10. pub amount: Amount,
  11. /// Unit wallet would like to pay with
  12. pub unit: CurrencyUnit,
  13. }
  14. /// Mint quote response [NUT-04]
  15. #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
  16. pub struct MintQuoteBolt11Response {
  17. /// Quote Id
  18. pub quote: String,
  19. /// Payment request to fulfil
  20. pub request: String,
  21. /// Whether the the request haas be paid
  22. pub paid: bool,
  23. /// Unix timestamp until the quote is valid
  24. pub expiry: u64,
  25. }
  26. /// Mint request [NUT-04]
  27. #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
  28. pub struct MintBolt11Request {
  29. /// Quote id
  30. pub quote: String,
  31. /// Outputs
  32. pub outputs: Vec<BlindedMessage>,
  33. }
  34. impl MintBolt11Request {
  35. pub fn total_amount(&self) -> Amount {
  36. self.outputs
  37. .iter()
  38. .map(|BlindedMessage { amount, .. }| *amount)
  39. .sum()
  40. }
  41. }
  42. /// Mint response [NUT-04]
  43. #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
  44. pub struct MintBolt11Response {
  45. /// Blinded Signatures
  46. pub signatures: Vec<BlindedSignature>,
  47. }
  48. /// Mint Settings
  49. #[derive(Debug, Default, Clone, PartialEq, Eq, Serialize, Deserialize)]
  50. pub struct Settings {
  51. methods: Vec<(PaymentMethod, CurrencyUnit)>,
  52. disabled: bool,
  53. }