From 19669d886b91ac47f73a5532785b3aeaea637303 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Wed, 12 Jul 2023 05:10:17 +0930 Subject: [PATCH] invoice: expose invoice_status_str function. Signed-off-by: Rusty Russell --- lightningd/invoice.c | 16 ++++++++++------ lightningd/invoice.h | 4 ++++ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/lightningd/invoice.c b/lightningd/invoice.c index 360ab13a7..f21966178 100644 --- a/lightningd/invoice.c +++ b/lightningd/invoice.c @@ -28,13 +28,17 @@ #include #include -static const char *invoice_status_str(const struct invoice_details *inv) +const char *invoice_status_str(enum invoice_status state) { - if (inv->state == PAID) + switch (state) { + case PAID: return "paid"; - if (inv->state == EXPIRED) + case EXPIRED: return "expired"; - return "unpaid"; + case UNPAID: + return "unpaid"; + } + abort(); } static void json_add_invoice_fields(struct json_stream *response, @@ -46,7 +50,7 @@ static void json_add_invoice_fields(struct json_stream *response, json_add_sha256(response, "payment_hash", &inv->rhash); if (inv->msat) json_add_amount_msat(response, "amount_msat", *inv->msat); - json_add_string(response, "status", invoice_status_str(inv)); + json_add_string(response, "status", invoice_status_str(inv->state)); if (inv->state == PAID) { json_add_u64(response, "pay_index", inv->pay_index); json_add_amount_msat(response, @@ -1347,7 +1351,7 @@ static struct command_result *json_delinvoice(struct command *cmd, /* This is time-sensitive, so only call once; otherwise error msg * might not make sense if it changed! */ - actual_status = invoice_status_str(details); + actual_status = invoice_status_str(details->state); if (!streq(actual_status, status)) { struct json_stream *js; js = json_stream_fail(cmd, INVOICE_STATUS_UNEXPECTED, diff --git a/lightningd/invoice.h b/lightningd/invoice.h index 4fba86064..35f29a2da 100644 --- a/lightningd/invoice.h +++ b/lightningd/invoice.h @@ -1,6 +1,7 @@ #ifndef LIGHTNING_LIGHTNINGD_INVOICE_H #define LIGHTNING_LIGHTNINGD_INVOICE_H #include "config.h" +#include #include struct amount_msat; @@ -38,4 +39,7 @@ void invoice_try_pay(struct lightningd *ld, struct htlc_set *set, const struct invoice_details *details); +/* Simple enum -> string converter for JSON fields */ +const char *invoice_status_str(enum invoice_status state); + #endif /* LIGHTNING_LIGHTNINGD_INVOICE_H */