2017-08-28 18:06:01 +02:00
|
|
|
#ifndef LIGHTNING_LIGHTNINGD_BITCOIND_H
|
|
|
|
#define LIGHTNING_LIGHTNINGD_BITCOIND_H
|
2016-01-21 21:11:49 +01:00
|
|
|
#include "config.h"
|
2017-07-10 10:59:15 +02:00
|
|
|
#include <bitcoin/chainparams.h>
|
2018-01-31 22:26:25 +01:00
|
|
|
#include <bitcoin/tx.h>
|
2017-03-02 13:21:49 +01:00
|
|
|
#include <ccan/list/list.h>
|
2016-01-21 21:11:49 +01:00
|
|
|
#include <ccan/short_types/short_types.h>
|
2020-01-07 16:09:59 +01:00
|
|
|
#include <ccan/strmap/strmap.h>
|
2017-03-02 13:21:49 +01:00
|
|
|
#include <ccan/tal/tal.h>
|
2017-09-28 05:39:05 +02:00
|
|
|
#include <ccan/time/time.h>
|
2016-01-21 21:11:49 +01:00
|
|
|
#include <ccan/typesafe_cb/typesafe_cb.h>
|
2016-01-21 21:11:49 +01:00
|
|
|
#include <stdbool.h>
|
2016-01-21 21:11:49 +01:00
|
|
|
|
2017-12-18 07:44:10 +01:00
|
|
|
struct bitcoin_blkid;
|
2018-01-04 12:40:58 +01:00
|
|
|
struct bitcoin_tx_output;
|
|
|
|
struct block;
|
2017-08-28 18:09:01 +02:00
|
|
|
struct lightningd;
|
2016-01-21 21:11:49 +01:00
|
|
|
struct ripemd160;
|
|
|
|
struct bitcoin_tx;
|
2016-04-24 12:10:29 +02:00
|
|
|
struct bitcoin_block;
|
2016-01-21 21:11:49 +01:00
|
|
|
|
2018-09-19 04:45:25 +02:00
|
|
|
enum bitcoind_prio {
|
|
|
|
BITCOIND_LOW_PRIO,
|
|
|
|
BITCOIND_HIGH_PRIO
|
|
|
|
};
|
|
|
|
#define BITCOIND_NUM_PRIO (BITCOIND_HIGH_PRIO+1)
|
|
|
|
|
2017-03-02 13:21:49 +01:00
|
|
|
struct bitcoind {
|
2018-02-24 06:13:34 +01:00
|
|
|
/* eg. "bitcoin-cli" */
|
|
|
|
char *cli;
|
|
|
|
|
2017-03-02 13:21:49 +01:00
|
|
|
/* -datadir arg for bitcoin-cli. */
|
|
|
|
char *datadir;
|
|
|
|
|
|
|
|
/* Where to do logging. */
|
|
|
|
struct log *log;
|
|
|
|
|
2017-11-01 11:20:40 +01:00
|
|
|
/* Main lightningd structure */
|
|
|
|
struct lightningd *ld;
|
|
|
|
|
2019-08-09 04:38:59 +02:00
|
|
|
/* Is bitcoind synced? If not, we retry. */
|
|
|
|
bool synced;
|
|
|
|
|
2018-09-19 04:45:25 +02:00
|
|
|
/* How many high/low prio requests are we running (it's ratelimited) */
|
|
|
|
size_t num_requests[BITCOIND_NUM_PRIO];
|
2017-03-02 13:21:49 +01:00
|
|
|
|
2018-09-19 04:45:25 +02:00
|
|
|
/* Pending requests (high and low prio). */
|
|
|
|
struct list_head pending[BITCOIND_NUM_PRIO];
|
2017-07-10 10:59:15 +02:00
|
|
|
|
2017-09-28 05:39:05 +02:00
|
|
|
/* If non-zero, time we first hit a bitcoind error. */
|
|
|
|
unsigned int error_count;
|
|
|
|
struct timemono first_error_time;
|
|
|
|
|
2017-09-12 06:55:54 +02:00
|
|
|
/* Ignore results, we're shutting down. */
|
|
|
|
bool shutdown;
|
2018-01-30 15:17:58 +01:00
|
|
|
|
2019-06-29 21:12:15 +02:00
|
|
|
/* How long to keep trying to contact bitcoind
|
|
|
|
* before fatally exiting. */
|
|
|
|
u64 retry_timeout;
|
|
|
|
|
2018-01-30 15:17:58 +01:00
|
|
|
/* Passthrough parameters for bitcoin-cli */
|
2018-03-25 13:57:52 +02:00
|
|
|
char *rpcuser, *rpcpass, *rpcconnect, *rpcport;
|
2019-08-06 16:26:42 +02:00
|
|
|
|
|
|
|
struct list_head pending_getfilteredblock;
|
2020-01-07 16:09:59 +01:00
|
|
|
|
|
|
|
/* Map each method to a plugin, so we can have multiple plugins
|
|
|
|
* handling different functionalities. */
|
|
|
|
STRMAP(struct plugin *) pluginsmap;
|
2017-03-02 13:21:49 +01:00
|
|
|
};
|
|
|
|
|
2019-08-05 18:33:08 +02:00
|
|
|
/* A single outpoint in a filtered block */
|
|
|
|
struct filteredblock_outpoint {
|
|
|
|
struct bitcoin_txid txid;
|
|
|
|
u32 outnum;
|
|
|
|
u32 txindex;
|
|
|
|
const u8 *scriptPubKey;
|
2019-08-07 04:02:21 +02:00
|
|
|
struct amount_sat amount;
|
2019-08-05 18:33:08 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/* 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;
|
|
|
|
};
|
|
|
|
|
2017-11-01 11:20:40 +01:00
|
|
|
struct bitcoind *new_bitcoind(const tal_t *ctx,
|
|
|
|
struct lightningd *ld,
|
|
|
|
struct log *log);
|
2017-03-02 13:21:49 +01:00
|
|
|
|
2017-11-21 04:30:29 +01:00
|
|
|
void bitcoind_estimate_fees_(struct bitcoind *bitcoind,
|
|
|
|
const u32 blocks[], const char *estmode[],
|
|
|
|
size_t num_estimates,
|
|
|
|
void (*cb)(struct bitcoind *bitcoind,
|
2017-11-21 04:33:22 +01:00
|
|
|
const u32 satoshi_per_kw[], void *),
|
2017-11-21 04:30:29 +01:00
|
|
|
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 *, \
|
2017-11-21 04:33:22 +01:00
|
|
|
const u32 *), \
|
2017-11-21 04:30:29 +01:00
|
|
|
(arg))
|
2016-04-12 05:37:03 +02:00
|
|
|
|
2017-06-20 15:34:43 +02:00
|
|
|
void bitcoind_sendrawtx_(struct bitcoind *bitcoind,
|
2016-05-04 08:33:10 +02:00
|
|
|
const char *hextx,
|
2017-03-02 13:21:49 +01:00
|
|
|
void (*cb)(struct bitcoind *bitcoind,
|
2020-01-09 12:25:45 +01:00
|
|
|
bool success, const char *msg, void *),
|
2016-05-04 08:33:10 +02:00
|
|
|
void *arg);
|
|
|
|
|
2017-06-20 15:34:43 +02:00
|
|
|
#define bitcoind_sendrawtx(bitcoind_, hextx, cb, arg) \
|
|
|
|
bitcoind_sendrawtx_((bitcoind_), (hextx), \
|
2016-05-04 08:33:10 +02:00
|
|
|
typesafe_cb_preargs(void, void *, \
|
|
|
|
(cb), (arg), \
|
2017-03-02 13:21:49 +01:00
|
|
|
struct bitcoind *, \
|
2020-01-09 12:25:45 +01:00
|
|
|
bool, const char *), \
|
2016-05-04 08:33:10 +02:00
|
|
|
(arg))
|
|
|
|
|
2019-08-05 18:33:08 +02:00
|
|
|
void bitcoind_getfilteredblock_(struct bitcoind *bitcoind, u32 height,
|
|
|
|
void (*cb)(struct bitcoind *bitcoind,
|
2019-08-08 06:24:33 +02:00
|
|
|
const struct filteredblock *fb,
|
2019-08-05 18:33:08 +02:00
|
|
|
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))
|
|
|
|
|
2020-01-08 17:53:31 +01:00
|
|
|
void bitcoind_getchaininfo_(struct bitcoind *bitcoind,
|
|
|
|
const bool first_call,
|
|
|
|
void (*cb)(struct bitcoind *bitcoind,
|
|
|
|
const char *chain,
|
|
|
|
u32 headercount,
|
|
|
|
u32 blockcount,
|
|
|
|
const bool ibd,
|
|
|
|
const bool first_call, void *),
|
|
|
|
void *cb_arg);
|
|
|
|
#define bitcoind_getchaininfo(bitcoind_, first_call_, cb, arg) \
|
|
|
|
bitcoind_getchaininfo_((bitcoind_), (first_call_), \
|
|
|
|
typesafe_cb_preargs(void, void *, \
|
|
|
|
(cb), (arg), \
|
|
|
|
struct bitcoind *, \
|
|
|
|
const char *, u32, u32, \
|
|
|
|
const bool, const bool), \
|
|
|
|
(arg))
|
|
|
|
|
|
|
|
void bitcoind_getrawblockbyheight_(struct bitcoind *bitcoind,
|
|
|
|
u32 height,
|
|
|
|
void (*cb)(struct bitcoind *bitcoind,
|
|
|
|
struct bitcoin_blkid *blkid,
|
|
|
|
struct bitcoin_block *blk,
|
|
|
|
void *arg),
|
|
|
|
void *arg);
|
|
|
|
#define bitcoind_getrawblockbyheight(bitcoind_, height_, cb, arg) \
|
|
|
|
bitcoind_getrawblockbyheight_((bitcoind_), (height_), \
|
|
|
|
typesafe_cb_preargs(void, void *, \
|
|
|
|
(cb), (arg), \
|
|
|
|
struct bitcoind *, \
|
|
|
|
struct bitcoin_blkid *, \
|
|
|
|
struct bitcoin_block *),\
|
|
|
|
(arg))
|
|
|
|
|
2018-01-31 22:26:25 +01:00
|
|
|
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);
|
|
|
|
|
2019-07-27 19:58:27 +02:00
|
|
|
void bitcoind_getclientversion(struct bitcoind *bitcoind);
|
|
|
|
|
2020-01-07 11:59:18 +01:00
|
|
|
void bitcoind_check_commands(struct bitcoind *bitcoind);
|
|
|
|
|
2017-08-28 18:06:01 +02:00
|
|
|
#endif /* LIGHTNING_LIGHTNINGD_BITCOIND_H */
|