forked from ElementsProject/lightning
-
Notifications
You must be signed in to change notification settings - Fork 0
/
watch.h
150 lines (123 loc) · 4.09 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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#ifndef LIGHTNING_LIGHTNINGD_WATCH_H
#define LIGHTNING_LIGHTNINGD_WATCH_H
#include "config.h"
#include <bitcoin/tx.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 block;
enum watch_result {
DELETE_WATCH = -1,
KEEP_WATCHING = -2
};
struct txwatch_output {
struct bitcoin_txid txid;
unsigned int index;
};
/* Watching an output */
struct txowatch {
struct chain_topology *topo;
/* Peer who owns us. */
struct peer *peer;
/* Output to watch. */
struct txwatch_output out;
/* A new tx. */
enum watch_result (*cb)(struct peer *peer,
const struct bitcoin_tx *tx,
size_t input_num,
const struct block *block,
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 chain_topology *topo;
/* Peer who owns us. */
struct peer *peer;
/* Transaction to watch. */
struct bitcoin_txid txid;
unsigned int depth;
/* A new depth (0 if kicked out, otherwise 1 = tip, etc.) */
enum watch_result (*cb)(struct peer *peer,
const struct bitcoin_tx *tx,
unsigned int depth,
void *cbdata);
void *cbdata;
};
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);
HTABLE_DEFINE_TYPE(struct txwatch, txwatch_keyof, txid_hash, txwatch_eq,
txwatch_hash);
struct txwatch *watch_txid_(const tal_t *ctx,
struct chain_topology *topo,
struct peer *peer,
const struct bitcoin_txid *txid,
enum watch_result (*cb)(struct peer *peer,
const struct bitcoin_tx *,
unsigned int depth,
void *),
void *cbdata);
#define watch_txid(ctx, topo, peer_, txid, cb, cbdata) \
watch_txid_((ctx), (topo), (peer_), (txid), \
typesafe_cb_preargs(enum watch_result, void *, \
(cb), (cbdata), \
struct peer *, \
const struct bitcoin_tx *, \
unsigned int depth), \
(cbdata))
struct txwatch *watch_tx_(const tal_t *ctx,
struct chain_topology *topo,
struct peer *peer,
const struct bitcoin_tx *tx,
enum watch_result (*cb)(struct peer *peer,
const struct bitcoin_tx *,
unsigned int depth,
void *),
void *cbdata);
#define watch_tx(ctx, topo, peer_, tx, cb, cbdata) \
watch_tx_((ctx), (topo), (peer_), (tx), \
typesafe_cb_preargs(enum watch_result, void *, \
(cb), (cbdata), \
struct peer *, \
const struct bitcoin_tx *, \
unsigned int depth), \
(cbdata))
struct txowatch *watch_txo_(const tal_t *ctx,
struct chain_topology *topo,
struct peer *peer,
const struct bitcoin_txid *txid,
unsigned int output,
enum watch_result (*cb)(struct peer *peer,
const struct bitcoin_tx *tx,
size_t input_num,
const struct block *block,
void *),
void *cbdata);
#define watch_txo(ctx, topo, peer_, txid, outnum, cb, cbdata) \
watch_txo_((ctx), (topo), (peer_), (txid), (outnum), \
typesafe_cb_preargs(enum watch_result, void *, \
(cb), (cbdata), \
struct peer *, \
const struct bitcoin_tx *, \
size_t, \
const struct block *block), \
(cbdata))
void txwatch_fire(struct chain_topology *topo,
const struct bitcoin_tx *tx,
unsigned int depth);
void txowatch_fire(struct chain_topology *topo,
const struct txowatch *txow,
const struct bitcoin_tx *tx, size_t input_num,
const struct block *block);
bool watching_txid(const struct chain_topology *topo,
const struct bitcoin_txid *txid);
void watch_topology_changed(struct chain_topology *topo);
#endif /* LIGHTNING_LIGHTNINGD_WATCH_H */