Called after lightningd has signed the inputs. */
| 181 | |
| 182 | /* Called after lightningd has signed the inputs. */ |
| 183 | static 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 | |
| 228 | static struct command_result *finish_txprepare(struct command *cmd, |
| 229 | struct txprepare *txp) |
nothing calls this directly
no test coverage detected