Skip to content

Commit

Permalink
mint: annotate post_check for Swagger UI
Browse files Browse the repository at this point in the history
  • Loading branch information
ok300 committed Oct 10, 2024
1 parent 243094b commit 7a01ccc
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
8 changes: 7 additions & 1 deletion crates/cdk-axum/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -54,6 +55,8 @@ pub struct MintState {
BlindedMessage,
BlindSignature,
BlindSignatureDleq,
CheckStateRequest,
CheckStateResponse,
ContactInfo,
CurrencyUnit,
ErrorCode,
Expand Down Expand Up @@ -86,8 +89,10 @@ pub struct MintState {
PaymentMethod,
Proof,
ProofDleq,
ProofState,
PublicKey,
SecretKey,
State,
SupportedSettings,
SwapRequest,
SwapResponse,
Expand All @@ -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
Expand Down
13 changes: 13 additions & 0 deletions crates/cdk-axum/src/router_handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<MintState>,
Json(payload): Json<CheckStateRequest>,
Expand Down
8 changes: 7 additions & 1 deletion crates/cdk/src/nuts/nut07.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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<String>, max_items = 1_000))]
pub ys: Vec<PublicKey>,
}

/// 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,
Expand All @@ -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<ProofState>,
Expand Down

0 comments on commit 7a01ccc

Please sign in to comment.