lightningd: add arg to bitcoind_estimate_fees callback.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2024-06-23 00:34:33 +09:30
parent 436bf6c9e1
commit f318d08e94
3 changed files with 28 additions and 12 deletions

View file

@ -174,7 +174,8 @@ static void bitcoin_plugin_send(struct bitcoind *bitcoind,
struct estimatefee_call {
struct bitcoind *bitcoind;
void (*cb)(struct lightningd *ld, u32 feerate_floor,
const struct feerate_est *rates);
const struct feerate_est *rates, void *);
void *cb_arg;
};
/* Note: returns estimates in perkb, caller converts! */
@ -341,20 +342,23 @@ static void estimatefees_callback(const char *buf, const jsmntok_t *toks,
feerates[i].rate = floor;
}
call->cb(call->bitcoind->ld, floor, feerates);
call->cb(call->bitcoind->ld, floor, feerates, call->cb_arg);
tal_free(call);
}
void bitcoind_estimate_fees(struct bitcoind *bitcoind,
void (*cb)(struct lightningd *ld,
u32 feerate_floor,
const struct feerate_est *feerates))
void bitcoind_estimate_fees_(struct bitcoind *bitcoind,
void (*cb)(struct lightningd *ld,
u32 feerate_floor,
const struct feerate_est *feerates,
void *arg),
void *cb_arg)
{
struct jsonrpc_request *req;
struct estimatefee_call *call = tal(bitcoind, struct estimatefee_call);
call->bitcoind = bitcoind;
call->cb = cb;
call->cb_arg = cb_arg;
req = jsonrpc_request_start(bitcoind, "estimatefees", NULL, true,
bitcoind->log,

View file

@ -58,10 +58,21 @@ struct bitcoind *new_bitcoind(const tal_t *ctx,
struct lightningd *ld,
struct logger *log);
void bitcoind_estimate_fees(struct bitcoind *bitcoind,
void (*cb)(struct lightningd *ld,
u32 feerate_floor,
const struct feerate_est *feerates));
#define bitcoind_estimate_fees(bitcoind_, cb, arg) \
bitcoind_estimate_fees_((bitcoind_), \
typesafe_cb_preargs(void, void *, \
(cb), (arg), \
struct lightningd *, \
u32, \
const struct feerate_est *), \
(arg))
void bitcoind_estimate_fees_(struct bitcoind *bitcoind,
void (*cb)(struct lightningd *ld,
u32 feerate_floor,
const struct feerate_est *feerates,
void *arg),
void *cb_arg);
/* If ctx is freed, cb won't be called! */
void bitcoind_sendrawtx_(const tal_t *ctx,

View file

@ -519,7 +519,8 @@ static bool different_blockcounts(struct chain_topology *topo,
static void update_feerates(struct lightningd *ld,
u32 feerate_floor,
const struct feerate_est *rates TAKES)
const struct feerate_est *rates TAKES,
void *arg UNUSED)
{
struct feerate_est *new_smoothed;
bool changed;
@ -579,7 +580,7 @@ static void start_fee_estimate(struct chain_topology *topo)
if (topo->stopping)
return;
/* Once per new block head, update fee estimates. */
bitcoind_estimate_fees(topo->bitcoind, update_feerates);
bitcoind_estimate_fees(topo->bitcoind, update_feerates, NULL);
}
struct rate_conversion {