| 645 | AUTODATA(json_command, &fundpsbt_command); |
| 646 | |
| 647 | static struct command_result *json_addpsbtoutput(struct command *cmd, |
| 648 | const char *buffer, |
| 649 | const jsmntok_t *obj UNNEEDED, |
| 650 | const jsmntok_t *params) |
| 651 | { |
| 652 | struct json_stream *response; |
| 653 | struct amount_sat *amount; |
| 654 | struct wally_psbt *psbt; |
| 655 | u32 *locktime; |
| 656 | ssize_t outnum; |
| 657 | u32 weight; |
| 658 | s64 keyidx; |
| 659 | const u8 *b32script; |
| 660 | bool *add_initiator_serial_ids; |
| 661 | struct wally_psbt_output *output; |
| 662 | u64 serial_id; |
| 663 | |
| 664 | if (!param_check(cmd, buffer, params, |
| 665 | p_req("satoshi", param_sat, &amount), |
| 666 | p_opt("initialpsbt", param_psbt, &psbt), |
| 667 | p_opt("locktime", param_number, &locktime), |
| 668 | p_opt("destination", param_bitcoin_address, |
| 669 | &b32script), |
| 670 | p_opt_def("add_initiator_serial_ids", param_bool, |
| 671 | &add_initiator_serial_ids, false), |
| 672 | NULL)) |
| 673 | return command_param_failed(); |
| 674 | |
| 675 | if (!psbt) { |
| 676 | if (!locktime) { |
| 677 | locktime = tal(cmd, u32); |
| 678 | *locktime = default_locktime(cmd->ld->topology); |
| 679 | } |
| 680 | psbt = create_psbt(cmd, 0, 0, *locktime); |
| 681 | } else if (locktime) { |
| 682 | return command_fail(cmd, FUNDING_PSBT_INVALID, |
| 683 | "Can't set locktime of an existing {initialpsbt}"); |
| 684 | } |
| 685 | |
| 686 | if (!validate_psbt(psbt)) |
| 687 | return command_fail(cmd, |
| 688 | FUNDING_PSBT_INVALID, |
| 689 | "PSBT failed to validate."); |
| 690 | |
| 691 | if (amount_sat_less(*amount, chainparams->dust_limit)) |
| 692 | return command_fail(cmd, FUND_OUTPUT_IS_DUST, |
| 693 | "Receive amount is below dust limit (%s)", |
| 694 | fmt_amount_sat(tmpctx, |
| 695 | chainparams->dust_limit)); |
| 696 | |
| 697 | if (command_check_only(cmd)) |
| 698 | return command_check_done(cmd); |
| 699 | |
| 700 | /* Get a change adddress */ |
| 701 | if (!b32script) { |
| 702 | enum addrtype type; |
| 703 | |
| 704 | /* FIXME: P2TR for elements! */ |
nothing calls this directly
no test coverage detected