nut09.rs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. //! Mint Information
  2. // https://github.com/cashubtc/nuts/blob/main/09.md
  3. use serde::{Deserialize, Deserializer, Serialize, Serializer};
  4. use super::nut01::PublicKey;
  5. /// Mint Version
  6. #[derive(Debug, Clone, PartialEq, Eq)]
  7. pub struct MintVersion {
  8. pub name: String,
  9. pub version: String,
  10. }
  11. impl Serialize for MintVersion {
  12. fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
  13. where
  14. S: Serializer,
  15. {
  16. let combined = format!("{}/{}", self.name, self.version);
  17. serializer.serialize_str(&combined)
  18. }
  19. }
  20. impl<'de> Deserialize<'de> for MintVersion {
  21. fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
  22. where
  23. D: Deserializer<'de>,
  24. {
  25. let combined = String::deserialize(deserializer)?;
  26. let parts: Vec<&str> = combined.split('/').collect();
  27. if parts.len() != 2 {
  28. return Err(serde::de::Error::custom("Invalid input string"));
  29. }
  30. Ok(MintVersion {
  31. name: parts[0].to_string(),
  32. version: parts[1].to_string(),
  33. })
  34. }
  35. }
  36. /// Mint Info [NIP-09]
  37. #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
  38. pub struct MintInfo {
  39. /// name of the mint and should be recognizable
  40. #[serde(skip_serializing_if = "Option::is_none")]
  41. pub name: Option<String>,
  42. /// hex pubkey of the mint
  43. #[serde(skip_serializing_if = "Option::is_none")]
  44. pub pubkey: Option<PublicKey>,
  45. /// implementation name and the version running
  46. #[serde(skip_serializing_if = "Option::is_none")]
  47. pub version: Option<MintVersion>,
  48. /// short description of the mint
  49. #[serde(skip_serializing_if = "Option::is_none")]
  50. pub description: Option<String>,
  51. /// long description
  52. #[serde(skip_serializing_if = "Option::is_none")]
  53. pub description_long: Option<String>,
  54. /// contact methods to reach the mint operator
  55. #[serde(skip_serializing_if = "Option::is_none")]
  56. pub contact: Option<Vec<Vec<String>>>,
  57. /// shows which NUTs the mint supports
  58. #[serde(skip_serializing_if = "Vec::is_empty")]
  59. pub nuts: Vec<String>,
  60. /// message of the day that the wallet must display to the user
  61. #[serde(skip_serializing_if = "Option::is_none")]
  62. pub motd: Option<String>,
  63. }