| 249 | } |
| 250 | |
| 251 | static void estimatefees_callback(const char *buf, const jsmntok_t *toks, |
| 252 | const jsmntok_t *idtok, |
| 253 | struct estimatefee_call *call) |
| 254 | { |
| 255 | const jsmntok_t *resulttok, *floortok; |
| 256 | struct feerate_est *feerates; |
| 257 | u32 floor; |
| 258 | |
| 259 | resulttok = get_bitcoin_result(call->bitcoind, buf, toks, "estimatefees"); |
| 260 | |
| 261 | /* Modern style has floor. */ |
| 262 | floortok = json_get_member(buf, resulttok, "feerate_floor"); |
| 263 | if (floortok) { |
| 264 | feerates = parse_feerate_ranges(call, call->bitcoind, |
| 265 | buf, floortok, |
| 266 | json_get_member(buf, resulttok, |
| 267 | "feerates"), |
| 268 | &floor); |
| 269 | } else { |
| 270 | bitcoin_plugin_error(call->bitcoind, buf, resulttok, |
| 271 | "estimatefees", |
| 272 | "missing feerate_floor field"); |
| 273 | } |
| 274 | |
| 275 | /* Convert to perkw */ |
| 276 | floor = feerate_from_style(floor, FEERATE_PER_KBYTE); |
| 277 | if (floor < FEERATE_FLOOR) |
| 278 | floor = FEERATE_FLOOR; |
| 279 | |
| 280 | /* FIXME: We could let this go below the dynamic floor, but we'd |
| 281 | * need to know if the floor is because of their node's policy |
| 282 | * (minrelaytxfee) or mempool conditions (mempoolminfee). */ |
| 283 | for (size_t i = 0; i < tal_count(feerates); i++) { |
| 284 | feerates[i].rate = feerate_from_style(feerates[i].rate, |
| 285 | FEERATE_PER_KBYTE); |
| 286 | if (feerates[i].rate < floor) |
| 287 | feerates[i].rate = floor; |
| 288 | } |
| 289 | |
| 290 | call->cb(call->bitcoind->ld, floor, feerates, call->cb_arg); |
| 291 | tal_free(call); |
| 292 | } |
| 293 | |
| 294 | void bitcoind_estimate_fees_(const tal_t *ctx, |
| 295 | struct bitcoind *bitcoind, |
nothing calls this directly
no test coverage detected