Browse Source

bcli cleanups

Correct some comments wrt estimatefees, add a constructor for bitcoind

Signed-off-by: Antoine Poinsot <darosior@protonmail.com>
nifty/pset-pre
Antoine Poinsot 5 years ago
committed by Rusty Russell
parent
commit
d67743d511
  1. 32
      plugins/bcli.c

32
plugins/bcli.c

@ -584,7 +584,7 @@ static struct command_result *estimatefees_third_step(struct bitcoin_cli *bcli)
struct estimatefees_stash *stash = bcli->stash; struct estimatefees_stash *stash = bcli->stash;
const char **params = tal_arr(bcli->cmd, const char *, 2); const char **params = tal_arr(bcli->cmd, const char *, 2);
/* If we cannot estimatefees, no need to continue bothering bitcoind. */ /* If we cannot estimate fees, no need to continue bothering bitcoind. */
if (*bcli->exitstatus != 0) if (*bcli->exitstatus != 0)
return estimatefees_null_response(bcli); return estimatefees_null_response(bcli);
@ -607,7 +607,7 @@ static struct command_result *estimatefees_second_step(struct bitcoin_cli *bcli)
struct estimatefees_stash *stash = bcli->stash; struct estimatefees_stash *stash = bcli->stash;
const char **params = tal_arr(bcli->cmd, const char *, 2); const char **params = tal_arr(bcli->cmd, const char *, 2);
/* If we cannot estimatefees, no need to continue bothering bitcoind. */ /* If we cannot estimate fees, no need to continue bothering bitcoind. */
if (*bcli->exitstatus != 0) if (*bcli->exitstatus != 0)
return estimatefees_null_response(bcli); return estimatefees_null_response(bcli);
@ -754,13 +754,13 @@ static struct command_result *getchaininfo(struct command *cmd,
return command_still_pending(cmd); return command_still_pending(cmd);
} }
/* Get the current feerates. We us an urgent feerate for unilateral_close and max, /* Get the current feerates. We use an urgent feerate for unilateral_close and max,
* a slightly less urgent feerate for htlc_resolution and penalty transactions, * a slightly less urgent feerate for htlc_resolution and penalty transactions,
* a slow feerate for min, and a normal one for all others. * a slow feerate for min, and a normal one for all others.
* *
* Calls `estimatesmartfee` with targets 2/CONSERVATIVE (urgent), * Calls `estimatesmartfee` with targets 2/CONSERVATIVE (very urgent),
* 4/ECONOMICAL (normal), and 100/ECONOMICAL (slow) then returns the * 3/CONSERVATIVE (urgent), 4/ECONOMICAL (normal), and 100/ECONOMICAL (slow)
* feerates as sat/kVB. * then returns the feerates as sat/kVB.
*/ */
static struct command_result *estimatefees(struct command *cmd, static struct command_result *estimatefees(struct command *cmd,
const char *buf UNUSED, const char *buf UNUSED,
@ -772,7 +772,8 @@ static struct command_result *estimatefees(struct command *cmd,
if (!param(cmd, buf, toks, NULL)) if (!param(cmd, buf, toks, NULL))
return command_param_failed(); return command_param_failed();
/* First call to estimatesmartfee, for urgent estimation. */ /* First call to estimatesmartfee, for very urgent estimation (unilateral
* and max_acceptable feerates). */
params[0] = "2"; params[0] = "2";
params[1] = "CONSERVATIVE"; params[1] = "CONSERVATIVE";
start_bitcoin_cli(NULL, cmd, estimatefees_second_step, true, start_bitcoin_cli(NULL, cmd, estimatefees_second_step, true,
@ -931,12 +932,9 @@ static const struct plugin_command commands[] = {
}, },
}; };
int main(int argc, char *argv[]) static struct bitcoind *new_bitcoind(const tal_t *ctx)
{ {
setup_locale(); bitcoind = tal(ctx, struct bitcoind);
/* Initialize our global context object here to handle startup options. */
bitcoind = tal(NULL, struct bitcoind);
bitcoind->cli = NULL; bitcoind->cli = NULL;
bitcoind->datadir = NULL; bitcoind->datadir = NULL;
@ -953,6 +951,16 @@ int main(int argc, char *argv[])
bitcoind->max_fee_multiplier = 10; bitcoind->max_fee_multiplier = 10;
bitcoind->commit_fee_percent = 100; bitcoind->commit_fee_percent = 100;
return bitcoind;
}
int main(int argc, char *argv[])
{
setup_locale();
/* Initialize our global context object here to handle startup options. */
bitcoind = new_bitcoind(NULL);
plugin_main(argv, init, PLUGIN_STATIC, NULL, commands, ARRAY_SIZE(commands), plugin_main(argv, init, PLUGIN_STATIC, NULL, commands, ARRAY_SIZE(commands),
NULL, 0, NULL, 0, NULL, 0, NULL, 0,
plugin_option("bitcoin-datadir", plugin_option("bitcoin-datadir",

Loading…
Cancel
Save