mirror of
https://github.com/aljazceru/lightning.git
synced 2026-01-08 16:44:22 +01:00
lightningd/bitcoind: remove all bitcoin-cli specific code
Changelog-Added: pluggable backends for Bitcoin data queries, default still bitcoind (using bitcoin-cli).
This commit is contained in:
@@ -1,4 +1,8 @@
|
||||
/* Code for talking to bitcoind. We use bitcoin-cli. */
|
||||
/* Code for talking to bitcoind. We use a plugin as the Bitcoin backend.
|
||||
* The default one shipped with C-lightning is a plugin which talks to bitcoind
|
||||
* by using bitcoin-cli, but the interface we use to gather Bitcoin data is
|
||||
* standardized and you can use another plugin as the Bitcoin backend, or
|
||||
* even make your own! */
|
||||
#include "bitcoin/base58.h"
|
||||
#include "bitcoin/block.h"
|
||||
#include "bitcoin/feerate.h"
|
||||
@@ -739,8 +743,6 @@ void bitcoind_getfilteredblock_(struct bitcoind *bitcoind, u32 height,
|
||||
static void destroy_bitcoind(struct bitcoind *bitcoind)
|
||||
{
|
||||
strmap_clear(&bitcoind->pluginsmap);
|
||||
/* Suppresses the callbacks from bcli_finished as we free conns. */
|
||||
bitcoind->shutdown = true;
|
||||
}
|
||||
|
||||
struct bitcoind *new_bitcoind(const tal_t *ctx,
|
||||
@@ -750,22 +752,9 @@ struct bitcoind *new_bitcoind(const tal_t *ctx,
|
||||
struct bitcoind *bitcoind = tal(ctx, struct bitcoind);
|
||||
|
||||
strmap_init(&bitcoind->pluginsmap);
|
||||
bitcoind->cli = NULL;
|
||||
bitcoind->datadir = NULL;
|
||||
bitcoind->ld = ld;
|
||||
bitcoind->log = log;
|
||||
for (size_t i = 0; i < BITCOIND_NUM_PRIO; i++) {
|
||||
bitcoind->num_requests[i] = 0;
|
||||
list_head_init(&bitcoind->pending[i]);
|
||||
}
|
||||
list_head_init(&bitcoind->pending_getfilteredblock);
|
||||
bitcoind->shutdown = false;
|
||||
bitcoind->error_count = 0;
|
||||
bitcoind->retry_timeout = 60;
|
||||
bitcoind->rpcuser = NULL;
|
||||
bitcoind->rpcpass = NULL;
|
||||
bitcoind->rpcconnect = NULL;
|
||||
bitcoind->rpcport = NULL;
|
||||
tal_add_destructor(bitcoind, destroy_bitcoind);
|
||||
bitcoind->synced = false;
|
||||
|
||||
|
||||
@@ -19,48 +19,19 @@ struct ripemd160;
|
||||
struct bitcoin_tx;
|
||||
struct bitcoin_block;
|
||||
|
||||
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. */
|
||||
/* Is our Bitcoin backend 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];
|
||||
|
||||
/* 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;
|
||||
|
||||
/* Map each method to a plugin, so we can have multiple plugins
|
||||
|
||||
@@ -789,35 +789,11 @@ static void register_opts(struct lightningd *ld)
|
||||
|
||||
opt_register_noarg("--help|-h", opt_lightningd_usage, ld,
|
||||
"Print this message.");
|
||||
opt_register_arg("--bitcoin-datadir", opt_set_talstr, NULL,
|
||||
&ld->topology->bitcoind->datadir,
|
||||
"-datadir arg for bitcoin-cli");
|
||||
opt_register_arg("--rgb", opt_set_rgb, NULL, ld,
|
||||
"RRGGBB hex color for node");
|
||||
opt_register_arg("--alias", opt_set_alias, NULL, ld,
|
||||
"Up to 32-byte alias for node");
|
||||
|
||||
opt_register_arg("--bitcoin-cli", opt_set_talstr, NULL,
|
||||
&ld->topology->bitcoind->cli,
|
||||
"bitcoin-cli pathname");
|
||||
opt_register_arg("--bitcoin-rpcuser", opt_set_talstr, NULL,
|
||||
&ld->topology->bitcoind->rpcuser,
|
||||
"bitcoind RPC username");
|
||||
opt_register_arg("--bitcoin-rpcpassword", opt_set_talstr, NULL,
|
||||
&ld->topology->bitcoind->rpcpass,
|
||||
"bitcoind RPC password");
|
||||
opt_register_arg("--bitcoin-rpcconnect", opt_set_talstr, NULL,
|
||||
&ld->topology->bitcoind->rpcconnect,
|
||||
"bitcoind RPC host to connect to");
|
||||
opt_register_arg("--bitcoin-rpcport", opt_set_talstr, NULL,
|
||||
&ld->topology->bitcoind->rpcport,
|
||||
"bitcoind RPC port");
|
||||
opt_register_arg("--bitcoin-retry-timeout",
|
||||
opt_set_u64, opt_show_u64,
|
||||
&ld->topology->bitcoind->retry_timeout,
|
||||
"how long to keep trying to contact bitcoind "
|
||||
"before fatally exiting");
|
||||
|
||||
opt_register_arg("--pid-file=<file>", opt_set_talstr, opt_show_charp,
|
||||
&ld->pidfile,
|
||||
"Specify pid file");
|
||||
|
||||
Reference in New Issue
Block a user