| 486 | } |
| 487 | |
| 488 | static struct command_result *json_fundpsbt(struct command *cmd, |
| 489 | const char *buffer, |
| 490 | const jsmntok_t *obj UNNEEDED, |
| 491 | const jsmntok_t *params) |
| 492 | { |
| 493 | struct utxo **utxos; |
| 494 | const struct utxo **excluded; |
| 495 | u32 *feerate_per_kw; |
| 496 | u32 *minconf, *weight, *min_witness_weight; |
| 497 | struct amount_sat *amount, input, diff, change; |
| 498 | bool all, *excess_as_change, *nonwrapped, *keep_emergency_funds; |
| 499 | u32 *locktime, *reserve, maxheight; |
| 500 | u32 current_height; |
| 501 | |
| 502 | if (!param_check(cmd, buffer, params, |
| 503 | p_req("satoshi", param_sat_or_all, &amount), |
| 504 | p_req("feerate", param_feerate, &feerate_per_kw), |
| 505 | p_req("startweight", param_number, &weight), |
| 506 | p_opt_def("minconf", param_number, &minconf, 1), |
| 507 | p_opt_def("reserve", param_number, &reserve, |
| 508 | RESERVATION_DEFAULT), |
| 509 | p_opt("locktime", param_number, &locktime), |
| 510 | p_opt_def("min_witness_weight", param_number, |
| 511 | &min_witness_weight, 0), |
| 512 | p_opt_def("excess_as_change", param_bool, |
| 513 | &excess_as_change, false), |
| 514 | p_opt_def("nonwrapped", param_bool, |
| 515 | &nonwrapped, false), |
| 516 | p_opt_def("opening_anchor_channel", param_bool, |
| 517 | &keep_emergency_funds, false), |
| 518 | NULL)) |
| 519 | return command_param_failed(); |
| 520 | |
| 521 | /* If we have anchor channels, we definitely need to keep |
| 522 | * emergency funds. */ |
| 523 | if (have_anchor_channel(cmd->ld)) |
| 524 | *keep_emergency_funds = true; |
| 525 | |
| 526 | all = amount_sat_eq(*amount, AMOUNT_SAT(-1ULL)); |
| 527 | maxheight = minconf_to_maxheight(*minconf, cmd->ld); |
| 528 | |
| 529 | current_height = get_block_height(cmd->ld->topology); |
| 530 | |
| 531 | /* We keep adding until we meet their output requirements. */ |
| 532 | utxos = tal_arr(cmd, struct utxo *, 0); |
| 533 | |
| 534 | /* Either uneconomical at this feerate, or already included. */ |
| 535 | excluded = tal_arr(cmd, const struct utxo *, 0); |
| 536 | |
| 537 | input = AMOUNT_SAT(0); |
| 538 | while (!inputs_sufficient(input, *amount, *feerate_per_kw, *weight, |
| 539 | &diff)) { |
| 540 | struct utxo *utxo; |
| 541 | struct amount_sat fee; |
| 542 | u32 utxo_weight; |
| 543 | |
| 544 | utxo = wallet_find_utxo(utxos, cmd->ld->wallet, |
| 545 | current_height, |
nothing calls this directly
no test coverage detected