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

Function finish_txprepare

plugins/txprepare.c:228–285  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

226}
227
228static struct command_result *finish_txprepare(struct command *cmd,
229 struct txprepare *txp)
230{
231 struct json_stream *js;
232 struct unreleased_tx *utx;
233
234 /* Add the outputs they gave us */
235 for (size_t i = 0; i < tal_count(txp->outputs); i++) {
236 struct wally_tx_output *out;
237
238 out = wally_tx_output(NULL, txp->outputs[i].script,
239 txp->outputs[i].amount);
240 if (!out)
241 return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
242 "Invalid output %zi (%s:%s)", i,
243 tal_hex(tmpctx,
244 txp->outputs[i].script),
245 fmt_amount_sat(tmpctx,
246 txp->outputs[i].amount));
247 psbt_add_output(txp->psbt, out, i);
248
249 if (txp->outputs[i].is_to_external)
250 psbt_output_mark_as_external(txp->psbt,
251 &txp->psbt->outputs[i]);
252
253 wally_tx_output_free(out);
254 }
255
256 /* If this is elements, we should normalize
257 * the PSBT fee output */
258 psbt_elements_normalize_fees(txp->psbt);
259
260 utx = tal(NULL, struct unreleased_tx);
261 utx->is_upgrade = txp->is_upgrade;
262 utx->psbt = tal_steal(utx, txp->psbt);
263 psbt_txid(utx, utx->psbt, &utx->txid, &utx->tx);
264
265 /* If this is a withdraw, we sign and send immediately. */
266 if (txp->is_withdraw) {
267 struct out_req *req;
268
269 /* Won't live beyond this cmd. */
270 tal_steal(cmd, utx);
271 req = jsonrpc_request_start(cmd, "signpsbt",
272 signpsbt_done,
273 txprepare_forward_error,
274 utx);
275 json_add_psbt(req->js, "psbt", utx->psbt);
276 return send_outreq(req);
277 }
278
279 list_add(&unreleased_txs, &utx->list);
280 js = jsonrpc_stream_success(cmd);
281 json_add_hex_talarr(js, "unsigned_tx", linearize_wtx(tmpctx, utx->tx));
282 json_add_txid(js, "txid", &utx->txid);
283 json_add_psbt(js, "psbt", utx->psbt);
284 return command_finished(cmd, js);
285}

Callers 1

psbt_createdFunction · 0.85

Calls 15

tal_hexFunction · 0.85
psbt_add_outputFunction · 0.85
psbt_txidFunction · 0.85
json_add_psbtFunction · 0.85
json_add_hex_talarrFunction · 0.85
linearize_wtxFunction · 0.85
json_add_txidFunction · 0.85
wally_tx_outputClass · 0.70
command_failFunction · 0.70
send_outreqFunction · 0.70

Tested by

no test coverage detected