MCPcopy Create free account
hub / github.com/ElementsProject/lightning / get_feerate

Function get_feerate

plugins/bcli.c:564–597  ·  view source on GitHub ↗

Get a single feerate from estimatesmartfee. * Returns NULL on success (feerate stored in *perkb), or error response. */

Source from the content-addressed store, hash-verified

562/* Get a single feerate from estimatesmartfee.
563 * Returns NULL on success (feerate stored in *perkb), or error response. */
564static struct command_result *get_feerate(struct command *cmd,
565 u32 blocks,
566 const char *style,
567 u64 *perkb)
568{
569 struct bcli_result *res;
570 const jsmntok_t *tokens;
571
572 res = run_bitcoin_cli(cmd, cmd->plugin, "estimatesmartfee",
573 tal_fmt(tmpctx, "%u", blocks), style, NULL);
574
575 if (res->exitstatus != 0)
576 return estimatefees_null_response(cmd);
577
578 tokens = json_parse_simple(res->output, res->output, res->output_len);
579 if (!tokens)
580 return command_err(cmd, res, "bad JSON: cannot parse");
581
582 if (json_scan(tmpctx, res->output, tokens, "{feerate:%}",
583 JSON_SCAN(json_to_bitcoin_amount, perkb)) != NULL) {
584 /* Paranoia: if it had a feerate, but was malformed: */
585 if (json_get_member(res->output, tokens, "feerate"))
586 return command_err(cmd, res, "bad JSON: cannot scan");
587 /* Regtest fee estimation is generally awful: Fake it at min. */
588 if (bitcoind->fake_fees)
589 *perkb = 1000;
590 else
591 /* We return null if estimation failed, and bitcoin-cli will
592 * exit with 0 but no feerate field on failure. */
593 return estimatefees_null_response(cmd);
594 }
595
596 return NULL;
597}
598
599/* Get the current feerates. We use an urgent feerate for unilateral_close and max,
600 * a slightly less urgent feerate for htlc_resolution and penalty transactions,

Callers 9

estimatefeesFunction · 0.70
json_add_htlcsFunction · 0.50
commit_txfeeFunction · 0.50
NON_NULL_ARGSFunction · 0.50
calc_max_close_feerateFunction · 0.50
peer_start_closingdFunction · 0.50
peer_sending_commitsigFunction · 0.50
peer_got_commitsigFunction · 0.50
mainFunction · 0.50

Calls 6

run_bitcoin_cliFunction · 0.85
json_parse_simpleFunction · 0.85
command_errFunction · 0.85
json_get_memberFunction · 0.85
json_scanFunction · 0.50

Tested by

no test coverage detected