| 401 | mw_load_outputs(struct multiwithdraw_command *mw); |
| 402 | |
| 403 | static struct command_result * |
| 404 | mw_after_fundpsbt(struct command *cmd, |
| 405 | const char *buf, |
| 406 | const jsmntok_t *result, |
| 407 | struct multiwithdraw_command *mw) |
| 408 | { |
| 409 | const jsmntok_t *field; |
| 410 | u32 feerate_per_kw; |
| 411 | u32 estimated_final_weight; |
| 412 | struct amount_sat excess_sat; |
| 413 | struct amount_msat excess_msat; |
| 414 | bool ok = true; |
| 415 | |
| 416 | /* Extract results. */ |
| 417 | field = ok ? json_get_member(buf, result, "psbt") : NULL; |
| 418 | ok = ok && field; |
| 419 | mw->psbt = ok ? psbt_from_b64(mw, |
| 420 | buf + field->start, |
| 421 | field->end - field->start) : NULL; |
| 422 | ok = ok && mw->psbt; |
| 423 | |
| 424 | field = ok ? json_get_member(buf, result, "feerate_per_kw") : NULL; |
| 425 | ok = ok && field; |
| 426 | ok = ok && json_to_number(buf, field, &feerate_per_kw); |
| 427 | |
| 428 | field = ok ? json_get_member(buf, result, "estimated_final_weight") : NULL; |
| 429 | ok = ok && field; |
| 430 | ok = ok && json_to_number(buf, field, &estimated_final_weight); |
| 431 | |
| 432 | field = ok ? json_get_member(buf, result, "excess_msat") : NULL; |
| 433 | ok = ok && field; |
| 434 | ok = ok && json_to_msat(buf, field, &excess_msat); |
| 435 | ok = ok && amount_msat_to_sat(&excess_sat, excess_msat); |
| 436 | |
| 437 | if (!ok) |
| 438 | plugin_err(mw->cmd->plugin, |
| 439 | "Unexpected result from fundpsbt/utxopsbt: %.*s", |
| 440 | json_tok_full_len(result), |
| 441 | json_tok_full(buf, result)); |
| 442 | |
| 443 | plugin_log(mw->cmd->plugin, LOG_DBG, |
| 444 | "multiwithdraw %"PRIu64": %s done: %s.", |
| 445 | mw->id, |
| 446 | mw->utxos ? "utxopsbt" : "fundpsbt", |
| 447 | psbt_to_b64(tmpctx, mw->psbt)); |
| 448 | |
| 449 | /* Handle 'all'. */ |
| 450 | if (mw->has_all) { |
| 451 | size_t all_index = SIZE_MAX; |
| 452 | for (size_t i = 0; i < tal_count(mw->outputs); ++i) { |
| 453 | if (mw->outputs[i].all) { |
| 454 | all_index = i; |
| 455 | continue; |
| 456 | } |
| 457 | if (!amount_sat_sub(&excess_sat, excess_sat, |
| 458 | mw->outputs[i].amount)) |
| 459 | return mw_fail(mw, |
| 460 | FUND_CANNOT_AFFORD, |
nothing calls this directly
no test coverage detected