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

Function signpsbt_done

plugins/txprepare.c:183–226  ·  view source on GitHub ↗

Called after lightningd has signed the inputs. */

Source from the content-addressed store, hash-verified

181
182/* Called after lightningd has signed the inputs. */
183static struct command_result *signpsbt_done(struct command *cmd,
184 const char *method,
185 const char *buf,
186 const jsmntok_t *result,
187 struct unreleased_tx *utx)
188{
189 struct out_req *req;
190 const jsmntok_t *psbttok = json_get_member(buf, result, "signed_psbt");
191 struct bitcoin_txid txid;
192
193 tal_free(utx->psbt);
194 utx->psbt = json_tok_psbt(utx, buf, psbttok);
195 /* Replace with signed tx. */
196 tal_free(utx->tx);
197
198 /* The txid from the signed PSBT should match our expectation. */
199 psbt_txid(NULL, utx->psbt, &txid, NULL);
200 if (!bitcoin_txid_eq(&txid, &utx->txid)) {
201 return command_fail(cmd, LIGHTNINGD,
202 "Signed tx changed txid? Had '%s' now '%s'",
203 fmt_bitcoin_txid(tmpctx, &utx->txid),
204 fmt_bitcoin_txid(tmpctx, &txid));
205 }
206
207 /* Finalize the signed PSBT and extract the fully signed tx,
208 * so that utx->tx contains witness data for the response. */
209 if (!psbt_finalize(utx->psbt))
210 return command_fail(cmd, LIGHTNINGD,
211 "Signed PSBT not finalizeable: %s",
212 fmt_wally_psbt(tmpctx, utx->psbt));
213
214 utx->tx = psbt_final_tx(utx, utx->psbt);
215 if (!utx->tx)
216 return command_fail(cmd, LIGHTNINGD,
217 "Could not extract final tx: %s",
218 fmt_wally_psbt(tmpctx, utx->psbt));
219
220 req = jsonrpc_request_start(cmd, "sendpsbt",
221 sendpsbt_done,
222 txprepare_forward_error,
223 utx);
224 json_add_psbt(req->js, "psbt", utx->psbt);
225 return send_outreq(req);
226}
227
228static struct command_result *finish_txprepare(struct command *cmd,
229 struct txprepare *txp)

Callers

nothing calls this directly

Calls 11

json_get_memberFunction · 0.85
tal_freeFunction · 0.85
json_tok_psbtFunction · 0.85
psbt_txidFunction · 0.85
fmt_bitcoin_txidFunction · 0.85
psbt_finalizeFunction · 0.85
fmt_wally_psbtFunction · 0.85
psbt_final_txFunction · 0.85
json_add_psbtFunction · 0.85
command_failFunction · 0.70
send_outreqFunction · 0.70

Tested by

no test coverage detected