forked from ElementsProject/lightning
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bitcoind.h
209 lines (176 loc) · 5.82 KB
/
bitcoind.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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
#ifndef LIGHTNING_LIGHTNINGD_BITCOIND_H
#define LIGHTNING_LIGHTNINGD_BITCOIND_H
#include "config.h"
#include <bitcoin/chainparams.h>
#include <bitcoin/tx.h>
#include <ccan/list/list.h>
#include <ccan/short_types/short_types.h>
#include <ccan/tal/tal.h>
#include <ccan/time/time.h>
#include <ccan/typesafe_cb/typesafe_cb.h>
#include <stdbool.h>
struct bitcoin_blkid;
struct bitcoin_tx_output;
struct block;
struct lightningd;
struct ripemd160;
struct bitcoin_tx;
struct bitcoin_block;
enum bitcoind_mode {
BITCOIND_MAINNET = 1,
BITCOIND_TESTNET,
BITCOIND_REGTEST
};
enum bitcoind_prio {
BITCOIND_LOW_PRIO,
BITCOIND_HIGH_PRIO
};
#define BITCOIND_NUM_PRIO (BITCOIND_HIGH_PRIO+1)
struct bitcoind {
/* eg. "bitcoin-cli" */
char *cli;
/* -datadir arg for bitcoin-cli. */
char *datadir;
/* Where to do logging. */
struct log *log;
/* Main lightningd structure */
struct lightningd *ld;
/* Is bitcoind synced? If not, we retry. */
bool synced;
/* How many high/low prio requests are we running (it's ratelimited) */
size_t num_requests[BITCOIND_NUM_PRIO];
/* Pending requests (high and low prio). */
struct list_head pending[BITCOIND_NUM_PRIO];
/* What network are we on? */
const struct chainparams *chainparams;
/* If non-zero, time we first hit a bitcoind error. */
unsigned int error_count;
struct timemono first_error_time;
/* Ignore results, we're shutting down. */
bool shutdown;
/* How long to keep trying to contact bitcoind
* before fatally exiting. */
u64 retry_timeout;
/* Passthrough parameters for bitcoin-cli */
char *rpcuser, *rpcpass, *rpcconnect, *rpcport;
struct list_head pending_getfilteredblock;
};
/* A single outpoint in a filtered block */
struct filteredblock_outpoint {
struct bitcoin_txid txid;
u32 outnum;
u32 txindex;
const u8 *scriptPubKey;
struct amount_sat amount;
};
/* A struct representing a block with most of the parts filtered out. */
struct filteredblock {
struct bitcoin_blkid id;
u32 height;
struct bitcoin_blkid prev_hash;
struct filteredblock_outpoint **outpoints;
};
struct bitcoind *new_bitcoind(const tal_t *ctx,
struct lightningd *ld,
struct log *log);
void wait_for_bitcoind(struct bitcoind *bitcoind);
void bitcoind_estimate_fees_(struct bitcoind *bitcoind,
const u32 blocks[], const char *estmode[],
size_t num_estimates,
void (*cb)(struct bitcoind *bitcoind,
const u32 satoshi_per_kw[], void *),
void *arg);
#define bitcoind_estimate_fees(bitcoind_, blocks, estmode, num, cb, arg) \
bitcoind_estimate_fees_((bitcoind_), (blocks), (estmode), (num), \
typesafe_cb_preargs(void, void *, \
(cb), (arg), \
struct bitcoind *, \
const u32 *), \
(arg))
void bitcoind_sendrawtx_(struct bitcoind *bitcoind,
const char *hextx,
void (*cb)(struct bitcoind *bitcoind,
int exitstatus, const char *msg, void *),
void *arg);
#define bitcoind_sendrawtx(bitcoind_, hextx, cb, arg) \
bitcoind_sendrawtx_((bitcoind_), (hextx), \
typesafe_cb_preargs(void, void *, \
(cb), (arg), \
struct bitcoind *, \
int, const char *), \
(arg))
void bitcoind_getblockcount_(struct bitcoind *bitcoind,
void (*cb)(struct bitcoind *bitcoind,
u32 blockcount,
void *arg),
void *arg);
#define bitcoind_getblockcount(bitcoind_, cb, arg) \
bitcoind_getblockcount_((bitcoind_), \
typesafe_cb_preargs(void, void *, \
(cb), (arg), \
struct bitcoind *, \
u32 blockcount), \
(arg))
/* blkid is NULL if call fails. */
void bitcoind_getblockhash_(struct bitcoind *bitcoind,
u32 height,
void (*cb)(struct bitcoind *bitcoind,
const struct bitcoin_blkid *blkid,
void *arg),
void *arg);
#define bitcoind_getblockhash(bitcoind_, height, cb, arg) \
bitcoind_getblockhash_((bitcoind_), \
(height), \
typesafe_cb_preargs(void, void *, \
(cb), (arg), \
struct bitcoind *, \
const struct bitcoin_blkid *), \
(arg))
void bitcoind_getfilteredblock_(struct bitcoind *bitcoind, u32 height,
void (*cb)(struct bitcoind *bitcoind,
const struct filteredblock *fb,
void *arg),
void *arg);
#define bitcoind_getfilteredblock(bitcoind_, height, cb, arg) \
bitcoind_getfilteredblock_((bitcoind_), \
(height), \
typesafe_cb_preargs(void, void *, \
(cb), (arg), \
struct bitcoind *, \
const struct filteredblock *), \
(arg))
void bitcoind_getrawblock_(struct bitcoind *bitcoind,
const struct bitcoin_blkid *blockid,
void (*cb)(struct bitcoind *bitcoind,
struct bitcoin_block *blk,
void *arg),
void *arg);
#define bitcoind_getrawblock(bitcoind_, blkid, cb, arg) \
bitcoind_getrawblock_((bitcoind_), (blkid), \
typesafe_cb_preargs(void, void *, \
(cb), (arg), \
struct bitcoind *, \
struct bitcoin_block *), \
(arg))
void bitcoind_getoutput_(struct bitcoind *bitcoind,
unsigned int blocknum, unsigned int txnum,
unsigned int outnum,
void (*cb)(struct bitcoind *bitcoind,
const struct bitcoin_tx_output *output,
void *arg),
void *arg);
#define bitcoind_getoutput(bitcoind_, blocknum, txnum, outnum, cb, arg) \
bitcoind_getoutput_((bitcoind_), (blocknum), (txnum), (outnum), \
typesafe_cb_preargs(void, void *, \
(cb), (arg), \
struct bitcoind *, \
const struct bitcoin_tx_output*), \
(arg))
void bitcoind_gettxout(struct bitcoind *bitcoind,
const struct bitcoin_txid *txid, const u32 outnum,
void (*cb)(struct bitcoind *bitcoind,
const struct bitcoin_tx_output *txout,
void *arg),
void *arg);
void bitcoind_getclientversion(struct bitcoind *bitcoind);
#endif /* LIGHTNING_LIGHTNINGD_BITCOIND_H */