nut05.rs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. //! Melting Tokens
  2. // https://github.com/cashubtc/nuts/blob/main/05.md
  3. use serde::{Deserialize, Serialize};
  4. use super::CurrencyUnit;
  5. use crate::nuts::Proofs;
  6. use crate::{Amount, Bolt11Invoice};
  7. /// Melt quote request [NUT-05]
  8. #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
  9. pub struct MeltQuoteBolt11Request {
  10. /// Bolt11 invoice to be paid
  11. pub request: Bolt11Invoice,
  12. /// Unit wallet would like to pay with
  13. pub unit: CurrencyUnit,
  14. }
  15. /// Melt quote response [NUT-05]
  16. #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
  17. pub struct MeltQuoteBolt11Response {
  18. /// Quote Id
  19. pub quote: String,
  20. /// The amount that needs to be provided
  21. pub amount: u64,
  22. /// The fee reserve that is required
  23. pub fee_reserve: u64,
  24. /// Whether the the request haas be paid
  25. pub paid: bool,
  26. /// Unix timestamp until the quote is valid
  27. pub expiry: u64,
  28. }
  29. /// Melt Bolt11 Request [NUT-05]
  30. #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
  31. pub struct MeltBolt11Request {
  32. /// Quote ID
  33. pub quote: String,
  34. /// Proofs
  35. pub inputs: Proofs,
  36. }
  37. impl MeltBolt11Request {
  38. pub fn proofs_amount(&self) -> Amount {
  39. self.inputs.iter().map(|proof| proof.amount).sum()
  40. }
  41. }
  42. /// Melt Response [NUT-05]
  43. #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
  44. pub struct MeltBolt11Response {
  45. /// Indicate if payment was successful
  46. pub paid: bool,
  47. /// Bolt11 preimage
  48. pub payment_preimage: String,
  49. }