cashu/nuts/
nut19.rs

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