types.rs 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. //! Types for `cashu-crab`
  2. use serde::{Deserialize, Serialize};
  3. use uuid::Uuid;
  4. use crate::nuts::{CurrencyUnit, Proofs};
  5. use crate::Amount;
  6. #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
  7. pub struct ProofsStatus {
  8. pub spendable: Proofs,
  9. pub spent: Proofs,
  10. }
  11. /// Melt response with proofs
  12. #[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)]
  13. pub struct Melted {
  14. pub paid: bool,
  15. pub preimage: Option<String>,
  16. pub change: Option<Proofs>,
  17. }
  18. /// Possible states of an invoice
  19. #[derive(Debug, Serialize, Deserialize, Clone, Copy, PartialEq)]
  20. pub enum InvoiceStatus {
  21. Unpaid,
  22. Paid,
  23. Expired,
  24. InFlight,
  25. }
  26. /// Mint Quote Info
  27. #[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
  28. pub struct MintQuote {
  29. pub id: String,
  30. pub amount: Amount,
  31. pub unit: CurrencyUnit,
  32. pub request: String,
  33. pub paid: bool,
  34. pub expiry: u64,
  35. }
  36. impl MintQuote {
  37. pub fn new(request: String, unit: CurrencyUnit, amount: Amount, expiry: u64) -> Self {
  38. let id = Uuid::new_v4();
  39. Self {
  40. id: id.to_string(),
  41. amount,
  42. unit,
  43. request,
  44. paid: false,
  45. expiry,
  46. }
  47. }
  48. }
  49. /// Melt Quote Info
  50. #[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
  51. pub struct MeltQuote {
  52. pub id: String,
  53. pub unit: CurrencyUnit,
  54. pub amount: Amount,
  55. pub request: String,
  56. pub fee_reserve: Amount,
  57. pub paid: bool,
  58. pub expiry: u64,
  59. }
  60. impl MeltQuote {
  61. pub fn new(
  62. request: String,
  63. unit: CurrencyUnit,
  64. amount: Amount,
  65. fee_reserve: Amount,
  66. expiry: u64,
  67. ) -> Self {
  68. let id = Uuid::new_v4();
  69. Self {
  70. id: id.to_string(),
  71. amount,
  72. unit,
  73. request,
  74. fee_reserve,
  75. paid: false,
  76. expiry,
  77. }
  78. }
  79. }