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/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 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
|
|
|
|
};
|
|
|
|
|
2016-01-22 06:41:49 +10:30
|
|
|
struct txwatch_output {
|
2017-12-18 17:11:52 +10:30
|
|
|
struct bitcoin_txid txid;
|
2016-01-22 06:41:49 +10:30
|
|
|
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 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);
|
|
|
|
|
|
|
|
|
2018-02-21 07:29:09 +10:30
|
|
|
struct txwatch *watch_txid(const tal_t *ctx,
|
|
|
|
struct chain_topology *topo,
|
|
|
|
struct channel *channel,
|
|
|
|
const struct bitcoin_txid *txid,
|
2018-08-13 12:35:33 +09:30
|
|
|
enum watch_result (*cb)(struct lightningd *ld,
|
|
|
|
struct channel *channel,
|
|
|
|
const struct bitcoin_txid *,
|
2019-06-28 11:28:31 +09:30
|
|
|
const struct bitcoin_tx *,
|
2018-02-21 07:29:09 +10:30
|
|
|
unsigned int depth));
|
2016-04-24 19:39:21 +09:30
|
|
|
|
2018-02-21 07:29:09 +10:30
|
|
|
struct txwatch *watch_tx(const tal_t *ctx,
|
|
|
|
struct chain_topology *topo,
|
|
|
|
struct channel *channel,
|
|
|
|
const struct bitcoin_tx *tx,
|
2018-08-13 12:35:33 +09:30
|
|
|
enum watch_result (*cb)(struct lightningd *ld,
|
|
|
|
struct channel *channel,
|
|
|
|
const struct bitcoin_txid *,
|
2019-06-28 11:28:31 +09:30
|
|
|
const struct bitcoin_tx *,
|
2018-08-13 12:35:33 +09:30
|
|
|
unsigned int depth));
|
2018-02-21 07:29:09 +10:30
|
|
|
|
|
|
|
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 19:39:21 +09:30
|
|
|
|
2018-01-29 12:51:18 +10:30
|
|
|
struct txwatch *find_txwatch(struct chain_topology *topo,
|
|
|
|
const struct bitcoin_txid *txid,
|
2018-02-12 20:43:04 +10:30
|
|
|
const struct channel *channel);
|
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 */
|