Get a single feerate from estimatesmartfee. * Returns NULL on success (feerate stored in *perkb), or error response. */
| 555 | /* Get a single feerate from estimatesmartfee. |
| 556 | * Returns NULL on success (feerate stored in *perkb), or error response. */ |
| 557 | static 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, |
no test coverage detected