Skip to content

Commit

Permalink
feat: check melt quote
Browse files Browse the repository at this point in the history
  • Loading branch information
StringNick committed Sep 14, 2024
1 parent 89bda97 commit 949e755
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/core/mint/mint.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/router/router.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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, .{});

Expand Down
18 changes: 18 additions & 0 deletions src/router/router_handlers.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 949e755

Please sign in to comment.