Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions lightningd/watchman.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@

#include "config.h"
#include <bitcoin/tx.h>
#include <ccan/tal/str/str.h>
#include <ccan/tal/tal.h>
#include <inttypes.h>

struct lightningd;
struct pending_op;
Expand Down Expand Up @@ -144,4 +146,25 @@ void watchman_unwatch_blockdepth(struct lightningd *ld,
const char *owner,
u32 confirm_height);

/*
* Owner string constructors.
*
* Always use these instead of raw tal_fmt() to build owner strings. Sharing
* one constructor between watchman_watch_* and watchman_unwatch_* guarantees
* the strings are identical and the unwatch can never silently fail due to a
* format mismatch (e.g. %u vs PRIu64).
*/

/* wallet/ owners */
static inline const char *owner_wallet_utxo(const tal_t *ctx,
const struct bitcoin_outpoint *op)
{ return tal_fmt(ctx, "wallet/utxo/%s", fmt_bitcoin_outpoint(ctx, op)); }

/* One owner per (HD keyindex, address form) pair, e.g. "wallet/spk/42/p2tr".
* A single key can be watched in several forms at once (p2wpkh, p2tr and
* legacy p2sh-p2wpkh). */
static inline const char *owner_wallet_spk(const tal_t *ctx, u64 keyidx,
const char *form)
{ return tal_fmt(ctx, "wallet/spk/%"PRIu64"/%s", keyidx, form); }

