Skip to content

Commit

Permalink
lightningd: re-add 'offerout' functionality, as 'invoicerequest'.
Browse files Browse the repository at this point in the history
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
  • Loading branch information
rustyrussell authored and cdecker committed Nov 9, 2022
1 parent 3b17fe9 commit 89d462f
Show file tree
Hide file tree
Showing 11 changed files with 907 additions and 28 deletions.
31 changes: 26 additions & 5 deletions devtools/bolt12-cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -349,10 +349,10 @@ static bool print_recurrence_counter_with_base(const u32 *recurrence_counter,
return true;
}

static void print_payment_hash(const struct sha256 *payment_hash)
static void print_hash(const char *fieldname, const struct sha256 *hash)
{
printf("invoice_payment_hash: %s\n",
type_to_string(tmpctx, struct sha256, payment_hash));
printf("%s: %s\n",
fieldname, type_to_string(tmpctx, struct sha256, hash));
}

static void print_relative_expiry(u64 *created_at, u32 *relative)
Expand Down Expand Up @@ -511,12 +511,15 @@ int main(int argc, char *argv[])
}

if (streq(hrp, "lno")) {
struct sha256 offer_id;
const struct tlv_offer *offer
= offer_decode(ctx, argv[2], strlen(argv[2]),
NULL, NULL, &fail);
if (!offer)
errx(ERROR_BAD_DECODE, "Bad offer: %s", fail);

offer_offer_id(offer, &offer_id);
print_hash("offer_id", &offer_id);
if (offer->offer_chains)
print_offer_chains(offer->offer_chains);
if (offer->offer_amount)
Expand Down Expand Up @@ -545,12 +548,20 @@ int main(int argc, char *argv[])
if (!print_extra_fields(offer->fields))
well_formed = false;
} else if (streq(hrp, "lnr")) {
struct sha256 offer_id, invreq_id;
const struct tlv_invoice_request *invreq
= invrequest_decode(ctx, argv[2], strlen(argv[2]),
NULL, NULL, &fail);
if (!invreq)
errx(ERROR_BAD_DECODE, "Bad invreq: %s", fail);

if (invreq->offer_node_id) {
invreq_offer_id(invreq, &offer_id);
print_hash("offer_id", &offer_id);
}
invreq_invreq_id(invreq, &invreq_id);
print_hash("invreq_id", &invreq_id);

/* FIXME: We can do more intra-field checking! */
if (must_have(invreq, invreq_metadata))
print_hex("invreq_metadata", invreq->invreq_metadata);
Expand All @@ -572,7 +583,7 @@ int main(int argc, char *argv[])
well_formed &= print_utf8("offer_issuer", invreq->offer_issuer);
if (invreq->offer_quantity_max)
print_u64("offer_quantity_max", *invreq->offer_quantity_max);
if (must_have(invreq, offer_node_id))
if (invreq->offer_node_id)
print_node_id("offer_node_id", invreq->offer_node_id);
if (invreq->offer_recurrence)
well_formed &= print_recurrance(invreq->offer_recurrence,
Expand Down Expand Up @@ -607,12 +618,22 @@ int main(int argc, char *argv[])
if (!print_extra_fields(invreq->fields))
well_formed = false;
} else if (streq(hrp, "lni")) {
struct sha256 offer_id, invreq_id;
const struct tlv_invoice *invoice
= invoice_decode(ctx, argv[2], strlen(argv[2]),
NULL, NULL, &fail);
if (!invoice)
errx(ERROR_BAD_DECODE, "Bad invoice: %s", fail);

if (invoice->invreq_payer_id) {
if (invoice->offer_node_id) {
invoice_offer_id(invoice, &offer_id);
print_hash("offer_id", &offer_id);
}
invoice_invreq_id(invoice, &invreq_id);
print_hash("invreq_id", &invreq_id);
}

/* FIXME: We can do more intra-field checking! */
if (must_have(invoice, invreq_metadata))
print_hex("invreq_metadata", invoice->invreq_metadata);
Expand Down Expand Up @@ -670,7 +691,7 @@ int main(int argc, char *argv[])
print_relative_expiry(invoice->invoice_created_at,
invoice->invoice_relative_expiry);
if (must_have(invoice, invoice_payment_hash))
print_payment_hash(invoice->invoice_payment_hash);
print_hash("invoice_payment_hash", invoice->invoice_payment_hash);
if (must_have(invoice, invoice_amount))
print_msat("invoice_amount", *invoice->invoice_amount);
if (invoice->invoice_fallbacks)
Expand Down
19 changes: 12 additions & 7 deletions lightningd/offer.c
Original file line number Diff line number Diff line change
Expand Up @@ -396,14 +396,15 @@ static struct command_result *json_createinvoicerequest(struct command *cmd,
struct json_stream *response;
u64 *prev_basetime = NULL;
struct sha256 merkle;
bool *save, *single_use;
bool *save, *single_use, *exposeid;
enum offer_status status;
struct sha256 invreq_id;
const char *b12str;

if (!param(cmd, buffer, params,
p_req("bolt12", param_b12_invreq, &invreq),
p_req("savetodb", param_bool, &save),
p_opt_def("exposeid", param_bool, &exposeid, false),
p_opt("recurrence_label", param_label, &label),
p_opt_def("single_use", param_bool, &single_use, true),
NULL))
Expand Down Expand Up @@ -449,10 +450,14 @@ static struct command_result *json_createinvoicerequest(struct command *cmd,
}

invreq->invreq_payer_id = tal(invreq, struct pubkey);
if (!payer_key(cmd->ld,
invreq->invreq_metadata,
tal_bytelen(invreq->invreq_metadata),
invreq->invreq_payer_id)) {
if (*exposeid) {
if (!pubkey_from_node_id(invreq->invreq_payer_id,
&cmd->ld->id))
fatal("Our ID is invalid?");
} else if (!payer_key(cmd->ld,
invreq->invreq_metadata,
tal_bytelen(invreq->invreq_metadata),
invreq->invreq_payer_id)) {
return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
"Invalid tweak");
}
Expand All @@ -466,8 +471,8 @@ static struct command_result *json_createinvoicerequest(struct command *cmd,
merkle_tlv(invreq->fields, &merkle);
invreq->signature = tal(invreq, struct bip340sig);
hsm_sign_b12(cmd->ld, "invoice_request", "signature",
&merkle, invreq->invreq_metadata, invreq->invreq_payer_id,
invreq->signature);
&merkle, *exposeid ? NULL : invreq->invreq_metadata,
invreq->invreq_payer_id, invreq->signature);

b12str = invrequest_encode(cmd, invreq);

Expand Down
4 changes: 2 additions & 2 deletions plugins/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ PLUGIN_PAY_LIB_SRC := plugins/libplugin-pay.c
PLUGIN_PAY_LIB_HEADER := plugins/libplugin-pay.h
PLUGIN_PAY_LIB_OBJS := $(PLUGIN_PAY_LIB_SRC:.c=.o)

PLUGIN_OFFERS_SRC := plugins/offers.c plugins/offers_offer.c plugins/offers_invreq_hook.c
PLUGIN_OFFERS_SRC := plugins/offers.c plugins/offers_offer.c plugins/offers_invreq_hook.c plugins/offers_inv_hook.c
PLUGIN_OFFERS_OBJS := $(PLUGIN_OFFERS_SRC:.c=.o)
PLUGIN_OFFERS_HEADER := $(PLUGIN_OFFERS_SRC:.c=.h)

PLUGIN_FETCHINVOICE_SRC := plugins/fetchinvoice.c
PLUGIN_FETCHINVOICE_OBJS := $(PLUGIN_FETCHINVOICE_SRC:.c=.o)
PLUGIN_FETCHINVOICE_HEADER :=
PLUGIN_FETCHINVOICE_HEADER :=

PLUGIN_SPENDER_SRC := \
plugins/spender/fundchannel.c \
Expand Down
Loading

0 comments on commit 89d462f

Please sign in to comment.