diff --git a/plugins/fetchinvoice.c b/plugins/fetchinvoice.c index bf780e23f..8c587d60d 100644 --- a/plugins/fetchinvoice.c +++ b/plugins/fetchinvoice.c @@ -643,8 +643,7 @@ static struct pubkey *path_to_node(const tal_t *ctx, /* Marshal arguments for sending onion messages */ struct sending { struct sent *sent; - const char *msgfield; - const u8 *msgval; + struct tlv_onionmsg_payload *payload; struct command_result *(*done)(struct command *cmd, const char *buf UNUSED, const jsmntok_t *result UNUSED, @@ -688,7 +687,7 @@ send_modern_message(struct command *cmd, &node_alias[i]); } /* Final payload contains the actual data. */ - payloads[nhops-1] = tlv_onionmsg_payload_new(payloads); + payloads[nhops-1] = sending->payload; /* We don't include enctlv in final, but it gives us final alias */ if (!create_final_enctlv(tmpctx, &blinding_iter, &sent->path[nhops-1], @@ -700,15 +699,6 @@ send_modern_message(struct command *cmd, "Could create final enctlv"); } - /* FIXME: This interface is a string for sendobsonionmessage! */ - if (streq(sending->msgfield, "invoice_request")) { - payloads[nhops-1]->invoice_request - = cast_const(u8 *, sending->msgval); - } else { - assert(streq(sending->msgfield, "invoice")); - payloads[nhops-1]->invoice - = cast_const(u8 *, sending->msgval); - } payloads[nhops-1]->reply_path = reply_path; req = jsonrpc_request_start(cmd->plugin, cmd, "sendonionmessage", @@ -783,8 +773,7 @@ static struct command_result *make_reply_path(struct command *cmd, static struct command_result *send_message(struct command *cmd, struct sent *sent, - const char *msgfield TAKES, - const u8 *msgval TAKES, + struct tlv_onionmsg_payload *payload STEALS, struct command_result *(*done) (struct command *cmd, const char *buf UNUSED, @@ -793,8 +782,7 @@ static struct command_result *send_message(struct command *cmd, { struct sending *sending = tal(cmd, struct sending); sending->sent = sent; - sending->msgfield = tal_strdup(sending, msgfield); - sending->msgval = tal_dup_talarr(sending, u8, msgval); + sending->payload = tal_steal(sending, payload); sending->done = done; return make_reply_path(cmd, sending); @@ -833,11 +821,12 @@ sendinvreq_after_connect(struct command *cmd, const jsmntok_t *result UNUSED, struct sent *sent) { - u8 *rawinvreq = tal_arr(tmpctx, u8, 0); - towire_tlv_invoice_request(&rawinvreq, sent->invreq); + struct tlv_onionmsg_payload *payload = tlv_onionmsg_payload_new(sent); - return send_message(cmd, sent, "invoice_request", rawinvreq, - sendonionmsg_done); + payload->invoice_request = tal_arr(payload, u8, 0); + towire_tlv_invoice_request(&payload->invoice_request, sent->invreq); + + return send_message(cmd, sent, payload, sendonionmsg_done); } struct connect_attempt { @@ -1379,9 +1368,12 @@ sendinvoice_after_connect(struct command *cmd, const jsmntok_t *result UNUSED, struct sent *sent) { - u8 *rawinv = tal_arr(tmpctx, u8, 0); - towire_tlv_invoice(&rawinv, sent->inv); - return send_message(cmd, sent, "invoice", rawinv, prepare_inv_timeout); + struct tlv_onionmsg_payload *payload = tlv_onionmsg_payload_new(sent); + + payload->invoice = tal_arr(payload, u8, 0); + towire_tlv_invoice(&payload->invoice, sent->inv); + + return send_message(cmd, sent, payload, prepare_inv_timeout); } static struct command_result *createinvoice_done(struct command *cmd, diff --git a/plugins/offers.c b/plugins/offers.c index 41a4af4a9..cfe3309cf 100644 --- a/plugins/offers.c +++ b/plugins/offers.c @@ -43,12 +43,10 @@ static struct command_result *sendonionmessage_error(struct command *cmd, return command_hook_success(cmd); } -/* FIXME: replyfield string interface is to accomodate obsolete API */ struct command_result * send_onion_reply(struct command *cmd, struct tlv_onionmsg_payload_reply_path *reply_path, - const char *replyfield, - const u8 *replydata) + struct tlv_onionmsg_payload *payload) { struct out_req *req; size_t nhops; @@ -68,18 +66,14 @@ send_onion_reply(struct command *cmd, json_object_start(req->js, NULL); json_add_pubkey(req->js, "id", &reply_path->path[i]->node_id); - omp = tlv_onionmsg_payload_new(tmpctx); + /* Put payload in last hop. */ + if (i == nhops - 1) + omp = payload; + else + omp = tlv_onionmsg_payload_new(tmpctx); + omp->encrypted_data_tlv = reply_path->path[i]->encrypted_recipient_data; - /* Put payload in last hop. */ - if (i == nhops - 1) { - if (streq(replyfield, "invoice")) { - omp->invoice = cast_const(u8 *, replydata); - } else { - assert(streq(replyfield, "invoice_error")); - omp->invoice_error = cast_const(u8 *, replydata); - } - } tlv = tal_arr(tmpctx, u8, 0); towire_tlv_onionmsg_payload(&tlv, omp); json_add_hex_talarr(req->js, "tlv", tlv); diff --git a/plugins/offers.h b/plugins/offers.h index ab7a33d80..d283da351 100644 --- a/plugins/offers.h +++ b/plugins/offers.h @@ -9,6 +9,5 @@ struct command; struct command_result *WARN_UNUSED_RESULT send_onion_reply(struct command *cmd, struct tlv_onionmsg_payload_reply_path *reply_path, - const char *replyfield, - const u8 *replydata); + struct tlv_onionmsg_payload *payload); #endif /* LIGHTNING_PLUGINS_OFFERS_H */ diff --git a/plugins/offers_inv_hook.c b/plugins/offers_inv_hook.c index a2b720f32..680307bee 100644 --- a/plugins/offers_inv_hook.c +++ b/plugins/offers_inv_hook.c @@ -26,8 +26,8 @@ fail_inv_level(struct command *cmd, const char *fmt, va_list ap) { char *full_fmt, *msg; + struct tlv_onionmsg_payload *payload; struct tlv_invoice_error *err; - u8 *errdata; full_fmt = tal_fmt(tmpctx, "Failed invoice"); if (inv->inv) { @@ -56,9 +56,10 @@ fail_inv_level(struct command *cmd, err->error = tal_dup_arr(err, char, msg, strlen(msg), 0); /* FIXME: Add suggested_value / erroneous_field! */ - errdata = tal_arr(cmd, u8, 0); - towire_tlv_invoice_error(&errdata, err); - return send_onion_reply(cmd, inv->reply_path, "invoice_error", errdata); + payload = tlv_onionmsg_payload_new(tmpctx); + payload->invoice_error = tal_arr(payload, u8, 0); + towire_tlv_invoice_error(&payload->invoice_error, err); + return send_onion_reply(cmd, inv->reply_path, payload); } static struct command_result *WARN_UNUSED_RESULT diff --git a/plugins/offers_invreq_hook.c b/plugins/offers_invreq_hook.c index e8a304fdc..17eb2c688 100644 --- a/plugins/offers_invreq_hook.c +++ b/plugins/offers_invreq_hook.c @@ -35,8 +35,8 @@ fail_invreq_level(struct command *cmd, const char *fmt, va_list ap) { char *full_fmt, *msg; + struct tlv_onionmsg_payload *payload; struct tlv_invoice_error *err; - u8 *errdata; full_fmt = tal_fmt(tmpctx, "Failed invoice_request"); if (invreq->invreq) { @@ -61,9 +61,10 @@ fail_invreq_level(struct command *cmd, err->error = tal_dup_arr(err, char, msg, strlen(msg), 0); /* FIXME: Add suggested_value / erroneous_field! */ - errdata = tal_arr(cmd, u8, 0); - towire_tlv_invoice_error(&errdata, err); - return send_onion_reply(cmd, invreq->reply_path, "invoice_error", errdata); + payload = tlv_onionmsg_payload_new(tmpctx); + payload->invoice_error = tal_arr(payload, u8, 0); + towire_tlv_invoice_error(&payload->invoice_error, err); + return send_onion_reply(cmd, invreq->reply_path, payload); } static struct command_result *WARN_UNUSED_RESULT PRINTF_FMT(3,4) @@ -170,6 +171,7 @@ static struct command_result *createinvoice_done(struct command *cmd, { char *hrp; u8 *rawinv; + struct tlv_onionmsg_payload *payload; const jsmntok_t *t; /* We have a signed invoice, use it as a reply. */ @@ -182,7 +184,9 @@ static struct command_result *createinvoice_done(struct command *cmd, json_tok_full(buf, t)); } - return send_onion_reply(cmd, ir->reply_path, "invoice", rawinv); + payload = tlv_onionmsg_payload_new(tmpctx); + payload->invoice = rawinv; + return send_onion_reply(cmd, ir->reply_path, payload); } static struct command_result *createinvoice_error(struct command *cmd,