mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-19 15:14:23 +01:00
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:
committed by
Christian Decker
parent
1d1174c286
commit
179f573e45
@@ -57,9 +57,6 @@ void towire_secp256k1_ecdsa_signature(u8 **pptr UNNEEDED,
|
|||||||
/* Generated stub for towire_sha256 */
|
/* Generated stub for towire_sha256 */
|
||||||
void towire_sha256(u8 **pptr UNNEEDED, const struct sha256 *sha256 UNNEEDED)
|
void towire_sha256(u8 **pptr UNNEEDED, const struct sha256 *sha256 UNNEEDED)
|
||||||
{ fprintf(stderr, "towire_sha256 called!\n"); abort(); }
|
{ 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 */
|
/* Generated stub for towire_tu32 */
|
||||||
void towire_tu32(u8 **pptr UNNEEDED, u32 v UNNEEDED)
|
void towire_tu32(u8 **pptr UNNEEDED, u32 v UNNEEDED)
|
||||||
{ fprintf(stderr, "towire_tu32 called!\n"); abort(); }
|
{ fprintf(stderr, "towire_tu32 called!\n"); abort(); }
|
||||||
|
|||||||
@@ -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
|
/* This is only if we're a public node; otherwise, the offers plugin
|
||||||
* will have populated a real blinded path */
|
* 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 lightningd *ld,
|
||||||
struct tlv_invoice *inv STEALS)
|
struct tlv_invoice *inv)
|
||||||
{
|
{
|
||||||
struct blinded_path *path;
|
struct blinded_path *path;
|
||||||
struct privkey blinding;
|
struct privkey blinding;
|
||||||
struct tlv_encrypted_data_tlv *tlv;
|
struct tlv_encrypted_data_tlv *tlv;
|
||||||
u8 *wire;
|
|
||||||
size_t dlen;
|
|
||||||
|
|
||||||
path = tal(NULL, struct blinded_path);
|
path = tal(NULL, struct blinded_path);
|
||||||
if (!pubkey_from_node_id(&path->first_node_id, &ld->id))
|
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]->htlc_maximum_msat = AMOUNT_MSAT(21000000 * MSAT_PER_BTC);
|
||||||
inv->invoice_blindedpay[0]->features = NULL;
|
inv->invoice_blindedpay[0]->features = NULL;
|
||||||
|
|
||||||
/* But we need to update ->fields, so re-linearize */
|
/* Recalc ->fields */
|
||||||
wire = tal_arr(tmpctx, u8, 0);
|
tal_free(inv->fields);
|
||||||
towire_tlv_invoice(&wire, inv);
|
inv->fields = tlv_make_fields(inv, tlv_invoice);
|
||||||
tal_free(inv);
|
|
||||||
|
|
||||||
dlen = tal_bytelen(wire);
|
|
||||||
return fromwire_tlv_invoice(ctx,
|
|
||||||
cast_const2(const u8 **, &wire), &dlen);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct command_result *json_createinvoice(struct command *cmd,
|
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
|
* can recognize payments (bolt12 doesn't use
|
||||||
* payment_secret) */
|
* payment_secret) */
|
||||||
if (!inv->invoice_paths)
|
if (!inv->invoice_paths)
|
||||||
inv = add_stub_blindedpath(cmd, cmd->ld, inv);
|
add_stub_blindedpath(cmd, cmd->ld, inv);
|
||||||
|
|
||||||
if (inv->signature)
|
if (inv->signature)
|
||||||
return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
|
return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
|
||||||
|
|||||||
@@ -907,14 +907,11 @@ static struct command_result *invreq_done(struct command *cmd,
|
|||||||
static struct command_result *
|
static struct command_result *
|
||||||
force_payer_secret(struct command *cmd,
|
force_payer_secret(struct command *cmd,
|
||||||
struct sent *sent,
|
struct sent *sent,
|
||||||
struct tlv_invoice_request *invreq,
|
struct tlv_invoice_request *invreq STEALS,
|
||||||
const struct secret *payer_secret)
|
const struct secret *payer_secret)
|
||||||
{
|
{
|
||||||
struct sha256 merkle, sha;
|
struct sha256 merkle, sha;
|
||||||
secp256k1_keypair kp;
|
secp256k1_keypair kp;
|
||||||
u8 *msg;
|
|
||||||
const u8 *p;
|
|
||||||
size_t len;
|
|
||||||
|
|
||||||
if (secp256k1_keypair_create(secp256k1_ctx, &kp, payer_secret->data) != 1)
|
if (secp256k1_keypair_create(secp256k1_ctx, &kp, payer_secret->data) != 1)
|
||||||
return command_fail(cmd, LIGHTNINGD, "Bad payer_secret");
|
return command_fail(cmd, LIGHTNINGD, "Bad payer_secret");
|
||||||
@@ -928,16 +925,11 @@ force_payer_secret(struct command *cmd,
|
|||||||
"secp256k1_keypair_pub failed on %s?",
|
"secp256k1_keypair_pub failed on %s?",
|
||||||
type_to_string(tmpctx, struct secret, payer_secret));
|
type_to_string(tmpctx, struct secret, payer_secret));
|
||||||
|
|
||||||
/* Linearize populates ->fields */
|
/* Re-calculate ->fields */
|
||||||
msg = tal_arr(tmpctx, u8, 0);
|
tal_free(invreq->fields);
|
||||||
towire_tlv_invoice_request(&msg, invreq);
|
invreq->fields = tlv_make_fields(invreq, tlv_invoice_request);
|
||||||
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));
|
|
||||||
|
|
||||||
|
sent->invreq = tal_steal(sent, invreq);
|
||||||
merkle_tlv(sent->invreq->fields, &merkle);
|
merkle_tlv(sent->invreq->fields, &merkle);
|
||||||
sighash_from_merkle("invoice_request", "signature", &merkle, &sha);
|
sighash_from_merkle("invoice_request", "signature", &merkle, &sha);
|
||||||
|
|
||||||
|
|||||||
@@ -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.h_args := $(wire/onion_wiregen.h_args)
|
||||||
wire/onion_exp_wiregen.c_args := $(wire/onion_wiregen.c_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_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'
|
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)
|
wire/channel_type_wiregen.c_args := $(wire/channel_type_wiregen.h_args)
|
||||||
|
|
||||||
# All generated wire/ files depend on this Makefile
|
# 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
|
maintainer-clean: wire-maintainer-clean
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user