| 175 | } |
| 176 | |
| 177 | static struct command_result *finish_txprepare(struct command *cmd, |
| 178 | struct txprepare *txp) |
| 179 | { |
| 180 | struct json_stream *js; |
| 181 | struct unreleased_tx *utx; |
| 182 | |
| 183 | /* Add the outputs they gave us */ |
| 184 | for (size_t i = 0; i < tal_count(txp->outputs); i++) { |
| 185 | struct wally_tx_output *out; |
| 186 | |
| 187 | out = wally_tx_output(NULL, txp->outputs[i].script, |
| 188 | txp->outputs[i].amount); |
| 189 | if (!out) |
| 190 | return command_fail(cmd, JSONRPC2_INVALID_PARAMS, |
| 191 | "Invalid output %zi (%s:%s)", i, |
| 192 | tal_hex(tmpctx, |
| 193 | txp->outputs[i].script), |
| 194 | type_to_string(tmpctx, |
| 195 | struct amount_sat, |
| 196 | &txp->outputs[i].amount)); |
| 197 | psbt_add_output(txp->psbt, out, i); |
| 198 | |
| 199 | if (txp->outputs[i].is_to_external) |
| 200 | psbt_output_mark_as_external(txp->psbt, |
| 201 | &txp->psbt->outputs[i]); |
| 202 | |
| 203 | wally_tx_output_free(out); |
| 204 | } |
| 205 | |
| 206 | /* If this is elements, we should normalize |
| 207 | * the PSBT fee output */ |
| 208 | psbt_elements_normalize_fees(txp->psbt); |
| 209 | |
| 210 | utx = tal(NULL, struct unreleased_tx); |
| 211 | utx->psbt = tal_steal(utx, txp->psbt); |
| 212 | psbt_txid(utx, txp->psbt, &utx->txid, &utx->tx); |
| 213 | |
| 214 | /* If this is a withdraw, we sign and send immediately. */ |
| 215 | if (txp->is_withdraw) { |
| 216 | struct out_req *req; |
| 217 | |
| 218 | /* Won't live beyond this cmd. */ |
| 219 | tal_steal(cmd, utx); |
| 220 | req = jsonrpc_request_start(cmd->plugin, cmd, "signpsbt", |
| 221 | signpsbt_done, forward_error, |
| 222 | utx); |
| 223 | json_add_psbt(req->js, "psbt", utx->psbt); |
| 224 | return send_outreq(cmd->plugin, req); |
| 225 | } |
| 226 | |
| 227 | list_add(&unreleased_txs, &utx->list); |
| 228 | js = jsonrpc_stream_success(cmd); |
| 229 | json_add_hex_talarr(js, "unsigned_tx", linearize_wtx(tmpctx, utx->tx)); |
| 230 | json_add_txid(js, "txid", &utx->txid); |
| 231 | json_add_psbt(js, "psbt", utx->psbt); |
| 232 | return command_finished(cmd, js); |
| 233 | } |
| 234 |
no test coverage detected