diff --git a/src/core/mint/mint.zig b/src/core/mint/mint.zig index f11a29a..e230586 100644 --- a/src/core/mint/mint.zig +++ b/src/core/mint/mint.zig @@ -11,6 +11,7 @@ const zul = @import("zul"); const RWMutex = helper.RWMutex; const MintInfo = core.nuts.MintInfo; const MintQuoteBolt11Response = core.nuts.nut04.MintQuoteBolt11Response; +const MeltQuoteBolt11Response = core.nuts.nut05.MeltQuoteBolt11Response; const MintQuoteState = core.nuts.nut04.QuoteState; const MintKeySet = core.nuts.MintKeySet; const CurrencyUnit = core.nuts.CurrencyUnit; @@ -937,6 +938,16 @@ pub const Mint = struct { .signatures = promises.items, }; } + + /// Check melt quote status + pub fn checkMeltQuote(self: *Mint, gpa: std.mem.Allocator, quote_id: [16]u8) !MeltQuoteBolt11Response { + const quote = try self.localstore + .value + .getMeltQuote(gpa, quote_id) orelse return error.UnknownQuote; + errdefer quote.deinit(); + + return MeltQuoteBolt11Response.fromMeltQuote(quote); + } }; /// Generate new [`MintKeySetInfo`] from path diff --git a/src/router/router.zig b/src/router/router.zig index a8626ab..2af17f1 100644 --- a/src/router/router.zig +++ b/src/router/router.zig @@ -50,6 +50,7 @@ pub fn createMintServer( router.get("/v1/keysets", router_handlers.getKeysets, .{}); router.get("/v1/keys/:keyset_id", router_handlers.getKeysetPubkeys, .{}); router.get("/v1/mint/quote/bolt11/:quote_id", router_handlers.getCheckMintBolt11Quote, .{}); + router.get("/v1/melt/quote/bolt11/:quote_id", router_handlers.getCheckMeltBolt11Quote, .{}); router.post("/v1/checkstate", router_handlers.postCheck, .{}); router.get("/v1/info", router_handlers.getMintInfo, .{}); diff --git a/src/router/router_handlers.zig b/src/router/router_handlers.zig index fc63bb2..e7ad5a6 100644 --- a/src/router/router_handlers.zig +++ b/src/router/router_handlers.zig @@ -48,6 +48,24 @@ pub fn getCheckMintBolt11Quote( return try res.json(quote, .{}); } +pub fn getCheckMeltBolt11Quote( + state: MintState, + req: *httpz.Request, + res: *httpz.Response, +) !void { + const quote_id_hex = req.param("quote_id") orelse return error.ExpectQuoteId; + + const quote_id = try zul.UUID.parse(quote_id_hex); + const quote = state + .mint + .checkMeltQuote(res.arena, quote_id.bin) catch |err| { + std.log.debug("Could not check melt quote {any}: {any}", .{ quote_id, err }); + return error.CheckMintQuoteFailed; + }; + + return try res.json(quote, .{}); +} + pub fn postCheck( state: MintState, req: *httpz.Request,