From 7a01ccc9c943ecfb7f6a30eb42e9b673615cd9c3 Mon Sep 17 00:00:00 2001 From: ok300 <106775972+ok300@users.noreply.github.com> Date: Thu, 10 Oct 2024 02:29:57 +0200 Subject: [PATCH] mint: annotate post_check for Swagger UI --- crates/cdk-axum/src/lib.rs | 8 +++++++- crates/cdk-axum/src/router_handlers.rs | 13 +++++++++++++ crates/cdk/src/nuts/nut07.rs | 8 +++++++- 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/crates/cdk-axum/src/lib.rs b/crates/cdk-axum/src/lib.rs index 7910da6d7..218b858ee 100644 --- a/crates/cdk-axum/src/lib.rs +++ b/crates/cdk-axum/src/lib.rs @@ -28,6 +28,7 @@ use cdk::nuts::nut05::{ MeltBolt11Request, MeltMethodSettings, MeltQuoteBolt11Request, MeltQuoteBolt11Response, }; use cdk::nuts::nut06::{ContactInfo, MintInfo, MintVersion, Nuts, SupportedSettings}; +use cdk::nuts::nut07::{CheckStateRequest, CheckStateResponse, ProofState, State}; use cdk::nuts::nut11::P2PKWitness; use cdk::nuts::nut12::{BlindSignatureDleq, ProofDleq}; use cdk::nuts::nut14::HTLCWitness; @@ -54,6 +55,8 @@ pub struct MintState { BlindedMessage, BlindSignature, BlindSignatureDleq, + CheckStateRequest, + CheckStateResponse, ContactInfo, CurrencyUnit, ErrorCode, @@ -86,8 +89,10 @@ pub struct MintState { PaymentMethod, Proof, ProofDleq, + ProofState, PublicKey, SecretKey, + State, SupportedSettings, SwapRequest, SwapResponse, @@ -108,7 +113,8 @@ pub struct MintState { get_melt_bolt11_quote, get_check_melt_bolt11_quote, post_melt_bolt11, - post_swap + post_swap, + post_check ) )] /// OpenAPI spec for the mint's v1 APIs diff --git a/crates/cdk-axum/src/router_handlers.rs b/crates/cdk-axum/src/router_handlers.rs index fbd899204..8fc06a889 100644 --- a/crates/cdk-axum/src/router_handlers.rs +++ b/crates/cdk-axum/src/router_handlers.rs @@ -286,6 +286,19 @@ pub async fn post_melt_bolt11( Ok(Json(res)) } +#[utoipa::path( + post, + context_path = "/v1", + path = "/checkstate", + request_body(content = CheckStateRequest, description = "State params", content_type = "application/json"), + responses( + (status = 200, description = "Successful response", body = CheckStateResponse, content_type = "application/json"), + (status = 500, description = "Server error", body = ErrorResponse, content_type = "application/json") + ) +)] +/// Check whether a proof is spent already or is pending in a transaction +/// +/// Check whether a secret has been spent already or not. pub async fn post_check( State(state): State, Json(payload): Json, diff --git a/crates/cdk/src/nuts/nut07.rs b/crates/cdk/src/nuts/nut07.rs index 3b69102d3..a8a739502 100644 --- a/crates/cdk/src/nuts/nut07.rs +++ b/crates/cdk/src/nuts/nut07.rs @@ -21,6 +21,7 @@ pub enum Error { /// State of Proof #[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, Serialize, Deserialize)] #[serde(rename_all = "UPPERCASE")] +#[cfg_attr(feature = "mint", derive(utoipa::ToSchema))] pub enum State { /// Spent Spent, @@ -63,19 +64,23 @@ impl FromStr for State { } } -/// Check spendabale request [NUT-07] +/// Check spendable request [NUT-07] #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] +#[cfg_attr(feature = "mint", derive(utoipa::ToSchema))] pub struct CheckStateRequest { /// Y's of the proofs to check #[serde(rename = "Ys")] + #[cfg_attr(feature = "mint", schema(value_type = Vec, max_items = 1_000))] pub ys: Vec, } /// Proof state [NUT-07] #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] +#[cfg_attr(feature = "mint", derive(utoipa::ToSchema))] pub struct ProofState { /// Y of proof #[serde(rename = "Y")] + #[cfg_attr(feature = "mint", schema(value_type = String))] pub y: PublicKey, /// State of proof pub state: State, @@ -85,6 +90,7 @@ pub struct ProofState { /// Check Spendable Response [NUT-07] #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] +#[cfg_attr(feature = "mint", derive(utoipa::ToSchema))] pub struct CheckStateResponse { /// Proof states pub states: Vec,