psbt_changeset_get_next - Get next message to send * * This generates the next message to send from a changeset for the * interactive transaction protocol. * * @ctx - allocation context of returned msg * @cid - channel_id for the message * @set - changeset to get next update from * * Returns a wire message or NULL if no changes. */
| 219 | * Returns a wire message or NULL if no changes. |
| 220 | */ |
| 221 | static u8 *psbt_changeset_get_next(const tal_t *ctx, |
| 222 | struct channel_id *cid, |
| 223 | struct psbt_changeset *set) |
| 224 | { |
| 225 | u64 serial_id; |
| 226 | u8 *msg; |
| 227 | |
| 228 | if (tal_count(set->added_ins) != 0) { |
| 229 | const struct input_set *in = &set->added_ins[0]; |
| 230 | u8 *script; |
| 231 | |
| 232 | if (!psbt_get_serial_id(&in->input.unknowns, &serial_id)) |
| 233 | abort(); |
| 234 | |
| 235 | const u8 *prevtx = linearize_wtx(ctx, |
| 236 | in->input.utxo); |
| 237 | |
| 238 | if (in->input.redeem_script_len) |
| 239 | script = tal_dup_arr(ctx, u8, |
| 240 | in->input.redeem_script, |
| 241 | in->input.redeem_script_len, 0); |
| 242 | else |
| 243 | script = NULL; |
| 244 | |
| 245 | msg = towire_tx_add_input(ctx, cid, serial_id, |
| 246 | prevtx, in->tx_input.index, |
| 247 | in->tx_input.sequence, |
| 248 | script); |
| 249 | |
| 250 | tal_arr_remove(&set->added_ins, 0); |
| 251 | return msg; |
| 252 | } |
| 253 | if (tal_count(set->rm_ins) != 0) { |
| 254 | if (!psbt_get_serial_id(&set->rm_ins[0].input.unknowns, |
| 255 | &serial_id)) |
| 256 | abort(); |
| 257 | |
| 258 | msg = towire_tx_remove_input(ctx, cid, serial_id); |
| 259 | |
| 260 | tal_arr_remove(&set->rm_ins, 0); |
| 261 | return msg; |
| 262 | } |
| 263 | if (tal_count(set->added_outs) != 0) { |
| 264 | struct amount_sat sats; |
| 265 | struct amount_asset asset_amt; |
| 266 | |
| 267 | const struct output_set *out = &set->added_outs[0]; |
| 268 | if (!psbt_get_serial_id(&out->output.unknowns, &serial_id)) |
| 269 | abort(); |
| 270 | |
| 271 | asset_amt = wally_tx_output_get_amount(&out->tx_output); |
| 272 | sats = amount_asset_to_sat(&asset_amt); |
| 273 | const u8 *script = wally_tx_output_get_script(ctx, |
| 274 | &out->tx_output); |
| 275 | |
| 276 | msg = towire_tx_add_output(ctx, cid, serial_id, |
| 277 | sats.satoshis, /* Raw: wire interface */ |
| 278 | script); |
no test coverage detected