2017-08-28 18:06:01 +02:00
|
|
|
#ifndef LIGHTNING_LIGHTNINGD_WATCH_H
|
|
|
|
#define LIGHTNING_LIGHTNINGD_WATCH_H
|
2016-01-21 21:11:49 +01:00
|
|
|
#include "config.h"
|
2017-12-18 07:41:52 +01:00
|
|
|
#include <bitcoin/tx.h>
|
2016-01-21 21:11:49 +01:00
|
|
|
#include <ccan/crypto/ripemd160/ripemd160.h>
|
|
|
|
#include <ccan/htable/htable_type.h>
|
|
|
|
#include <ccan/list/list.h>
|
|
|
|
#include <ccan/short_types/short_types.h>
|
|
|
|
#include <ccan/typesafe_cb/typesafe_cb.h>
|
|
|
|
|
|
|
|
struct bitcoin_tx;
|
2017-08-23 02:58:44 +02:00
|
|
|
struct block;
|
2018-02-20 21:59:09 +01:00
|
|
|
struct channel;
|
|
|
|
struct chain_topology;
|
|
|
|
struct txowatch;
|
|
|
|
struct txwatch;
|
2016-01-21 21:11:49 +01:00
|
|
|
|
2016-06-30 01:40:11 +02:00
|
|
|
enum watch_result {
|
|
|
|
DELETE_WATCH = -1,
|
|
|
|
KEEP_WATCHING = -2
|
|
|
|
};
|
|
|
|
|
2016-01-21 21:11:49 +01:00
|
|
|
struct txwatch_output {
|
2017-12-18 07:41:52 +01:00
|
|
|
struct bitcoin_txid txid;
|
2016-01-21 21:11:49 +01:00
|
|
|
unsigned int index;
|
|
|
|
};
|
|
|
|
|
|
|
|
const struct txwatch_output *txowatch_keyof(const struct txowatch *w);
|
|
|
|
size_t txo_hash(const struct txwatch_output *out);
|
|
|
|
bool txowatch_eq(const struct txowatch *w, const struct txwatch_output *out);
|
|
|
|
|
|
|
|
HTABLE_DEFINE_TYPE(struct txowatch, txowatch_keyof, txo_hash, txowatch_eq,
|
|
|
|
txowatch_hash);
|
|
|
|
|
2017-12-18 07:41:52 +01:00
|
|
|
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-21 21:11:49 +01:00
|
|
|
HTABLE_DEFINE_TYPE(struct txwatch, txwatch_keyof, txid_hash, txwatch_eq,
|
|
|
|
txwatch_hash);
|
|
|
|
|
|
|
|
|
2018-02-20 21:59:09 +01:00
|
|
|
struct txwatch *watch_txid(const tal_t *ctx,
|
|
|
|
struct chain_topology *topo,
|
|
|
|
struct channel *channel,
|
|
|
|
const struct bitcoin_txid *txid,
|
|
|
|
enum watch_result (*cb)(struct channel *channel,
|
2017-08-18 06:43:53 +02:00
|
|
|
const struct bitcoin_tx *,
|
2018-02-20 21:59:09 +01:00
|
|
|
unsigned int depth));
|
2016-04-24 12:09:21 +02:00
|
|
|
|
2018-02-20 21:59:09 +01:00
|
|
|
struct txwatch *watch_tx(const tal_t *ctx,
|
|
|
|
struct chain_topology *topo,
|
|
|
|
struct channel *channel,
|
|
|
|
const struct bitcoin_tx *tx,
|
|
|
|
enum watch_result (*cb)(struct channel *channel,
|
2017-08-18 06:43:53 +02:00
|
|
|
const struct bitcoin_tx *,
|
2018-02-20 21:59:09 +01:00
|
|
|
unsigned int depth));
|
|
|
|
|
|
|
|
struct txowatch *watch_txo(const tal_t *ctx,
|
|
|
|
struct chain_topology *topo,
|
|
|
|
struct channel *channel,
|
|
|
|
const struct bitcoin_txid *txid,
|
|
|
|
unsigned int output,
|
|
|
|
enum watch_result (*cb)(struct channel *channel,
|
|
|
|
const struct bitcoin_tx *tx,
|
|
|
|
size_t input_num,
|
|
|
|
const struct block *block));
|
2016-04-24 12:09:21 +02:00
|
|
|
|
2018-01-29 03:21:18 +01:00
|
|
|
struct txwatch *find_txwatch(struct chain_topology *topo,
|
|
|
|
const struct bitcoin_txid *txid,
|
2018-02-12 11:13:04 +01:00
|
|
|
const struct channel *channel);
|
2018-01-29 03:21:18 +01:00
|
|
|
|
2017-03-02 13:21:49 +01:00
|
|
|
void txwatch_fire(struct chain_topology *topo,
|
2017-08-18 06:43:53 +02:00
|
|
|
const struct bitcoin_tx *tx,
|
2016-04-24 12:20:35 +02:00
|
|
|
unsigned int depth);
|
2016-04-24 12:18:35 +02:00
|
|
|
|
2018-02-21 16:57:45 +01:00
|
|
|
void txowatch_fire(const struct txowatch *txow,
|
2017-08-23 02:58:44 +02:00
|
|
|
const struct bitcoin_tx *tx, size_t input_num,
|
|
|
|
const struct block *block);
|
2016-04-24 12:18:35 +02:00
|
|
|
|
2017-03-02 13:21:49 +01:00
|
|
|
bool watching_txid(const struct chain_topology *topo,
|
2017-12-18 07:41:52 +01:00
|
|
|
const struct bitcoin_txid *txid);
|
2016-05-04 08:40:37 +02:00
|
|
|
|
2017-03-02 13:21:49 +01:00
|
|
|
void watch_topology_changed(struct chain_topology *topo);
|
2017-08-28 18:06:01 +02:00
|
|
|
#endif /* LIGHTNING_LIGHTNINGD_WATCH_H */
|