mint.rs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. //! Mint types
  2. use bitcoin::bip32::DerivationPath;
  3. use serde::{Deserialize, Serialize};
  4. use uuid::Uuid;
  5. use crate::nuts::{MeltQuoteState, MintQuoteState};
  6. use crate::{Amount, CurrencyUnit, Id, KeySetInfo, PublicKey};
  7. /// Mint Quote Info
  8. #[derive(Debug, Clone, Hash, PartialEq, Eq, Serialize, Deserialize)]
  9. pub struct MintQuote {
  10. /// Quote id
  11. pub id: Uuid,
  12. /// Amount of quote
  13. pub amount: Amount,
  14. /// Unit of quote
  15. pub unit: CurrencyUnit,
  16. /// Quote payment request e.g. bolt11
  17. pub request: String,
  18. /// Quote state
  19. pub state: MintQuoteState,
  20. /// Expiration time of quote
  21. pub expiry: u64,
  22. /// Value used by ln backend to look up state of request
  23. pub request_lookup_id: String,
  24. /// Pubkey
  25. pub pubkey: Option<PublicKey>,
  26. }
  27. impl MintQuote {
  28. /// Create new [`MintQuote`]
  29. pub fn new(
  30. request: String,
  31. unit: CurrencyUnit,
  32. amount: Amount,
  33. expiry: u64,
  34. request_lookup_id: String,
  35. pubkey: Option<PublicKey>,
  36. ) -> Self {
  37. let id = Uuid::new_v4();
  38. Self {
  39. id,
  40. amount,
  41. unit,
  42. request,
  43. state: MintQuoteState::Unpaid,
  44. expiry,
  45. request_lookup_id,
  46. pubkey,
  47. }
  48. }
  49. }
  50. // Melt Quote Info
  51. #[derive(Debug, Clone, Hash, PartialEq, Eq, Serialize, Deserialize)]
  52. pub struct MeltQuote {
  53. /// Quote id
  54. pub id: Uuid,
  55. /// Quote unit
  56. pub unit: CurrencyUnit,
  57. /// Quote amount
  58. pub amount: Amount,
  59. /// Quote Payment request e.g. bolt11
  60. pub request: String,
  61. /// Quote fee reserve
  62. pub fee_reserve: Amount,
  63. /// Quote state
  64. pub state: MeltQuoteState,
  65. /// Expiration time of quote
  66. pub expiry: u64,
  67. /// Payment preimage
  68. pub payment_preimage: Option<String>,
  69. /// Value used by ln backend to look up state of request
  70. pub request_lookup_id: String,
  71. /// Msat to pay
  72. ///
  73. /// Used for an amountless invoice
  74. pub msat_to_pay: Option<Amount>,
  75. }
  76. impl MeltQuote {
  77. /// Create new [`MeltQuote`]
  78. pub fn new(
  79. request: String,
  80. unit: CurrencyUnit,
  81. amount: Amount,
  82. fee_reserve: Amount,
  83. expiry: u64,
  84. request_lookup_id: String,
  85. msat_to_pay: Option<Amount>,
  86. ) -> Self {
  87. let id = Uuid::new_v4();
  88. Self {
  89. id,
  90. amount,
  91. unit,
  92. request,
  93. fee_reserve,
  94. state: MeltQuoteState::Unpaid,
  95. expiry,
  96. payment_preimage: None,
  97. request_lookup_id,
  98. msat_to_pay,
  99. }
  100. }
  101. }
  102. /// Mint Keyset Info
  103. #[derive(Debug, Clone, Hash, PartialEq, Eq, Serialize, Deserialize)]
  104. pub struct MintKeySetInfo {
  105. /// Keyset [`Id`]
  106. pub id: Id,
  107. /// Keyset [`CurrencyUnit`]
  108. pub unit: CurrencyUnit,
  109. /// Keyset active or inactive
  110. /// Mint will only issue new [`BlindSignature`] on active keysets
  111. pub active: bool,
  112. /// Starting unix time Keyset is valid from
  113. pub valid_from: u64,
  114. /// When the Keyset is valid to
  115. /// This is not shown to the wallet and can only be used internally
  116. pub valid_to: Option<u64>,
  117. /// [`DerivationPath`] keyset
  118. pub derivation_path: DerivationPath,
  119. /// DerivationPath index of Keyset
  120. pub derivation_path_index: Option<u32>,
  121. /// Max order of keyset
  122. pub max_order: u8,
  123. /// Input Fee ppk
  124. #[serde(default = "default_fee")]
  125. pub input_fee_ppk: u64,
  126. }
  127. /// Default fee
  128. pub fn default_fee() -> u64 {
  129. 0
  130. }
  131. impl From<MintKeySetInfo> for KeySetInfo {
  132. fn from(keyset_info: MintKeySetInfo) -> Self {
  133. Self {
  134. id: keyset_info.id,
  135. unit: keyset_info.unit,
  136. active: keyset_info.active,
  137. input_fee_ppk: keyset_info.input_fee_ppk,
  138. }
  139. }
  140. }