Skip to content

Commit

Permalink
fixup! add p2tr fallback generation. builds but crashes when run
Browse files Browse the repository at this point in the history
  • Loading branch information
niftynei committed Jul 24, 2023
1 parent 590c882 commit 64d2e9f
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 59 deletions.
40 changes: 9 additions & 31 deletions lightningd/invoice.c
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,7 @@ add_routehints(struct invoice_info *info,
bool *warning_deadends,
bool *warning_offline,
bool *warning_private_unused,
bool *warning_fallbacks)
bool *warning_fallbacks)
{
const struct chanhints *chanhints = info->chanhints;
bool node_unpublished;
Expand Down Expand Up @@ -936,7 +936,7 @@ static void listincoming_done(const char *buffer,
&warning_deadends,
&warning_offline,
&warning_private_unused,
&warning_fallbacks);
&warning_fallbacks);
if (ret)
return;

Expand Down Expand Up @@ -1163,37 +1163,15 @@ static struct command_result *json_invoice(struct command *cmd,
}
} else if (cmd->ld->unified_invoices) {
struct pubkey pubkey;
// enum addrtype *addrtype;
// char *p2sh, *bech32, *p2tr;
// size_t i;
// const jsmntok_t *t;
u8 *p2tr_script;
// p_opt("fallbacks", param_array, &fallbacks),
// addrtype = tal(cmd, enum addrtype);
// *addrtype = ADDR_P2TR;
// newaddr_inner(cmd, &pubkey, addrtype);
enum addrtype addrtype;
addrtype = ADDR_P2TR;
newaddr_inner(cmd, &pubkey, &addrtype);
p2tr_script = scriptpubkey_p2tr(tmpctx, &pubkey);
// p2sh = encode_pubkey_to_addr(cmd, &pubkey, ADDR_P2SH_SEGWIT, NULL);
// bech32 = encode_pubkey_to_addr(cmd, &pubkey, ADDR_BECH32, NULL);
// p2tr = encode_pubkey_to_addr(cmd, &pubkey, ADDR_P2TR, NULL);
// if (!p2sh || !bech32 || !p2tr) {
// return command_fail(cmd, LIGHTNINGD,
// "p2wpkh address encoding failure.");
// }
const u8 *p2tr;

fallback_scripts = tal_arr(cmd, const u8 *, 1);
fallback_scripts[0] = p2tr_script;
// log_info(cmd->ld->log, "fallback scripts = %s", type_to_string(tmpctx, const** u8, fallback_scripts));
// json_for_each_arr(i, t, fallbacks) {
// struct command_result *r;

// r = parse_fallback(cmd, buffer, t, &fallback_scripts[i]);
// if (r)
// return r;
// }

if (!newaddr_inner(cmd, &pubkey, ADDR_P2TR))
return command_fail(cmd, LIGHTNINGD, "Keys exhausted ");

p2tr = scriptpubkey_p2tr(fallback_scripts, &pubkey);
fallback_scripts[0] = p2tr;
}
fprintf(stderr, "what's in here?? %s\n", tal_hex(tmpctx, fallback_scripts[0]));

Expand Down
4 changes: 2 additions & 2 deletions lightningd/test/run-invoice-select-inchan.c
Original file line number Diff line number Diff line change
Expand Up @@ -658,8 +658,8 @@ struct channel *new_unsaved_channel(struct peer *peer UNNEEDED,
u32 feerate_ppm UNNEEDED)
{ fprintf(stderr, "new_unsaved_channel called!\n"); abort(); }
/* Generated stub for newaddr_inner */
bool newaddr_inner(struct command *cmd UNNEEDED, struct pubkey *pubkey UNNEEDED,
enum addrtype *addrtype UNNEEDED)
bool newaddr_inner(struct command *cmd UNNEEDED, struct pubkey *pubkey UNNEEDED,
enum addrtype addrtype UNNEEDED)
{ fprintf(stderr, "newaddr_inner called!\n"); abort(); }
/* Generated stub for node_id_cmp */
int node_id_cmp(const struct node_id *a UNNEEDED, const struct node_id *b UNNEEDED)
Expand Down
29 changes: 5 additions & 24 deletions wallet/walletrpc.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,8 @@ static struct command_result *param_newaddr(struct command *cmd,
return NULL;
}

