Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mintd: Add Swagger UI for mint APIs #389

Merged
merged 1 commit into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ jobs:
-p cdk --no-default-features,
-p cdk --no-default-features --features wallet,
-p cdk --no-default-features --features mint,
-p cdk --no-default-features --features "mint swagger",
-p cdk-redb,
-p cdk-sqlite,
-p cdk-axum,
Expand Down Expand Up @@ -143,6 +144,7 @@ jobs:
-p cdk --no-default-features,
-p cdk --no-default-features --features wallet,
-p cdk --no-default-features --features mint,
-p cdk --no-default-features --features "mint swagger",
-p cdk-axum,
-p cdk-strike,
-p cdk-lnbits,
Expand Down
4 changes: 4 additions & 0 deletions crates/cdk-axum/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ axum = "0.6.20"
cdk = { path = "../cdk", version = "0.4.0", default-features = false, features = ["mint"] }
tokio = { version = "1", default-features = false }
tracing = { version = "0.1", default-features = false, features = ["attributes", "log"] }
utoipa = { version = "4", features = ["preserve_order", "preserve_path_order"], optional = true }
futures = { version = "0.3.28", default-features = false }
moka = { version = "0.11.1", features = ["future"] }
serde_json = "1"
paste = "1.0.15"

[features]
swagger = ["cdk/swagger", "dep:utoipa"]
111 changes: 110 additions & 1 deletion crates/cdk-axum/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,133 @@
#![warn(rustdoc::bare_urls)]

use std::sync::Arc;
use std::time::Duration;

use anyhow::Result;
use axum::routing::{get, post};
use axum::Router;
use cdk::mint::Mint;
use moka::future::Cache;
use router_handlers::*;
use std::time::Duration;

mod router_handlers;

#[cfg(feature = "swagger")]
mod swagger_imports {
pub use cdk::amount::Amount;
pub use cdk::error::{ErrorCode, ErrorResponse};
pub use cdk::nuts::nut00::{
BlindSignature, BlindedMessage, CurrencyUnit, PaymentMethod, Proof, Witness,
};
pub use cdk::nuts::nut01::{Keys, KeysResponse, PublicKey, SecretKey};
pub use cdk::nuts::nut02::{Id, KeySet, KeySetInfo, KeySetVersion, KeysetResponse};
pub use cdk::nuts::nut03::{SwapRequest, SwapResponse};
pub use cdk::nuts::nut04;
pub use cdk::nuts::nut04::{
MintBolt11Request, MintBolt11Response, MintMethodSettings, MintQuoteBolt11Request,
MintQuoteBolt11Response,
};
pub use cdk::nuts::nut05;
pub use cdk::nuts::nut05::{
MeltBolt11Request, MeltMethodSettings, MeltQuoteBolt11Request, MeltQuoteBolt11Response,
};
pub use cdk::nuts::nut06::{ContactInfo, MintInfo, MintVersion, Nuts, SupportedSettings};
pub use cdk::nuts::nut07::{CheckStateRequest, CheckStateResponse, ProofState, State};
pub use cdk::nuts::nut09::{RestoreRequest, RestoreResponse};
pub use cdk::nuts::nut11::P2PKWitness;
pub use cdk::nuts::nut12::{BlindSignatureDleq, ProofDleq};
pub use cdk::nuts::nut14::HTLCWitness;
pub use cdk::nuts::nut15;
pub use cdk::nuts::nut15::{Mpp, MppMethodSettings};
pub use cdk::nuts::{MeltQuoteState, MintQuoteState};
}

#[cfg(feature = "swagger")]
use swagger_imports::*;

/// CDK Mint State
#[derive(Clone)]
pub struct MintState {
mint: Arc<Mint>,
cache: Cache<String, String>,
}

#[cfg(feature = "swagger")]
#[derive(utoipa::OpenApi)]
#[openapi(
components(schemas(
Amount,
BlindedMessage,
BlindSignature,
BlindSignatureDleq,
CheckStateRequest,
CheckStateResponse,
ContactInfo,
CurrencyUnit,
ErrorCode,
ErrorResponse,
HTLCWitness,
Id,
Keys,
KeysResponse,
KeysetResponse,
KeySet,
KeySetInfo,
KeySetVersion,
MeltBolt11Request,
MeltQuoteBolt11Request,
MeltQuoteBolt11Response,
MeltQuoteState,
MeltMethodSettings,
MintBolt11Request,
MintBolt11Response,
MintInfo,
MintQuoteBolt11Request,
MintQuoteBolt11Response,
MintQuoteState,
MintMethodSettings,
MintVersion,
Mpp,
MppMethodSettings,
Nuts,
P2PKWitness,
PaymentMethod,
Proof,
ProofDleq,
ProofState,
PublicKey,
RestoreRequest,
RestoreResponse,
SecretKey,
State,
SupportedSettings,
SwapRequest,
SwapResponse,
Witness,
nut04::Settings,
nut05::Settings,
nut15::Settings
)),
info(description = "Cashu CDK mint APIs", title = "cdk-mintd",),
paths(
get_keys,
get_keyset_pubkeys,
get_keysets,
get_mint_info,
get_mint_bolt11_quote,
get_check_mint_bolt11_quote,
post_mint_bolt11,
get_melt_bolt11_quote,
get_check_melt_bolt11_quote,
post_melt_bolt11,
post_swap,
post_check,
post_restore
)
)]
/// OpenAPI spec for the mint's v1 APIs
pub struct ApiDocV1;

/// Create mint [`Router`] with required endpoints for cashu mint
pub async fn create_mint_router(mint: Arc<Mint>, cache_ttl: u64, cache_tti: u64) -> Result<Router> {
let state = MintState {
Expand Down
Loading
Loading