lightningd/invoice.c, plugins/fetchinvoice.c: use tlv_make_fields() instead of towire/fromwire hack.

I forgot this existed!

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2022-11-09 13:02:01 +10:30
committed by Christian Decker
parent 1d1174c286
commit 179f573e45
4 changed files with 14 additions and 32 deletions

View File

@@ -57,9 +57,6 @@ void towire_secp256k1_ecdsa_signature(u8 **pptr UNNEEDED,
/* Generated stub for towire_sha256 */
void towire_sha256(u8 **pptr UNNEEDED, const struct sha256 *sha256 UNNEEDED)
{ fprintf(stderr, "towire_sha256 called!\n"); abort(); }
/* Generated stub for towire_tu16 */
void towire_tu16(u8 **pptr UNNEEDED, u16 v UNNEEDED)
{ fprintf(stderr, "towire_tu16 called!\n"); abort(); }
/* Generated stub for towire_tu32 */
void towire_tu32(u8 **pptr UNNEEDED, u32 v UNNEEDED)
{ fprintf(stderr, "towire_tu32 called!\n"); abort(); }

View File

@@ -1634,15 +1634,13 @@ static struct command_result *fail_exists(struct command *cmd,
/* This is only if we're a public node; otherwise, the offers plugin
* will have populated a real blinded path */
static struct tlv_invoice *add_stub_blindedpath(const tal_t *ctx,
static void add_stub_blindedpath(const tal_t *ctx,
struct lightningd *ld,
struct tlv_invoice *inv STEALS)
struct tlv_invoice *inv)
{
struct blinded_path *path;
struct privkey blinding;
struct tlv_encrypted_data_tlv *tlv;
u8 *wire;
size_t dlen;
path = tal(NULL, struct blinded_path);
if (!pubkey_from_node_id(&path->first_node_id, &ld->id))
@@ -1686,14 +1684,9 @@ static struct tlv_invoice *add_stub_blindedpath(const tal_t *ctx,
inv->invoice_blindedpay[0]->htlc_maximum_msat = AMOUNT_MSAT(21000000 * MSAT_PER_BTC);
inv->invoice_blindedpay[0]->features = NULL;
/* But we need to update ->fields, so re-linearize */
wire = tal_arr(tmpctx, u8, 0);
towire_tlv_invoice(&wire, inv);
tal_free(inv);
dlen = tal_bytelen(wire);
return fromwire_tlv_invoice(ctx,
cast_const2(const u8 **, &wire), &dlen);
/* Recalc ->fields */
tal_free(inv->fields);
inv->fields = tlv_make_fields(inv, tlv_invoice);
}
static struct command_result *json_createinvoice(struct command *cmd,
@@ -1782,7 +1775,7 @@ static struct command_result *json_createinvoice(struct command *cmd,
* can recognize payments (bolt12 doesn't use
* payment_secret) */
if (!inv->invoice_paths)
inv = add_stub_blindedpath(cmd, cmd->ld, inv);
add_stub_blindedpath(cmd, cmd->ld, inv);
if (inv->signature)
return command_fail(cmd, JSONRPC2_INVALID_PARAMS,

View File

@@ -907,14 +907,11 @@ static struct command_result *invreq_done(struct command *cmd,
static struct command_result *
force_payer_secret(struct command *cmd,
struct sent *sent,
struct tlv_invoice_request *invreq,
struct tlv_invoice_request *invreq STEALS,
const struct secret *payer_secret)
{
struct sha256 merkle, sha;
secp256k1_keypair kp;
u8 *msg;
const u8 *p;
size_t len;
if (secp256k1_keypair_create(secp256k1_ctx, &kp, payer_secret->data) != 1)
return command_fail(cmd, LIGHTNINGD, "Bad payer_secret");
@@ -928,16 +925,11 @@ force_payer_secret(struct command *cmd,
"secp256k1_keypair_pub failed on %s?",
type_to_string(tmpctx, struct secret, payer_secret));
/* Linearize populates ->fields */
msg = tal_arr(tmpctx, u8, 0);
towire_tlv_invoice_request(&msg, invreq);
p = msg;
len = tal_bytelen(msg);
sent->invreq = fromwire_tlv_invoice_request(cmd, &p, &len);
if (!sent->invreq)
plugin_err(cmd->plugin,
"Could not remarshall invreq %s", tal_hex(tmpctx, msg));
/* Re-calculate ->fields */
tal_free(invreq->fields);
invreq->fields = tlv_make_fields(invreq, tlv_invoice_request);
sent->invreq = tal_steal(sent, invreq);
merkle_tlv(sent->invreq->fields, &merkle);
sighash_from_merkle("invoice_request", "signature", &merkle, &sha);

View File

@@ -137,7 +137,7 @@ wire/peer_exp_printgen.h_args := --include='wire/channel_type_printgen.h'
wire/onion_exp_wiregen.h_args := $(wire/onion_wiregen.h_args)
wire/onion_exp_wiregen.c_args := $(wire/onion_wiregen.c_args)
wire/bolt12_wiregen.c_args := -s --expose-tlv-type=tlv_blinded_path --expose-tlv-type=tlv_invoice_request
wire/bolt12_wiregen.c_args := -s --expose-tlv-type=tlv_blinded_path --expose-tlv-type=tlv_invoice_request --expose-tlv-type=tlv_invoice
wire/bolt12_wiregen.h_args := --include='bitcoin/short_channel_id.h' --include='bitcoin/signature.h' --include='bitcoin/privkey.h' --include='common/bigsize.h' --include='common/amount.h' --include='common/node_id.h' --include='bitcoin/block.h' --include='wire/onion_wire.h' $(wire/bolt12_wiregen.c_args)
wire/bolt12_printgen.c_args := --expose-tlv-type=tlv_blinded_path --expose-tlv-type=tlv_invoice_request --include='wire/onion$(EXP)_wiregen.h' --include='wire/onion$(EXP)_printgen.h'
@@ -155,7 +155,7 @@ wire/channel_type_wiregen.h_args := -s
wire/channel_type_wiregen.c_args := $(wire/channel_type_wiregen.h_args)
# All generated wire/ files depend on this Makefile
$(filter %printgen.h %printgen.c %wiregen.h %wiregen.c, $(WIRE_SRC) $(WIRE_PRINT_SRC) $(WIRE_NONEXP_SRC) $(WIRE_HEADERS) $(WIRE_NONEXP_HEADERS)): wire/Makefile
$(filter %printgen.h %printgen.c %wiregen.h %wiregen.c, $(WIRE_SRC) $(WIRE_BOLT12_SRC) $(WIRE_PRINT_SRC) $(WIRE_NONEXP_SRC) $(WIRE_HEADERS) $(WIRE_NONEXP_HEADERS)): wire/Makefile
maintainer-clean: wire-maintainer-clean