| 855 | |
| 856 | |
| 857 | static void sendpsbt_done(struct bitcoind *bitcoind UNUSED, |
| 858 | bool success, const char *msg, |
| 859 | struct sending_psbt *sending) |
| 860 | { |
| 861 | struct lightningd *ld = sending->cmd->ld; |
| 862 | struct json_stream *response; |
| 863 | struct bitcoin_txid txid; |
| 864 | struct amount_sat change; |
| 865 | |
| 866 | if (!success) { |
| 867 | /* Unreserve the inputs again. */ |
| 868 | for (size_t i = 0; i < tal_count(sending->utxos); i++) { |
| 869 | wallet_unreserve_utxo(ld->wallet, |
| 870 | sending->utxos[i], |
| 871 | get_block_height(ld->topology), |
| 872 | sending->reserve_blocks); |
| 873 | } |
| 874 | |
| 875 | was_pending(command_fail(sending->cmd, LIGHTNINGD, |
| 876 | "Error broadcasting transaction: %s." |
| 877 | " Unsent tx discarded %s", |
| 878 | msg, |
| 879 | type_to_string(tmpctx, struct wally_tx, |
| 880 | sending->wtx))); |
| 881 | return; |
| 882 | } |
| 883 | |
| 884 | wallet_transaction_add(ld->wallet, sending->wtx, 0, 0); |
| 885 | |
| 886 | /* Extract the change output and add it to the DB */ |
| 887 | wallet_extract_owned_outputs(ld->wallet, sending->wtx, NULL, &change); |
| 888 | wally_txid(sending->wtx, &txid); |
| 889 | |
| 890 | for (size_t i = 0; i < sending->psbt->num_outputs; i++) |
| 891 | maybe_notify_new_external_send(ld, &txid, i, sending->psbt); |
| 892 | |
| 893 | response = json_stream_success(sending->cmd); |
| 894 | json_add_hex_talarr(response, "tx", linearize_wtx(tmpctx, sending->wtx)); |
| 895 | json_add_txid(response, "txid", &txid); |
| 896 | was_pending(command_success(sending->cmd, response)); |
| 897 | } |
| 898 | |
| 899 | static struct command_result *json_sendpsbt(struct command *cmd, |
| 900 | const char *buffer, |
nothing calls this directly
no test coverage detected