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>
|
2020-01-07 16:09:59 +01:00
|
|
|
#include <ccan/strmap/strmap.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;
|
2023-04-07 06:39:53 +02:00
|
|
|
struct feerate_est;
|
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
|
|
|
|
2017-03-02 13:21:49 +01:00
|
|
|
struct bitcoind {
|
|
|
|
/* Where to do logging. */
|
2023-07-16 07:56:52 +02:00
|
|
|
struct logger *log;
|
2017-03-02 13:21:49 +01:00
|
|
|
|
2017-11-01 11:20:40 +01:00
|
|
|
/* Main lightningd structure */
|
|
|
|
struct lightningd *ld;
|
|
|
|
|
2020-01-10 12:12:20 +01:00
|
|
|
/* Is our Bitcoin backend synced? If not, we retry. */
|
2019-08-09 04:38:59 +02:00
|
|
|
bool synced;
|
|
|
|
|
2017-09-12 06:55:54 +02:00
|
|
|
/* Ignore results, we're shutting down. */
|
|
|
|
bool shutdown;
|
2018-01-30 15:17:58 +01:00
|
|
|
|
2021-09-01 06:35:15 +02:00
|
|
|
/* Timer if we're waiting for it to warm up. */
|
|
|
|
struct oneshot *checkchain_timer;
|
|
|
|
|
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 {
|
2021-10-13 05:45:36 +02:00
|
|
|
struct bitcoin_outpoint outpoint;
|
2019-08-05 18:33:08 +02:00
|
|
|
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,
|
2023-07-16 07:56:52 +02:00
|
|
|
struct logger *log);
|
2017-03-02 13:21:49 +01:00
|
|
|
|
2023-04-07 06:39:53 +02:00
|
|
|
void bitcoind_estimate_fees(struct bitcoind *bitcoind,
|
|
|
|
void (*cb)(struct lightningd *ld,
|
|
|
|
u32 feerate_floor,
|
|
|
|
const struct feerate_est *feerates));
|
2016-04-12 05:37:03 +02:00
|
|
|
|
2023-10-24 03:41:30 +02:00
|
|
|
/* If ctx is freed, cb won't be called! */
|
|
|
|
void bitcoind_sendrawtx_(const tal_t *ctx,
|
|
|
|
struct bitcoind *bitcoind,
|
2022-09-12 23:19:11 +02:00
|
|
|
const char *id_prefix TAKES,
|
2016-05-04 08:33:10 +02:00
|
|
|
const char *hextx,
|
2022-09-12 23:19:11 +02:00
|
|
|
bool allowhighfees,
|
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);
|
2023-10-24 03:41:30 +02:00
|
|
|
#define bitcoind_sendrawtx(ctx, bitcoind_, id_prefix, hextx, allowhighfees, cb, arg) \
|
|
|
|
bitcoind_sendrawtx_((ctx), (bitcoind_), (id_prefix), (hextx), \
|
2022-09-12 23:19:11 +02:00
|
|
|
(allowhighfees), \
|
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,
|
2023-04-15 16:53:47 +02:00
|
|
|
const u32 height,
|
2020-01-08 17:53:31 +01:00
|
|
|
void (*cb)(struct bitcoind *bitcoind,
|
|
|
|
const char *chain,
|
|
|
|
u32 headercount,
|
|
|
|
u32 blockcount,
|
|
|
|
const bool ibd,
|
|
|
|
const bool first_call, void *),
|
|
|
|
void *cb_arg);
|
2023-04-15 16:53:47 +02:00
|
|
|
#define bitcoind_getchaininfo(bitcoind_, first_call_, height_, cb, arg) \
|
|
|
|
bitcoind_getchaininfo_((bitcoind_), (first_call_), (height_), \
|
2020-01-08 17:53:31 +01:00
|
|
|
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))
|
|
|
|
|
2020-01-09 16:38:12 +01:00
|
|
|
void bitcoind_getutxout_(struct bitcoind *bitcoind,
|
2021-10-13 05:45:36 +02:00
|
|
|
const struct bitcoin_outpoint *outpoint,
|
2022-07-25 09:00:09 +02:00
|
|
|
void (*cb)(struct bitcoind *,
|
|
|
|
const struct bitcoin_tx_output *,
|
|
|
|
void *),
|
2020-01-09 16:38:12 +01:00
|
|
|
void *arg);
|
2021-10-13 05:45:36 +02:00
|
|
|
#define bitcoind_getutxout(bitcoind_, outpoint_, cb, arg) \
|
|
|
|
bitcoind_getutxout_((bitcoind_), (outpoint_), \
|
2020-01-09 16:38:12 +01:00
|
|
|
typesafe_cb_preargs(void, void *, \
|
|
|
|
(cb), (arg), \
|
|
|
|
struct bitcoind *, \
|
|
|
|
struct bitcoin_tx_output *),\
|
|
|
|
(arg))
|
2018-01-31 22:26:25 +01:00
|
|
|
|
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 */
|