2016-01-21 21:11:49 +01:00
|
|
|
#ifndef LIGHTNING_DAEMON_WATCH_H
|
|
|
|
#define LIGHTNING_DAEMON_WATCH_H
|
|
|
|
#include "config.h"
|
|
|
|
#include "bitcoin/shadouble.h"
|
|
|
|
#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;
|
|
|
|
struct lightningd_state;
|
|
|
|
|
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 {
|
|
|
|
struct sha256_double txid;
|
|
|
|
unsigned int index;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Watching an output */
|
|
|
|
struct txowatch {
|
2017-03-02 13:21:49 +01:00
|
|
|
struct chain_topology *topo;
|
2017-03-02 13:21:49 +01:00
|
|
|
|
2016-01-21 21:11:49 +01:00
|
|
|
/* Peer who owns us. */
|
|
|
|
struct peer *peer;
|
2016-11-11 00:02:04 +01:00
|
|
|
|
2016-01-21 21:11:49 +01:00
|
|
|
/* Output to watch. */
|
|
|
|
struct txwatch_output out;
|
|
|
|
|
|
|
|
/* A new tx. */
|
2016-06-30 01:40:11 +02:00
|
|
|
enum watch_result (*cb)(struct peer *peer,
|
|
|
|
const struct bitcoin_tx *tx,
|
|
|
|
size_t input_num,
|
|
|
|
void *cbdata);
|
2016-01-21 21:11:49 +01:00
|
|
|
|
|
|
|
void *cbdata;
|
|
|
|
};
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
struct txwatch {
|
2017-03-02 13:21:49 +01:00
|
|
|
struct chain_topology *topo;
|
2016-01-21 21:11:49 +01:00
|
|
|
|
|
|
|
/* Peer who owns us. */
|
|
|
|
struct peer *peer;
|
2016-05-04 08:40:37 +02:00
|
|
|
|
2016-01-21 21:11:49 +01:00
|
|
|
/* Transaction to watch. */
|
|
|
|
struct sha256_double txid;
|
2016-05-04 08:40:39 +02:00
|
|
|
unsigned int depth;
|
2016-01-21 21:11:49 +01:00
|
|
|
|
2016-05-04 08:40:39 +02:00
|
|
|
/* A new depth (0 if kicked out, otherwise 1 = tip, etc.) */
|
2017-08-18 06:43:53 +02:00
|
|
|
enum watch_result (*cb)(struct peer *peer,
|
|
|
|
const struct bitcoin_tx *tx,
|
|
|
|
unsigned int depth,
|
2016-06-30 01:40:11 +02:00
|
|
|
void *cbdata);
|
2017-08-18 06:43:53 +02:00
|
|
|
|
2016-01-21 21:11:49 +01:00
|
|
|
void *cbdata;
|
|
|
|
};
|
|
|
|
|
|
|
|
const struct sha256_double *txwatch_keyof(const struct txwatch *w);
|
|
|
|
size_t txid_hash(const struct sha256_double *txid);
|
|
|
|
bool txwatch_eq(const struct txwatch *w, const struct sha256_double *txid);
|
|
|
|
HTABLE_DEFINE_TYPE(struct txwatch, txwatch_keyof, txid_hash, txwatch_eq,
|
|
|
|
txwatch_hash);
|
|
|
|
|
|
|
|
|
2016-04-24 12:09:21 +02:00
|
|
|
struct txwatch *watch_txid_(const tal_t *ctx,
|
2017-03-02 13:21:49 +01:00
|
|
|
struct chain_topology *topo,
|
2016-04-24 12:09:21 +02:00
|
|
|
struct peer *peer,
|
|
|
|
const struct sha256_double *txid,
|
2016-06-30 01:40:11 +02:00
|
|
|
enum watch_result (*cb)(struct peer *peer,
|
2017-08-18 06:43:53 +02:00
|
|
|
const struct bitcoin_tx *,
|
2016-06-30 01:40:11 +02:00
|
|
|
unsigned int depth,
|
|
|
|
void *),
|
2016-04-24 12:09:21 +02:00
|
|
|
void *cbdata);
|
|
|
|
|
2017-03-07 01:57:09 +01:00
|
|
|
#define watch_txid(ctx, topo, peer_, txid, cb, cbdata) \
|
|
|
|
watch_txid_((ctx), (topo), (peer_), (txid), \
|
2016-06-30 01:40:11 +02:00
|
|
|
typesafe_cb_preargs(enum watch_result, void *, \
|
2016-04-24 12:09:21 +02:00
|
|
|
(cb), (cbdata), \
|
|
|
|
struct peer *, \
|
2017-08-18 06:43:53 +02:00
|
|
|
const struct bitcoin_tx *, \
|
|
|
|
unsigned int depth), \
|
2016-04-24 12:09:21 +02:00
|
|
|
(cbdata))
|
|
|
|
|
|
|
|
struct txwatch *watch_tx_(const tal_t *ctx,
|
2017-03-02 13:21:49 +01:00
|
|
|
struct chain_topology *topo,
|
2016-04-24 12:09:21 +02:00
|
|
|
struct peer *peer,
|
|
|
|
const struct bitcoin_tx *tx,
|
2016-06-30 01:40:11 +02:00
|
|
|
enum watch_result (*cb)(struct peer *peer,
|
2017-08-18 06:43:53 +02:00
|
|
|
const struct bitcoin_tx *,
|
2016-06-30 01:40:11 +02:00
|
|
|
unsigned int depth,
|
|
|
|
void *),
|
2016-04-24 12:09:21 +02:00
|
|
|
void *cbdata);
|
|
|
|
|
2017-03-07 01:57:09 +01:00
|
|
|
#define watch_tx(ctx, topo, peer_, tx, cb, cbdata) \
|
|
|
|
watch_tx_((ctx), (topo), (peer_), (tx), \
|
2016-06-30 01:40:11 +02:00
|
|
|
typesafe_cb_preargs(enum watch_result, void *, \
|
2016-04-24 12:09:21 +02:00
|
|
|
(cb), (cbdata), \
|
|
|
|
struct peer *, \
|
2017-08-18 06:43:53 +02:00
|
|
|
const struct bitcoin_tx *, \
|
|
|
|
unsigned int depth), \
|
2016-04-24 12:09:21 +02:00
|
|
|
(cbdata))
|
|
|
|
|
|
|
|
struct txowatch *watch_txo_(const tal_t *ctx,
|
2017-03-02 13:21:49 +01:00
|
|
|
struct chain_topology *topo,
|
2016-04-24 12:09:21 +02:00
|
|
|
struct peer *peer,
|
|
|
|
const struct sha256_double *txid,
|
|
|
|
unsigned int output,
|
2016-06-30 01:40:11 +02:00
|
|
|
enum watch_result (*cb)(struct peer *peer,
|
|
|
|
const struct bitcoin_tx *tx,
|
|
|
|
size_t input_num,
|
|
|
|
void *),
|
2016-04-24 12:09:21 +02:00
|
|
|
void *cbdata);
|
|
|
|
|
2017-03-07 01:57:09 +01:00
|
|
|
#define watch_txo(ctx, topo, peer_, txid, outnum, cb, cbdata) \
|
|
|
|
watch_txo_((ctx), (topo), (peer_), (txid), (outnum), \
|
2016-06-30 01:40:11 +02:00
|
|
|
typesafe_cb_preargs(enum watch_result, void *, \
|
2016-04-24 12:09:21 +02:00
|
|
|
(cb), (cbdata), \
|
|
|
|
struct peer *, \
|
2016-05-03 03:30:20 +02:00
|
|
|
const struct bitcoin_tx *, \
|
|
|
|
size_t), \
|
2016-04-24 12:09:21 +02:00
|
|
|
(cbdata))
|
|
|
|
|
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
|
|
|
|
2017-03-02 13:21:49 +01:00
|
|
|
void txowatch_fire(struct chain_topology *topo,
|
2016-04-24 12:18:35 +02:00
|
|
|
const struct txowatch *txow,
|
2016-05-03 03:30:20 +02:00
|
|
|
const struct bitcoin_tx *tx, size_t input_num);
|
2016-04-24 12:18:35 +02:00
|
|
|
|
2017-03-02 13:21:49 +01:00
|
|
|
bool watching_txid(const struct chain_topology *topo,
|
2016-05-04 08:40:37 +02:00
|
|
|
const struct sha256_double *txid);
|
|
|
|
|
2017-03-02 13:21:49 +01:00
|
|
|
void watch_topology_changed(struct chain_topology *topo);
|
2016-01-21 21:11:49 +01:00
|
|
|
#endif /* LIGHTNING_DAEMON_WATCH_H */
|