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

Function get_feerate

plugins/bcli.c:557–590  ·  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

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

Callers 8

estimatefeesFunction · 0.70
json_add_htlcsFunction · 0.50
commit_txfeeFunction · 0.50
NON_NULL_ARGSFunction · 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