nut19.rs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. //! NUT-19: Cached Responses
  2. //!
  3. //! <https://github.com/cashubtc/nuts/blob/main/19.md>
  4. use serde::{Deserialize, Serialize};
  5. /// Mint settings
  6. #[derive(Debug, Clone, PartialEq, Eq, Hash, Default, Serialize, Deserialize)]
  7. #[cfg_attr(feature = "swagger", derive(utoipa::ToSchema))]
  8. pub struct Settings {
  9. /// Number of seconds the responses are cached for
  10. pub ttl: Option<u64>,
  11. /// Cached endpoints
  12. pub cached_endpoints: Vec<CachedEndpoint>,
  13. }
  14. /// List of the methods and paths for which caching is enabled
  15. #[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
  16. #[cfg_attr(feature = "swagger", derive(utoipa::ToSchema))]
  17. pub struct CachedEndpoint {
  18. /// HTTP Method
  19. pub method: Method,
  20. /// Route path
  21. pub path: Path,
  22. }
  23. impl CachedEndpoint {
  24. /// Create [`CachedEndpoint`]
  25. pub fn new(method: Method, path: Path) -> Self {
  26. Self { method, path }
  27. }
  28. }
  29. /// HTTP method
  30. #[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
  31. #[serde(rename_all = "UPPERCASE")]
  32. #[cfg_attr(feature = "swagger", derive(utoipa::ToSchema))]
  33. pub enum Method {
  34. /// Get
  35. Get,
  36. /// POST
  37. Post,
  38. }
  39. /// Route path
  40. #[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
  41. #[cfg_attr(feature = "swagger", derive(utoipa::ToSchema))]
  42. pub enum Path {
  43. /// Bolt11 Mint
  44. #[serde(rename = "/v1/mint/bolt11")]
  45. MintBolt11,
  46. /// Bolt11 Melt
  47. #[serde(rename = "/v1/melt/bolt11")]
  48. MeltBolt11,
  49. /// Swap
  50. #[serde(rename = "/v1/swap")]
  51. Swap,
  52. }