Skip to content

Commit

Permalink
mint: annotate post_swap for Swagger UI
Browse files Browse the repository at this point in the history
  • Loading branch information
ok300 committed Oct 10, 2024
1 parent a702e9d commit 243094b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
6 changes: 5 additions & 1 deletion crates/cdk-axum/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use cdk::nuts::nut00::{
};
use cdk::nuts::nut01::{Keys, KeysResponse, PublicKey, SecretKey};
use cdk::nuts::nut02::{Id, KeySet, KeySetInfo, KeySetVersion, KeysetResponse};
use cdk::nuts::nut03::{SwapRequest, SwapResponse};
use cdk::nuts::nut04;
use cdk::nuts::nut04::{
MintBolt11Request, MintBolt11Response, MintMethodSettings, MintQuoteBolt11Request,
Expand Down Expand Up @@ -88,6 +89,8 @@ pub struct MintState {
PublicKey,
SecretKey,
SupportedSettings,
SwapRequest,
SwapResponse,
Witness,
nut04::Settings,
nut05::Settings,
Expand All @@ -104,7 +107,8 @@ pub struct MintState {
post_mint_bolt11,
get_melt_bolt11_quote,
get_check_melt_bolt11_quote,
post_melt_bolt11
post_melt_bolt11,
post_swap
)
)]
/// OpenAPI spec for the mint's v1 APIs
Expand Down
15 changes: 15 additions & 0 deletions crates/cdk-axum/src/router_handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,21 @@ pub async fn get_mint_info(State(state): State<MintState>) -> Result<Json<MintIn
Ok(Json(state.mint.mint_info().clone().time(unix_time())))
}

#[utoipa::path(
post,
context_path = "/v1",
path = "/swap",
request_body(content = SwapRequest, description = "Swap params", content_type = "application/json"),
responses(
(status = 200, description = "Successful response", body = SwapResponse, content_type = "application/json"),
(status = 500, description = "Server error", body = ErrorResponse, content_type = "application/json")
)
)]
/// Swap inputs for outputs of the same value
///
/// Requests a set of Proofs to be swapped for another set of BlindSignatures.
///
/// This endpoint can be used by Alice to swap a set of proofs before making a payment to Carol. It can then used by Carol to redeem the tokens for new proofs.
pub async fn post_swap(
State(state): State<MintState>,
Json(payload): Json<SwapRequest>,
Expand Down
3 changes: 3 additions & 0 deletions crates/cdk/src/nuts/nut03.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@ pub struct PreSwap {

/// Split Request [NUT-06]
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[cfg_attr(feature = "mint", derive(utoipa::ToSchema))]
pub struct SwapRequest {
/// Proofs that are to be spent in `Split`
#[cfg_attr(feature = "mint", schema(value_type = Vec<Proof>))]
pub inputs: Proofs,
/// Blinded Messages for Mint to sign
pub outputs: Vec<BlindedMessage>,
Expand Down Expand Up @@ -64,6 +66,7 @@ impl SwapRequest {

/// Split Response [NUT-06]
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[cfg_attr(feature = "mint", derive(utoipa::ToSchema))]
pub struct SwapResponse {
/// Promises
pub signatures: Vec<BlindSignature>,
Expand Down

0 comments on commit 243094b

Please sign in to comment.