mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-02-21 14:24:09 +01:00
plugins/fetchinvoice: remove obsolete string-based API.
Generate the payload in the callers. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
41ef85318d
commit
2fbe0f59f1
5 changed files with 37 additions and 47 deletions
|
@ -643,8 +643,7 @@ static struct pubkey *path_to_node(const tal_t *ctx,
|
||||||
/* Marshal arguments for sending onion messages */
|
/* Marshal arguments for sending onion messages */
|
||||||
struct sending {
|
struct sending {
|
||||||
struct sent *sent;
|
struct sent *sent;
|
||||||
const char *msgfield;
|
struct tlv_onionmsg_payload *payload;
|
||||||
const u8 *msgval;
|
|
||||||
struct command_result *(*done)(struct command *cmd,
|
struct command_result *(*done)(struct command *cmd,
|
||||||
const char *buf UNUSED,
|
const char *buf UNUSED,
|
||||||
const jsmntok_t *result UNUSED,
|
const jsmntok_t *result UNUSED,
|
||||||
|
@ -688,7 +687,7 @@ send_modern_message(struct command *cmd,
|
||||||
&node_alias[i]);
|
&node_alias[i]);
|
||||||
}
|
}
|
||||||
/* Final payload contains the actual data. */
|
/* 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 */
|
/* We don't include enctlv in final, but it gives us final alias */
|
||||||
if (!create_final_enctlv(tmpctx, &blinding_iter, &sent->path[nhops-1],
|
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");
|
"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;
|
payloads[nhops-1]->reply_path = reply_path;
|
||||||
|
|
||||||
req = jsonrpc_request_start(cmd->plugin, cmd, "sendonionmessage",
|
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,
|
static struct command_result *send_message(struct command *cmd,
|
||||||
struct sent *sent,
|
struct sent *sent,
|
||||||
const char *msgfield TAKES,
|
struct tlv_onionmsg_payload *payload STEALS,
|
||||||
const u8 *msgval TAKES,
|
|
||||||
struct command_result *(*done)
|
struct command_result *(*done)
|
||||||
(struct command *cmd,
|
(struct command *cmd,
|
||||||
const char *buf UNUSED,
|
const char *buf UNUSED,
|
||||||
|
@ -793,8 +782,7 @@ static struct command_result *send_message(struct command *cmd,
|
||||||
{
|
{
|
||||||
struct sending *sending = tal(cmd, struct sending);
|
struct sending *sending = tal(cmd, struct sending);
|
||||||
sending->sent = sent;
|
sending->sent = sent;
|
||||||
sending->msgfield = tal_strdup(sending, msgfield);
|
sending->payload = tal_steal(sending, payload);
|
||||||
sending->msgval = tal_dup_talarr(sending, u8, msgval);
|
|
||||||
sending->done = done;
|
sending->done = done;
|
||||||
|
|
||||||
return make_reply_path(cmd, sending);
|
return make_reply_path(cmd, sending);
|
||||||
|
@ -833,11 +821,12 @@ sendinvreq_after_connect(struct command *cmd,
|
||||||
const jsmntok_t *result UNUSED,
|
const jsmntok_t *result UNUSED,
|
||||||
struct sent *sent)
|
struct sent *sent)
|
||||||
{
|
{
|
||||||
u8 *rawinvreq = tal_arr(tmpctx, u8, 0);
|
struct tlv_onionmsg_payload *payload = tlv_onionmsg_payload_new(sent);
|
||||||
towire_tlv_invoice_request(&rawinvreq, sent->invreq);
|
|
||||||
|
|
||||||
return send_message(cmd, sent, "invoice_request", rawinvreq,
|
payload->invoice_request = tal_arr(payload, u8, 0);
|
||||||
sendonionmsg_done);
|
towire_tlv_invoice_request(&payload->invoice_request, sent->invreq);
|
||||||
|
|
||||||
|
return send_message(cmd, sent, payload, sendonionmsg_done);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct connect_attempt {
|
struct connect_attempt {
|
||||||
|
@ -1379,9 +1368,12 @@ sendinvoice_after_connect(struct command *cmd,
|
||||||
const jsmntok_t *result UNUSED,
|
const jsmntok_t *result UNUSED,
|
||||||
struct sent *sent)
|
struct sent *sent)
|
||||||
{
|
{
|
||||||
u8 *rawinv = tal_arr(tmpctx, u8, 0);
|
struct tlv_onionmsg_payload *payload = tlv_onionmsg_payload_new(sent);
|
||||||
towire_tlv_invoice(&rawinv, sent->inv);
|
|
||||||
return send_message(cmd, sent, "invoice", rawinv, prepare_inv_timeout);
|
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,
|
static struct command_result *createinvoice_done(struct command *cmd,
|
||||||
|
|
|
@ -43,12 +43,10 @@ static struct command_result *sendonionmessage_error(struct command *cmd,
|
||||||
return command_hook_success(cmd);
|
return command_hook_success(cmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* FIXME: replyfield string interface is to accomodate obsolete API */
|
|
||||||
struct command_result *
|
struct command_result *
|
||||||
send_onion_reply(struct command *cmd,
|
send_onion_reply(struct command *cmd,
|
||||||
struct tlv_onionmsg_payload_reply_path *reply_path,
|
struct tlv_onionmsg_payload_reply_path *reply_path,
|
||||||
const char *replyfield,
|
struct tlv_onionmsg_payload *payload)
|
||||||
const u8 *replydata)
|
|
||||||
{
|
{
|
||||||
struct out_req *req;
|
struct out_req *req;
|
||||||
size_t nhops;
|
size_t nhops;
|
||||||
|
@ -68,18 +66,14 @@ send_onion_reply(struct command *cmd,
|
||||||
json_object_start(req->js, NULL);
|
json_object_start(req->js, NULL);
|
||||||
json_add_pubkey(req->js, "id", &reply_path->path[i]->node_id);
|
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;
|
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);
|
tlv = tal_arr(tmpctx, u8, 0);
|
||||||
towire_tlv_onionmsg_payload(&tlv, omp);
|
towire_tlv_onionmsg_payload(&tlv, omp);
|
||||||
json_add_hex_talarr(req->js, "tlv", tlv);
|
json_add_hex_talarr(req->js, "tlv", tlv);
|
||||||
|
|
|
@ -9,6 +9,5 @@ struct command;
|
||||||
struct command_result *WARN_UNUSED_RESULT
|
struct command_result *WARN_UNUSED_RESULT
|
||||||
send_onion_reply(struct command *cmd,
|
send_onion_reply(struct command *cmd,
|
||||||
struct tlv_onionmsg_payload_reply_path *reply_path,
|
struct tlv_onionmsg_payload_reply_path *reply_path,
|
||||||
const char *replyfield,
|
struct tlv_onionmsg_payload *payload);
|
||||||
const u8 *replydata);
|
|
||||||
#endif /* LIGHTNING_PLUGINS_OFFERS_H */
|
#endif /* LIGHTNING_PLUGINS_OFFERS_H */
|
||||||
|
|
|
@ -26,8 +26,8 @@ fail_inv_level(struct command *cmd,
|
||||||
const char *fmt, va_list ap)
|
const char *fmt, va_list ap)
|
||||||
{
|
{
|
||||||
char *full_fmt, *msg;
|
char *full_fmt, *msg;
|
||||||
|
struct tlv_onionmsg_payload *payload;
|
||||||
struct tlv_invoice_error *err;
|
struct tlv_invoice_error *err;
|
||||||
u8 *errdata;
|
|
||||||
|
|
||||||
full_fmt = tal_fmt(tmpctx, "Failed invoice");
|
full_fmt = tal_fmt(tmpctx, "Failed invoice");
|
||||||
if (inv->inv) {
|
if (inv->inv) {
|
||||||
|
@ -56,9 +56,10 @@ fail_inv_level(struct command *cmd,
|
||||||
err->error = tal_dup_arr(err, char, msg, strlen(msg), 0);
|
err->error = tal_dup_arr(err, char, msg, strlen(msg), 0);
|
||||||
/* FIXME: Add suggested_value / erroneous_field! */
|
/* FIXME: Add suggested_value / erroneous_field! */
|
||||||
|
|
||||||
errdata = tal_arr(cmd, u8, 0);
|
payload = tlv_onionmsg_payload_new(tmpctx);
|
||||||
towire_tlv_invoice_error(&errdata, err);
|
payload->invoice_error = tal_arr(payload, u8, 0);
|
||||||
return send_onion_reply(cmd, inv->reply_path, "invoice_error", errdata);
|
towire_tlv_invoice_error(&payload->invoice_error, err);
|
||||||
|
return send_onion_reply(cmd, inv->reply_path, payload);
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct command_result *WARN_UNUSED_RESULT
|
static struct command_result *WARN_UNUSED_RESULT
|
||||||
|
|
|
@ -35,8 +35,8 @@ fail_invreq_level(struct command *cmd,
|
||||||
const char *fmt, va_list ap)
|
const char *fmt, va_list ap)
|
||||||
{
|
{
|
||||||
char *full_fmt, *msg;
|
char *full_fmt, *msg;
|
||||||
|
struct tlv_onionmsg_payload *payload;
|
||||||
struct tlv_invoice_error *err;
|
struct tlv_invoice_error *err;
|
||||||
u8 *errdata;
|
|
||||||
|
|
||||||
full_fmt = tal_fmt(tmpctx, "Failed invoice_request");
|
full_fmt = tal_fmt(tmpctx, "Failed invoice_request");
|
||||||
if (invreq->invreq) {
|
if (invreq->invreq) {
|
||||||
|
@ -61,9 +61,10 @@ fail_invreq_level(struct command *cmd,
|
||||||
err->error = tal_dup_arr(err, char, msg, strlen(msg), 0);
|
err->error = tal_dup_arr(err, char, msg, strlen(msg), 0);
|
||||||
/* FIXME: Add suggested_value / erroneous_field! */
|
/* FIXME: Add suggested_value / erroneous_field! */
|
||||||
|
|
||||||
errdata = tal_arr(cmd, u8, 0);
|
payload = tlv_onionmsg_payload_new(tmpctx);
|
||||||
towire_tlv_invoice_error(&errdata, err);
|
payload->invoice_error = tal_arr(payload, u8, 0);
|
||||||
return send_onion_reply(cmd, invreq->reply_path, "invoice_error", errdata);
|
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)
|
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;
|
char *hrp;
|
||||||
u8 *rawinv;
|
u8 *rawinv;
|
||||||
|
struct tlv_onionmsg_payload *payload;
|
||||||
const jsmntok_t *t;
|
const jsmntok_t *t;
|
||||||
|
|
||||||
/* We have a signed invoice, use it as a reply. */
|
/* 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));
|
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,
|
static struct command_result *createinvoice_error(struct command *cmd,
|
||||||
|
|
Loading…
Add table
Reference in a new issue