#endif /* LIGHTNING_LIGHTNINGD_WATCHMAN_H */
27 changes: 27 additions & 0 deletions wallet/test/run-chain_moves_duplicate-detect.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ bool fromwire_hsmd_get_channel_basepoints_reply(const void *p UNNEEDED, struct b
/* Generated stub for fromwire_hsmd_get_output_scriptpubkey_reply */
bool fromwire_hsmd_get_output_scriptpubkey_reply(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, u8 **script UNNEEDED)
{ fprintf(stderr, "fromwire_hsmd_get_output_scriptpubkey_reply called!\n"); abort(); }
/* Generated stub for get_block_height */
u32 get_block_height(const struct chain_topology *topo UNNEEDED)
{ fprintf(stderr, "get_block_height called!\n"); abort(); }
/* Generated stub for get_channel_basepoints */
void get_channel_basepoints(struct lightningd *ld UNNEEDED,
const struct node_id *peer_id UNNEEDED,
Expand Down Expand Up @@ -157,6 +160,12 @@ void inflight_set_last_tx(struct channel_inflight *inflight UNNEEDED,
struct bitcoin_tx *last_tx STEALS UNNEEDED,
const struct bitcoin_signature last_sig UNNEEDED)
{ fprintf(stderr, "inflight_set_last_tx called!\n"); abort(); }
/* Generated stub for invoice_check_onchain_payment */
void invoice_check_onchain_payment(struct lightningd *ld UNNEEDED,
const u8 *scriptPubKey UNNEEDED,
struct amount_sat sat UNNEEDED,
const struct bitcoin_outpoint *outpoint UNNEEDED)
{ fprintf(stderr, "invoice_check_onchain_payment called!\n"); abort(); }
/* Generated stub for invoices_new */
struct invoices *invoices_new(const tal_t *ctx UNNEEDED,
struct wallet *wallet UNNEEDED,
Expand Down Expand Up @@ -368,6 +377,24 @@ const char *wait_index_name(enum wait_index index UNNEEDED)
/* Generated stub for wait_subsystem_name */
const char *wait_subsystem_name(enum wait_subsystem subsystem UNNEEDED)
{ fprintf(stderr, "wait_subsystem_name called!\n"); abort(); }
/* Generated stub for watchman_unwatch_outpoint */
void watchman_unwatch_outpoint(struct lightningd *ld UNNEEDED,
const char *owner UNNEEDED,
const struct bitcoin_outpoint *outpoint UNNEEDED)
{ fprintf(stderr, "watchman_unwatch_outpoint called!\n"); abort(); }
/* Generated stub for watchman_watch_outpoint */
void watchman_watch_outpoint(struct lightningd *ld UNNEEDED,
const char *owner UNNEEDED,
const struct bitcoin_outpoint *outpoint UNNEEDED,
u32 start_block UNNEEDED)
{ fprintf(stderr, "watchman_watch_outpoint called!\n"); abort(); }
/* Generated stub for watchman_watch_scriptpubkey */
void watchman_watch_scriptpubkey(struct lightningd *ld UNNEEDED,
const char *owner UNNEEDED,
const u8 *scriptpubkey UNNEEDED,
size_t script_len UNNEEDED,
u32 start_block UNNEEDED)
{ fprintf(stderr, "watchman_watch_scriptpubkey called!\n"); abort(); }
/* AUTOGENERATED MOCKS END */

void plugin_hook_db_sync(struct db *db UNNEEDED)
Expand Down
27 changes: 27 additions & 0 deletions wallet/test/run-db.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ bool fromwire_hsmd_get_channel_basepoints_reply(const void *p UNNEEDED, struct b
/* Generated stub for fromwire_hsmd_get_output_scriptpubkey_reply */
bool fromwire_hsmd_get_output_scriptpubkey_reply(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, u8 **script UNNEEDED)
{ fprintf(stderr, "fromwire_hsmd_get_output_scriptpubkey_reply called!\n"); abort(); }
/* Generated stub for get_block_height */
u32 get_block_height(const struct chain_topology *topo UNNEEDED)
{ fprintf(stderr, "get_block_height called!\n"); abort(); }
/* Generated stub for get_channel_basepoints */
void get_channel_basepoints(struct lightningd *ld UNNEEDED,
const struct node_id *peer_id UNNEEDED,
Expand Down Expand Up @@ -161,6 +164,12 @@ void inflight_set_last_tx(struct channel_inflight *inflight UNNEEDED,
struct bitcoin_tx *last_tx STEALS UNNEEDED,
const struct bitcoin_signature last_sig UNNEEDED)
{ fprintf(stderr, "inflight_set_last_tx called!\n"); abort(); }
/* Generated stub for invoice_check_onchain_payment */
void invoice_check_onchain_payment(struct lightningd *ld UNNEEDED,
const u8 *scriptPubKey UNNEEDED,
struct amount_sat sat UNNEEDED,
const struct bitcoin_outpoint *outpoint UNNEEDED)
{ fprintf(stderr, "invoice_check_onchain_payment called!\n"); abort(); }
/* Generated stub for invoices_new */
struct invoices *invoices_new(const tal_t *ctx UNNEEDED,
struct wallet *wallet UNNEEDED,
Expand Down Expand Up @@ -381,6 +390,24 @@ const char *wait_index_name(enum wait_index index UNNEEDED)
/* Generated stub for wait_subsystem_name */
const char *wait_subsystem_name(enum wait_subsystem subsystem UNNEEDED)
{ fprintf(stderr, "wait_subsystem_name called!\n"); abort(); }
/* Generated stub for watchman_unwatch_outpoint */
void watchman_unwatch_outpoint(struct lightningd *ld UNNEEDED,
const char *owner UNNEEDED,
const struct bitcoin_outpoint *outpoint UNNEEDED)
{ fprintf(stderr, "watchman_unwatch_outpoint called!\n"); abort(); }
/* Generated stub for watchman_watch_outpoint */
void watchman_watch_outpoint(struct lightningd *ld UNNEEDED,
const char *owner UNNEEDED,
const struct bitcoin_outpoint *outpoint UNNEEDED,
u32 start_block UNNEEDED)
{ fprintf(stderr, "watchman_watch_outpoint called!\n"); abort(); }
/* Generated stub for watchman_watch_scriptpubkey */
void watchman_watch_scriptpubkey(struct lightningd *ld UNNEEDED,
const char *owner UNNEEDED,
const u8 *scriptpubkey UNNEEDED,
size_t script_len UNNEEDED,
u32 start_block UNNEEDED)
{ fprintf(stderr, "watchman_watch_scriptpubkey called!\n"); abort(); }
/* AUTOGENERATED MOCKS END */

void plugin_hook_db_sync(struct db *db UNNEEDED)
Expand Down
27 changes: 27 additions & 0 deletions wallet/test/run-migrate_remove_chain_moves_duplicates.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ bool fromwire_hsmd_get_channel_basepoints_reply(const void *p UNNEEDED, struct b
/* Generated stub for fromwire_hsmd_get_output_scriptpubkey_reply */
bool fromwire_hsmd_get_output_scriptpubkey_reply(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, u8 **script UNNEEDED)
{ fprintf(stderr, "fromwire_hsmd_get_output_scriptpubkey_reply called!\n"); abort(); }
/* Generated stub for get_block_height */
u32 get_block_height(const struct chain_topology *topo UNNEEDED)
{ fprintf(stderr, "get_block_height called!\n"); abort(); }
/* Generated stub for get_channel_basepoints */
void get_channel_basepoints(struct lightningd *ld UNNEEDED,
const struct node_id *peer_id UNNEEDED,
Expand Down Expand Up @@ -194,6 +197,12 @@ void inflight_set_last_tx(struct channel_inflight *inflight UNNEEDED,
struct bitcoin_tx *last_tx STEALS UNNEEDED,
const struct bitcoin_signature last_sig UNNEEDED)
{ fprintf(stderr, "inflight_set_last_tx called!\n"); abort(); }
/* Generated stub for invoice_check_onchain_payment */
void invoice_check_onchain_payment(struct lightningd *ld UNNEEDED,
const u8 *scriptPubKey UNNEEDED,
struct amount_sat sat UNNEEDED,
const struct bitcoin_outpoint *outpoint UNNEEDED)
{ fprintf(stderr, "invoice_check_onchain_payment called!\n"); abort(); }
/* Generated stub for invoices_new */
struct invoices *invoices_new(const tal_t *ctx UNNEEDED,
struct wallet *wallet UNNEEDED,
Expand Down Expand Up @@ -417,6 +426,24 @@ const char *wait_index_name(enum wait_index index UNNEEDED)
/* Generated stub for wait_subsystem_name */
const char *wait_subsystem_name(enum wait_subsystem subsystem UNNEEDED)
{ fprintf(stderr, "wait_subsystem_name called!\n"); abort(); }
/* Generated stub for watchman_unwatch_outpoint */
void watchman_unwatch_outpoint(struct lightningd *ld UNNEEDED,
const char *owner UNNEEDED,
const struct bitcoin_outpoint *outpoint UNNEEDED)
{ fprintf(stderr, "watchman_unwatch_outpoint called!\n"); abort(); }
/* Generated stub for watchman_watch_outpoint */
void watchman_watch_outpoint(struct lightningd *ld UNNEEDED,
const char *owner UNNEEDED,
const struct bitcoin_outpoint *outpoint UNNEEDED,
u32 start_block UNNEEDED)
{ fprintf(stderr, "watchman_watch_outpoint called!\n"); abort(); }
/* Generated stub for watchman_watch_scriptpubkey */
void watchman_watch_scriptpubkey(struct lightningd *ld UNNEEDED,
const char *owner UNNEEDED,
const u8 *scriptpubkey UNNEEDED,
size_t script_len UNNEEDED,
u32 start_block UNNEEDED)
{ fprintf(stderr, "watchman_watch_scriptpubkey called!\n"); abort(); }
/* AUTOGENERATED MOCKS END */
static const char *setup_stmts[] = {
SQL("CREATE TABLE vars ("
Expand Down
24 changes: 24 additions & 0 deletions wallet/test/run-wallet.c
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,12 @@ void htlc_set_add_(struct lightningd *ld UNNEEDED,
void (*succeeded)(void * UNNEEDED, const struct preimage *) UNNEEDED,
void *arg UNNEEDED)
{ fprintf(stderr, "htlc_set_add_ called!\n"); abort(); }
/* Generated stub for invoice_check_onchain_payment */
void invoice_check_onchain_payment(struct lightningd *ld UNNEEDED,
const u8 *scriptPubKey UNNEEDED,
struct amount_sat sat UNNEEDED,
const struct bitcoin_outpoint *outpoint UNNEEDED)
{ fprintf(stderr, "invoice_check_onchain_payment called!\n"); abort(); }
/* Generated stub for invoice_check_payment */
const struct invoice_details *invoice_check_payment(const tal_t *ctx UNNEEDED,
struct lightningd *ld UNNEEDED,
Expand Down Expand Up @@ -811,6 +817,24 @@ struct txowatch *watch_txo(const tal_t *ctx UNNEEDED,
size_t input_num UNNEEDED,
const struct block *block))
{ fprintf(stderr, "watch_txo called!\n"); abort(); }
/* Generated stub for watchman_unwatch_outpoint */
void watchman_unwatch_outpoint(struct lightningd *ld UNNEEDED,
const char *owner UNNEEDED,
const struct bitcoin_outpoint *outpoint UNNEEDED)
{ fprintf(stderr, "watchman_unwatch_outpoint called!\n"); abort(); }
/* Generated stub for watchman_watch_outpoint */
void watchman_watch_outpoint(struct lightningd *ld UNNEEDED,
const char *owner UNNEEDED,
const struct bitcoin_outpoint *outpoint UNNEEDED,
u32 start_block UNNEEDED)
{ fprintf(stderr, "watchman_watch_outpoint called!\n"); abort(); }
/* Generated stub for watchman_watch_scriptpubkey */
void watchman_watch_scriptpubkey(struct lightningd *ld UNNEEDED,
const char *owner UNNEEDED,
const u8 *scriptpubkey UNNEEDED,
size_t script_len UNNEEDED,
u32 start_block UNNEEDED)
{ fprintf(stderr, "watchman_watch_scriptpubkey called!\n"); abort(); }
/* AUTOGENERATED MOCKS END */

/* Fake stubs to talk to hsm */
Expand Down
Loading