| 897 | } |
| 898 | |
| 899 | static struct command_result *json_sendpsbt(struct command *cmd, |
| 900 | const char *buffer, |
| 901 | const jsmntok_t *obj, |
| 902 | const jsmntok_t *params) |
| 903 | { |
| 904 | struct command_result *res; |
| 905 | struct sending_psbt *sending; |
| 906 | struct wally_psbt *psbt; |
| 907 | struct lightningd *ld = cmd->ld; |
| 908 | u32 *reserve_blocks; |
| 909 | |
| 910 | if (!param(cmd, buffer, params, |
| 911 | p_req("psbt", param_psbt, &psbt), |
| 912 | p_opt_def("reserve", param_number, &reserve_blocks, 12 * 6), |
| 913 | NULL)) |
| 914 | return command_param_failed(); |
| 915 | |
| 916 | sending = tal(cmd, struct sending_psbt); |
| 917 | sending->cmd = cmd; |
| 918 | sending->reserve_blocks = *reserve_blocks; |
| 919 | |
| 920 | psbt_finalize(psbt); |
| 921 | sending->wtx = psbt_final_tx(sending, psbt); |
| 922 | |
| 923 | /* psbt contains info about which outputs are to external, |
| 924 | * and thus need a coin_move issued for them. We only |
| 925 | * notify if the transaction broadcasts */ |
| 926 | sending->psbt = tal_steal(sending, psbt); |
| 927 | |
| 928 | if (!sending->wtx) |
| 929 | return command_fail(cmd, LIGHTNINGD, |
| 930 | "PSBT not finalizeable %s", |
| 931 | type_to_string(tmpctx, struct wally_psbt, |
| 932 | psbt)); |
| 933 | |
| 934 | /* We have to find/locate the utxos that are ours on this PSBT, |
| 935 | * so that we know who to mark as used. |
| 936 | */ |
| 937 | res = match_psbt_inputs_to_utxos(cmd, psbt, NULL, &sending->utxos); |
| 938 | if (res) |
| 939 | return res; |
| 940 | |
| 941 | for (size_t i = 0; i < tal_count(sending->utxos); i++) { |
| 942 | if (!wallet_reserve_utxo(ld->wallet, sending->utxos[i], |
| 943 | get_block_height(ld->topology), |
| 944 | sending->reserve_blocks)) |
| 945 | fatal("UTXO not reservable?"); |
| 946 | } |
| 947 | |
| 948 | /* Now broadcast the transaction */ |
| 949 | bitcoind_sendrawtx(cmd->ld->topology->bitcoind, |
| 950 | cmd->id, |
| 951 | tal_hex(tmpctx, |
| 952 | linearize_wtx(tmpctx, sending->wtx)), |
| 953 | false, sendpsbt_done, sending); |
| 954 | |
| 955 | return command_still_pending(cmd); |
| 956 | } |
nothing calls this directly
no test coverage detected