2017-08-29 01:36:01 +09:30
|
|
|
#ifndef LIGHTNING_LIGHTNINGD_WATCH_H
|
|
|
|
#define LIGHTNING_LIGHTNINGD_WATCH_H
|
2016-01-22 06:41:49 +10:30
|
|
|
#include "config.h"
|
2017-12-18 17:11:52 +10:30
|
|
|
#include <bitcoin/tx.h>
|
2016-01-22 06:41:49 +10:30
|
|
|
#include <ccan/htable/htable_type.h>
|
|
|
|
|
2017-08-23 10:28:44 +09:30
|
|
|
struct block;
|
2018-02-21 07:29:09 +10:30
|
|
|
struct channel;
|
|
|
|
struct chain_topology;
|
2018-08-13 12:35:33 +09:30
|
|
|
struct lightningd;
|
2018-02-21 07:29:09 +10:30
|
|
|
struct txowatch;
|
|
|
|
struct txwatch;
|
2016-01-22 06:41:49 +10:30
|
|
|
|
2016-06-30 09:10:11 +09:30
|
|
|
enum watch_result {
|
|
|
|
DELETE_WATCH = -1,
|
|
|
|
KEEP_WATCHING = -2
|
|
|
|
};
|
|
|
|
|
2021-10-13 14:15:36 +10:30
|
|
|
const struct bitcoin_outpoint *txowatch_keyof(const struct txowatch *w);
|
|
|
|
size_t txo_hash(const struct bitcoin_outpoint *out);
|
|
|
|
bool txowatch_eq(const struct txowatch *w, const struct bitcoin_outpoint *out);
|
2016-01-22 06:41:49 +10:30
|
|
|
|
|
|
|
HTABLE_DEFINE_TYPE(struct txowatch, txowatch_keyof, txo_hash, txowatch_eq,
|
|
|
|
txowatch_hash);
|
|
|
|
|
2017-12-18 17:11:52 +10:30
|
|
|
const struct bitcoin_txid *txwatch_keyof(const struct txwatch *w);
|
|
|
|
size_t txid_hash(const struct bitcoin_txid *txid);
|
|
|
|
bool txwatch_eq(const struct txwatch *w, const struct bitcoin_txid *txid);
|
2016-01-22 06:41:49 +10:30
|
|
|
HTABLE_DEFINE_TYPE(struct txwatch, txwatch_keyof, txid_hash, txwatch_eq,
|
|
|
|
txwatch_hash);
|
|
|
|
|
|
|
|
|
2023-10-02 09:29:51 +10:30
|
|
|
struct txwatch *watch_txid_(const tal_t *ctx,
|
|
|
|
struct chain_topology *topo,
|
|
|
|
const struct bitcoin_txid *txid,
|
|
|
|
enum watch_result (*cb)(struct lightningd *ld,
|
|
|
|
const struct bitcoin_txid *,
|
|
|
|
const struct bitcoin_tx *,
|
|
|
|
unsigned int depth,
|
|
|
|
void *arg),
|
|
|
|
void *arg);
|
|
|
|
|
|
|
|
#define watch_txid(ctx, topo, txid, cb, arg) \
|
|
|
|
watch_txid_((ctx), (topo), (txid), \
|
|
|
|
typesafe_cb_preargs(enum watch_result, void *, \
|
|
|
|
(cb), (arg), \
|
|
|
|
struct lightningd *, \
|
|
|
|
const struct bitcoin_txid *, \
|
|
|
|
const struct bitcoin_tx *, \
|
|
|
|
unsigned int depth), \
|
|
|
|
(arg))
|
2016-04-24 19:39:21 +09:30
|
|
|
|
2018-02-21 07:29:09 +10:30
|
|
|
struct txowatch *watch_txo(const tal_t *ctx,
|
|
|
|
struct chain_topology *topo,
|
|
|
|
struct channel *channel,
|
2021-10-13 14:15:36 +10:30
|
|
|
const struct bitcoin_outpoint *outpoint,
|
2022-07-25 16:31:09 +09:30
|
|
|
enum watch_result (*cb)(struct channel *,
|
2018-02-21 07:29:09 +10:30
|
|
|
const struct bitcoin_tx *tx,
|
|
|
|
size_t input_num,
|
|
|
|
const struct block *block));
|
2016-04-24 19:39:21 +09:30
|
|
|
|
2023-10-02 09:29:51 +10:30
|
|
|
struct txwatch *find_txwatch_(struct chain_topology *topo,
|
|
|
|
const struct bitcoin_txid *txid,
|
|
|
|
enum watch_result (*cb)(struct lightningd *ld,
|
|
|
|
const struct bitcoin_txid *,
|
|
|
|
const struct bitcoin_tx *,
|
|
|
|
unsigned int depth,
|
|
|
|
void *arg),
|
|
|
|
void *arg);
|
|
|
|
|
|
|
|
#define find_txwatch(topo, txid, cb, arg) \
|
|
|
|
find_txwatch_((topo), (txid), \
|
|
|
|
typesafe_cb_preargs(enum watch_result, void *, \
|
|
|
|
(cb), (arg), \
|
|
|
|
struct lightningd *, \
|
|
|
|
const struct bitcoin_txid *, \
|
|
|
|
const struct bitcoin_tx *, \
|
|
|
|
unsigned int depth), \
|
|
|
|
(arg))
|
2018-01-29 12:51:18 +10:30
|
|
|
|
2017-03-02 22:51:49 +10:30
|
|
|
void txwatch_fire(struct chain_topology *topo,
|
2018-04-10 11:14:50 +02:00
|
|
|
const struct bitcoin_txid *txid,
|
2016-04-24 19:50:35 +09:30
|
|
|
unsigned int depth);
|
2016-04-24 19:48:35 +09:30
|
|
|
|
2018-02-21 16:57:45 +01:00
|
|
|
void txowatch_fire(const struct txowatch *txow,
|
2017-08-23 10:28:44 +09:30
|
|
|
const struct bitcoin_tx *tx, size_t input_num,
|
|
|
|
const struct block *block);
|
2016-04-24 19:48:35 +09:30
|
|
|
|
2017-03-02 22:51:49 +10:30
|
|
|
bool watching_txid(const struct chain_topology *topo,
|
2017-12-18 17:11:52 +10:30
|
|
|
const struct bitcoin_txid *txid);
|
2016-05-04 16:10:37 +09:30
|
|
|
|
2019-06-28 11:28:31 +09:30
|
|
|
/* FIXME: Implement bitcoin_tx_dup() so we tx arg can be TAKEN */
|
|
|
|
void txwatch_inform(const struct chain_topology *topo,
|
|
|
|
const struct bitcoin_txid *txid,
|
|
|
|
const struct bitcoin_tx *tx_may_steal);
|
|
|
|
|
2017-03-02 22:51:49 +10:30
|
|
|
void watch_topology_changed(struct chain_topology *topo);
|
2017-08-29 01:36:01 +09:30
|
|
|
#endif /* LIGHTNING_LIGHTNINGD_WATCH_H */
|