forked from ElementsProject/lightning
-
Notifications
You must be signed in to change notification settings - Fork 0
/
watch.h
113 lines (93 loc) · 3.18 KB
/
watch.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#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;
struct txwatch_output {
struct sha256_double txid;
unsigned int index;
};
/* Watching an output */
struct txowatch {
/* Peer who owns us. */
struct peer *peer;
/* Output to watch. */
struct txwatch_output out;
/* A new tx. */
void (*cb)(struct peer *peer,
const struct bitcoin_tx *tx,
void *cbdata);
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 {
struct lightningd_state *dstate;
/* Peer who owns us. */
struct peer *peer;
/* Transaction to watch. */
struct sha256_double txid;
int depth;
/* A new depth (-1 if conflicted), blkhash valid if > 0 */
void (*cb)(struct peer *peer, int depth,
const struct sha256_double *blkhash,
void *cbdata);
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);
void add_anchor_watch_(const tal_t *ctx,
struct peer *peer,
const struct sha256_double *txid,
unsigned int out,
void (*anchor_cb)(struct peer *peer, int depth,
const struct sha256_double *blkhash,
void *),
void (*spend_cb)(struct peer *peer,
const struct bitcoin_tx *, void *),
void *cbdata);
#define add_anchor_watch(ctx, peer, txid, out, anchor_cb, spend_cb, cbdata) \
add_anchor_watch_((ctx), (peer), (txid), (out), \
typesafe_cb_preargs(void, void *, \
(anchor_cb), (cbdata), \
struct peer *, \
int depth, \
const struct sha256_double *), \
typesafe_cb_preargs(void, void *, \
(spend_cb), (cbdata), \
struct peer *, \
const struct bitcoin_tx *), \
(cbdata))
struct txwatch *add_commit_tx_watch_(const tal_t *ctx,
struct peer *peer,
const struct sha256_double *txid,
void (*cb)(struct peer *peer, int depth,
const struct sha256_double *blkhash,
void *),
void *cbdata);
#define add_commit_tx_watch(ctx, peer, txid, cb, cbdata) \
add_commit_tx_watch_((ctx), (peer), (txid), \
typesafe_cb_preargs(void, void *, \
(cb), (cbdata), \
struct peer *, \
int, \
const struct sha256_double *), \
(cbdata))
void add_close_tx_watch(const tal_t *ctx,
struct peer *peer,
const struct bitcoin_tx *tx,
void (*cb)(struct peer *peer, int depth));
void setup_watch_timer(struct lightningd_state *dstate);
#endif /* LIGHTNING_DAEMON_WATCH_H */