bool newaddr_inner(struct command *cmd, struct pubkey *pubkey, enum addrtype *addrtype)
bool WARN_UNUSED_RESULT newaddr_inner(struct command *cmd, struct pubkey *pubkey, enum addrtype addrtype)
{
// struct pubkey pubkey;
// enum addrtype *addrtype;
s64 keyidx;
u8 *b32script;
u8 *p2tr_script;
Expand All @@ -136,11 +134,11 @@ bool newaddr_inner(struct command *cmd, struct pubkey *pubkey, enum addrtype *ad

b32script = scriptpubkey_p2wpkh(tmpctx, pubkey);
p2tr_script = scriptpubkey_p2tr(tmpctx, pubkey);
if (*addrtype & ADDR_BECH32)
if (addrtype & ADDR_BECH32)
txfilter_add_scriptpubkey(cmd->ld->owned_txfilter, b32script);
if (*addrtype & ADDR_P2TR)
if (addrtype & ADDR_P2TR)
txfilter_add_scriptpubkey(cmd->ld->owned_txfilter, p2tr_script);
if (cmd->ld->deprecated_apis && (*addrtype & ADDR_P2SH_SEGWIT))
if (cmd->ld->deprecated_apis && (addrtype & ADDR_P2SH_SEGWIT))
txfilter_add_scriptpubkey(cmd->ld->owned_txfilter,
scriptpubkey_p2sh(tmpctx, b32script));
return true;
Expand All @@ -165,27 +163,10 @@ static struct command_result *json_newaddr(struct command *cmd,
NULL))
return command_param_failed();

if (!newaddr_inner(cmd, &pubkey, addrtype)) {
if (!newaddr_inner(cmd, &pubkey, *addrtype)) {
return command_fail(cmd, LIGHTNINGD, "Keys exhausted ");
};

// keyidx = wallet_get_newindex(cmd->ld);
// if (keyidx < 0) {
// return command_fail(cmd, LIGHTNINGD, "Keys exhausted ");
// }

// bip32_pubkey(cmd->ld, &pubkey, keyidx);

// b32script = scriptpubkey_p2wpkh(tmpctx, &pubkey);
// p2tr_script = scriptpubkey_p2tr(tmpctx, &pubkey);
// if (*addrtype & ADDR_BECH32)
// txfilter_add_scriptpubkey(cmd->ld->owned_txfilter, b32script);
// if (*addrtype & ADDR_P2TR)
// txfilter_add_scriptpubkey(cmd->ld->owned_txfilter, p2tr_script);
// if (cmd->ld->deprecated_apis && (*addrtype & ADDR_P2SH_SEGWIT))
// txfilter_add_scriptpubkey(cmd->ld->owned_txfilter,
// scriptpubkey_p2sh(tmpctx, b32script));

p2sh = encode_pubkey_to_addr(cmd, &pubkey, ADDR_P2SH_SEGWIT, NULL);
bech32 = encode_pubkey_to_addr(cmd, &pubkey, ADDR_BECH32, NULL);
p2tr = encode_pubkey_to_addr(cmd, &pubkey, ADDR_P2TR, NULL);
Expand Down
4 changes: 2 additions & 2 deletions wallet/walletrpc.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ struct utxo;
/* We evaluate reserved timeouts lazily, so use this. */
bool is_reserved(const struct utxo *utxo, u32 current_height);

bool newaddr_inner(struct command *cmd, struct pubkey *pubkey,
enum addrtype *addrtype);
bool WARN_UNUSED_RESULT newaddr_inner(struct command *cmd, struct pubkey *pubkey,
enum addrtype addrtype);
#endif /* LIGHTNING_WALLET_WALLETRPC_H */

0 comments on commit 64d2e9f

Please sign in to comment.