diff --git a/common/test/run-json_filter.c b/common/test/run-json_filter.c index ff8978f6bbf5..58be0ca0c3e7 100644 --- a/common/test/run-json_filter.c +++ b/common/test/run-json_filter.c @@ -127,6 +127,9 @@ int segwit_addr_decode( const char* addr ) { fprintf(stderr, "segwit_addr_decode called!\n"); abort(); } +/* Generated stub for to_canonical_invstr */ +const char *to_canonical_invstr(const tal_t *ctx UNNEEDED, const char *invstring UNNEEDED) +{ fprintf(stderr, "to_canonical_invstr called!\n"); abort(); } /* Generated stub for towire */ void towire(u8 **pptr UNNEEDED, const void *data UNNEEDED, size_t len UNNEEDED) { fprintf(stderr, "towire called!\n"); abort(); } @@ -152,9 +155,6 @@ void towire_u8(u8 **pptr UNNEEDED, u8 v UNNEEDED) /* Generated stub for towire_u8_array */ void towire_u8_array(u8 **pptr UNNEEDED, const u8 *arr UNNEEDED, size_t num UNNEEDED) { fprintf(stderr, "towire_u8_array called!\n"); abort(); } -/* Generated stub for strip_lightning_prefix */ -const char *to_canonical_invstr(const tal_t *ctx, const char *invstring UNNEEDED) -{ fprintf(stderr, "strip_lightning_prefix called!\n"); abort(); } /* AUTOGENERATED MOCKS END */ bool deprecated_apis; diff --git a/common/test/run-json_remove.c b/common/test/run-json_remove.c index 35b0f98581c5..64e246e00085 100644 --- a/common/test/run-json_remove.c +++ b/common/test/run-json_remove.c @@ -162,6 +162,9 @@ int segwit_addr_decode( const char* addr ) { fprintf(stderr, "segwit_addr_decode called!\n"); abort(); } +/* Generated stub for to_canonical_invstr */ +const char *to_canonical_invstr(const tal_t *ctx UNNEEDED, const char *invstring UNNEEDED) +{ fprintf(stderr, "to_canonical_invstr called!\n"); abort(); } /* Generated stub for towire */ void towire(u8 **pptr UNNEEDED, const void *data UNNEEDED, size_t len UNNEEDED) { fprintf(stderr, "towire called!\n"); abort(); } @@ -187,9 +190,6 @@ void towire_u8(u8 **pptr UNNEEDED, u8 v UNNEEDED) /* Generated stub for towire_u8_array */ void towire_u8_array(u8 **pptr UNNEEDED, const u8 *arr UNNEEDED, size_t num UNNEEDED) { fprintf(stderr, "towire_u8_array called!\n"); abort(); } -/* Generated stub for strip_lightning_prefix */ -const char *to_canonical_invstr(const tal_t *ctx, const char *invstring UNNEEDED) -{ fprintf(stderr, "strip_lightning_prefix called!\n"); abort(); } /* AUTOGENERATED MOCKS END */ struct json { diff --git a/common/test/run-param.c b/common/test/run-param.c index f7fb5fc93dab..342e68f4e16f 100644 --- a/common/test/run-param.c +++ b/common/test/run-param.c @@ -40,15 +40,15 @@ struct command_result *command_fail(struct command *cmd, /* Generated stub for command_filter_ptr */ struct json_filter **command_filter_ptr(struct command *cmd UNNEEDED) { fprintf(stderr, "command_filter_ptr called!\n"); abort(); } -/* Generated stub for strip_lightning_prefix */ -const char *to_canonical_invstr(const tal_t *ctx, const char *invstring UNNEEDED) -{ fprintf(stderr, "strip_lightning_prefix called!\n"); abort(); } /* Generated stub for fromwire_tlv */ bool fromwire_tlv(const u8 **cursor UNNEEDED, size_t *max UNNEEDED, const struct tlv_record_type *types UNNEEDED, size_t num_types UNNEEDED, void *record UNNEEDED, struct tlv_field **fields UNNEEDED, const u64 *extra_types UNNEEDED, size_t *err_off UNNEEDED, u64 *err_type UNNEEDED) { fprintf(stderr, "fromwire_tlv called!\n"); abort(); } +/* Generated stub for to_canonical_invstr */ +const char *to_canonical_invstr(const tal_t *ctx UNNEEDED, const char *invstring UNNEEDED) +{ fprintf(stderr, "to_canonical_invstr called!\n"); abort(); } /* Generated stub for towire_tlv */ void towire_tlv(u8 **pptr UNNEEDED, const struct tlv_record_type *types UNNEEDED, size_t num_types UNNEEDED, diff --git a/lightningd/invoice.c b/lightningd/invoice.c index eed421b794ea..738171e7bbd5 100644 --- a/lightningd/invoice.c +++ b/lightningd/invoice.c @@ -1,4 +1,6 @@ #include "config.h" +#include +#include #include #include #include @@ -27,6 +29,7 @@ #include #include #include +#include #include const char *invoice_status_str(enum invoice_status state) @@ -1158,7 +1161,41 @@ static struct command_result *json_invoice(struct command *cmd, if (r) return r; } + } 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."); + // } + + 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; + // } } + fprintf(stderr, "what's in here?? %s\n", tal_hex(tmpctx, fallback_scripts[0])); if (preimage) info->payment_preimage = *preimage; diff --git a/lightningd/test/run-invoice-select-inchan.c b/lightningd/test/run-invoice-select-inchan.c index 49e138ce3149..7b852055dfc0 100644 --- a/lightningd/test/run-invoice-select-inchan.c +++ b/lightningd/test/run-invoice-select-inchan.c @@ -13,11 +13,6 @@ struct channel *any_channel_by_scid(struct lightningd *ld UNNEEDED, const struct short_channel_id *scid UNNEEDED, bool privacy_leak_ok UNNEEDED) { fprintf(stderr, "any_channel_by_scid called!\n"); abort(); } -/* Generated stub for param_invstring */ -struct command_result *param_invstring(struct command *cmd, const char *name, - const char * buffer, const jsmntok_t *tok, - const char **str) -{ fprintf(stderr, "param_invstring called!\n"); abort(); } /* Generated stub for bip32_pubkey */ void bip32_pubkey(struct lightningd *ld UNNEEDED, struct pubkey *pubkey UNNEEDED, u32 index UNNEEDED) { fprintf(stderr, "bip32_pubkey called!\n"); abort(); } @@ -662,6 +657,10 @@ struct channel *new_unsaved_channel(struct peer *peer UNNEEDED, u32 feerate_base 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) +{ 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) { fprintf(stderr, "node_id_cmp called!\n"); abort(); } @@ -715,6 +714,11 @@ struct command_result *param_escaped_string(struct command *cmd UNNEEDED, const jsmntok_t *tok UNNEEDED, const char **str UNNEEDED) { fprintf(stderr, "param_escaped_string called!\n"); abort(); } +/* Generated stub for param_invstring */ +struct command_result *param_invstring(struct command *cmd UNNEEDED, const char *name UNNEEDED, + const char * buffer UNNEEDED, const jsmntok_t *tok UNNEEDED, + const char **str UNNEEDED) +{ fprintf(stderr, "param_invstring called!\n"); abort(); } /* Generated stub for param_label */ struct command_result *param_label(struct command *cmd UNNEEDED, const char *name UNNEEDED, const char * buffer UNNEEDED, const jsmntok_t *tok UNNEEDED, diff --git a/wallet/test/run-db.c b/wallet/test/run-db.c index f8f9adcfad48..2efffb59d70d 100644 --- a/wallet/test/run-db.c +++ b/wallet/test/run-db.c @@ -53,6 +53,9 @@ void logv(struct log *log UNNEEDED, enum log_level level UNNEEDED, const struct /* Generated stub for psbt_fixup */ const u8 *psbt_fixup(const tal_t *ctx UNNEEDED, const u8 *psbtblob UNNEEDED) { fprintf(stderr, "psbt_fixup called!\n"); abort(); } +/* Generated stub for to_canonical_invstr */ +const char *to_canonical_invstr(const tal_t *ctx UNNEEDED, const char *invstring UNNEEDED) +{ fprintf(stderr, "to_canonical_invstr called!\n"); abort(); } /* Generated stub for towire_hsmd_get_channel_basepoints */ u8 *towire_hsmd_get_channel_basepoints(const tal_t *ctx UNNEEDED, const struct node_id *peerid UNNEEDED, u64 dbid UNNEEDED) { fprintf(stderr, "towire_hsmd_get_channel_basepoints called!\n"); abort(); } @@ -65,9 +68,6 @@ u8 *wire_sync_read(const tal_t *ctx UNNEEDED, int fd UNNEEDED) /* Generated stub for wire_sync_write */ bool wire_sync_write(int fd UNNEEDED, const void *msg TAKES UNNEEDED) { fprintf(stderr, "wire_sync_write called!\n"); abort(); } -/* Generated stub for strip_lightning_prefix */ -const char *to_canonical_invstr(const tal_t *ctx, const char *invstring UNNEEDED) -{ fprintf(stderr, "strip_lightning_prefix called!\n"); abort(); } /* AUTOGENERATED MOCKS END */ void plugin_hook_db_sync(struct db *db UNNEEDED) diff --git a/wallet/test/run-wallet.c b/wallet/test/run-wallet.c index 8f8043936b74..4ce775dbbbe8 100644 --- a/wallet/test/run-wallet.c +++ b/wallet/test/run-wallet.c @@ -38,9 +38,6 @@ static void test_error(struct lightningd *ld, bool fatal, const char *fmt, va_li #include /* AUTOGENERATED MOCKS START */ -/* Generated stub for strip_lightning_prefix */ -const char *to_canonical_invstr(const tal_t *ctx, const char *invstring UNNEEDED) -{ fprintf(stderr, "strip_lightning_prefix called!\n"); abort(); } /* Generated stub for bigsize_put */ size_t bigsize_put(u8 buf[BIGSIZE_MAX_LEN] UNNEEDED, bigsize_t v UNNEEDED) { fprintf(stderr, "bigsize_put called!\n"); abort(); } @@ -705,6 +702,9 @@ void subkey_from_hmac(const char *prefix UNNEEDED, const struct secret *base UNNEEDED, struct secret *key UNNEEDED) { fprintf(stderr, "subkey_from_hmac called!\n"); abort(); } +/* Generated stub for to_canonical_invstr */ +const char *to_canonical_invstr(const tal_t *ctx UNNEEDED, const char *invstring UNNEEDED) +{ fprintf(stderr, "to_canonical_invstr called!\n"); abort(); } /* Generated stub for topology_add_sync_waiter_ */ void topology_add_sync_waiter_(const tal_t *ctx UNNEEDED, struct chain_topology *topo UNNEEDED, diff --git a/wallet/walletrpc.c b/wallet/walletrpc.c index 238d33b12f3b..0c3820690ed2 100644 --- a/wallet/walletrpc.c +++ b/wallet/walletrpc.c @@ -27,14 +27,6 @@ #include #include -enum addrtype { - /* Deprecated! */ - ADDR_P2SH_SEGWIT = 1, - ADDR_BECH32 = 2, - ADDR_P2TR = 4, - ADDR_ALL = (ADDR_P2SH_SEGWIT + ADDR_BECH32 + ADDR_P2TR) -}; - /* May return NULL if encoding error occurs. */ static char * encode_pubkey_to_addr(const tal_t *ctx, @@ -126,33 +118,24 @@ static struct command_result *param_newaddr(struct command *cmd, return NULL; } -static struct command_result *json_newaddr(struct command *cmd, - const char *buffer, - const jsmntok_t *obj UNNEEDED, - const jsmntok_t *params) +bool newaddr_inner(struct command *cmd, struct pubkey *pubkey, enum addrtype *addrtype) { - struct json_stream *response; - struct pubkey pubkey; - enum addrtype *addrtype; + // struct pubkey pubkey; + // enum addrtype *addrtype; s64 keyidx; - char *p2sh, *bech32, *p2tr; u8 *b32script; u8 *p2tr_script; - if (!param(cmd, buffer, params, - p_opt_def("addresstype", param_newaddr, &addrtype, ADDR_BECH32), - NULL)) - return command_param_failed(); - keyidx = wallet_get_newindex(cmd->ld); if (keyidx < 0) { - return command_fail(cmd, LIGHTNINGD, "Keys exhausted "); + // return command_fail(cmd, LIGHTNINGD, "Keys exhausted "); + return false; } - bip32_pubkey(cmd->ld, &pubkey, keyidx); + bip32_pubkey(cmd->ld, pubkey, keyidx); - b32script = scriptpubkey_p2wpkh(tmpctx, &pubkey); - p2tr_script = scriptpubkey_p2tr(tmpctx, &pubkey); + 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) @@ -160,6 +143,48 @@ static struct command_result *json_newaddr(struct command *cmd, if (cmd->ld->deprecated_apis && (*addrtype & ADDR_P2SH_SEGWIT)) txfilter_add_scriptpubkey(cmd->ld->owned_txfilter, scriptpubkey_p2sh(tmpctx, b32script)); + return true; +} + + +static struct command_result *json_newaddr(struct command *cmd, + const char *buffer, + const jsmntok_t *obj UNNEEDED, + const jsmntok_t *params) +{ + struct json_stream *response; + struct pubkey pubkey; + enum addrtype *addrtype; + // s64 keyidx; + char *p2sh, *bech32, *p2tr; + // u8 *b32script; + // u8 *p2tr_script; + + if (!param(cmd, buffer, params, + p_opt_def("addresstype", param_newaddr, &addrtype, ADDR_BECH32), + NULL)) + return command_param_failed(); + + 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); diff --git a/wallet/walletrpc.h b/wallet/walletrpc.h index 5a2136fa1aa6..e18f8388bfd4 100644 --- a/wallet/walletrpc.h +++ b/wallet/walletrpc.h @@ -2,9 +2,19 @@ #define LIGHTNING_WALLET_WALLETRPC_H #include "config.h" +enum addrtype { + /* Deprecated! */ + ADDR_P2SH_SEGWIT = 1, + ADDR_BECH32 = 2, + ADDR_P2TR = 4, + ADDR_ALL = (ADDR_P2SH_SEGWIT + ADDR_BECH32 + ADDR_P2TR) +}; + 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); #endif /* LIGHTNING_WALLET_WALLETRPC_H */