MCPcopy Create free account
hub / github.com/ElementsProject/lightning / sendpsbt_done

Function sendpsbt_done

wallet/walletrpc.c:989–1036  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

987}
988
989static void sendpsbt_done(struct bitcoind *bitcoind UNUSED,
990 bool success, const char *msg,
991 struct sending_psbt *sending)
992{
993 struct lightningd *ld = sending->cmd->ld;
994 struct json_stream *response;
995 struct bitcoin_txid txid;
996
997 if (!success) {
998 /* Unreserve the inputs again. */
999 for (size_t i = 0; i < tal_count(sending->utxos); i++) {
1000 wallet_unreserve_utxo(ld->wallet,
1001 sending->utxos[i],
1002 get_block_height(ld->topology),
1003 sending->reserve_blocks);
1004 }
1005
1006 was_pending(command_fail(sending->cmd, LIGHTNINGD,
1007 "Error broadcasting transaction: %s."
1008 " Unsent tx discarded %s",
1009 msg,
1010 fmt_wally_tx(tmpctx, sending->wtx)));
1011 return;
1012 }
1013
1014 /* Internal-only after, set to v2 */
1015 if (!psbt_set_version(sending->psbt, 2)) {
1016 abort(); // Send succeeded but later calls may fail
1017 }
1018
1019 wallet_transaction_add(ld->wallet, sending->wtx, 0, 0);
1020 wally_txid(sending->wtx, &txid);
1021
1022 /* Extract the change output and add it to the DB */
1023 if (!wallet_extract_owned_outputs(ld->wallet, sending->wtx, false, NULL, NULL)) {
1024 /* If we're not watching it for selfish reasons (i.e. pure send to
1025 * others), make sure we're watching it so we can update depth in db */
1026 watch_unconfirmed_txid(ld, ld->topology, &txid);
1027 }
1028
1029 for (size_t i = 0; i < sending->psbt->num_outputs; i++)
1030 maybe_notify_new_external_send(ld, &txid, i, sending->psbt);
1031
1032 response = json_stream_success(sending->cmd);
1033 json_add_hex_talarr(response, "tx", linearize_wtx(tmpctx, sending->wtx));
1034 json_add_txid(response, "txid", &txid);
1035 was_pending(command_success(sending->cmd, response));
1036}
1037
1038static struct command_result *json_dev_finalizepsbt(struct command *cmd,
1039 const char *buffer,

Callers

nothing calls this directly

Calls 15

fmt_wally_txFunction · 0.85
psbt_set_versionFunction · 0.85
abortFunction · 0.85
wally_txidFunction · 0.85
watch_unconfirmed_txidFunction · 0.85
json_add_hex_talarrFunction · 0.85
linearize_wtxFunction · 0.85
json_add_txidFunction · 0.85
wallet_unreserve_utxoFunction · 0.70
wallet_transaction_addFunction · 0.70

Tested by

no test coverage detected