this requires having a serial_id entry on everything */ YOU MUST KEEP orig + new AROUND TO USE THE RESULTING SETS */
| 282 | /* this requires having a serial_id entry on everything */ |
| 283 | /* YOU MUST KEEP orig + new AROUND TO USE THE RESULTING SETS */ |
| 284 | struct psbt_changeset *psbt_get_changeset(const tal_t *ctx, |
| 285 | struct wally_psbt *orig, |
| 286 | struct wally_psbt *new) |
| 287 | { |
| 288 | int result; |
| 289 | size_t i = 0, j = 0; |
| 290 | struct psbt_changeset *set; |
| 291 | |
| 292 | psbt_sort_by_serial_id(orig); |
| 293 | psbt_sort_by_serial_id(new); |
| 294 | |
| 295 | set = new_changeset(ctx); |
| 296 | |
| 297 | /* Find the input diff */ |
| 298 | while (i < orig->num_inputs || j < new->num_inputs) { |
| 299 | if (i >= orig->num_inputs) { |
| 300 | ADD(input, set->added_ins, new, j); |
| 301 | j++; |
| 302 | continue; |
| 303 | } |
| 304 | if (j >= new->num_inputs) { |
| 305 | ADD(input, set->rm_ins, orig, i); |
| 306 | i++; |
| 307 | continue; |
| 308 | } |
| 309 | |
| 310 | result = compare_serials(&orig->inputs[i].unknowns, |
| 311 | &new->inputs[j].unknowns); |
| 312 | if (result == -1) { |
| 313 | ADD(input, set->rm_ins, orig, i); |
| 314 | i++; |
| 315 | continue; |
| 316 | } |
| 317 | if (result == 1) { |
| 318 | ADD(input, set->added_ins, new, j); |
| 319 | j++; |
| 320 | continue; |
| 321 | } |
| 322 | |
| 323 | if (!input_identical(orig, i, new, j)) { |
| 324 | ADD(input, set->rm_ins, orig, i); |
| 325 | ADD(input, set->added_ins, new, j); |
| 326 | } |
| 327 | i++; |
| 328 | j++; |
| 329 | } |
| 330 | /* Find the output diff */ |
| 331 | i = 0; |
| 332 | j = 0; |
| 333 | while (i < orig->num_outputs || j < new->num_outputs) { |
| 334 | if (i >= orig->num_outputs) { |
| 335 | ADD(output, set->added_outs, new, j); |
| 336 | j++; |
| 337 | continue; |
| 338 | } |
| 339 | if (j >= new->num_outputs) { |
| 340 | ADD(output, set->rm_outs, orig, i); |
| 341 | i++; |