this requires having a serial_id entry on everything */ YOU MUST KEEP orig + new AROUND TO USE THE RESULTING SETS */
| 237 | /* this requires having a serial_id entry on everything */ |
| 238 | /* YOU MUST KEEP orig + new AROUND TO USE THE RESULTING SETS */ |
| 239 | struct psbt_changeset *psbt_get_changeset(const tal_t *ctx, |
| 240 | struct wally_psbt *orig, |
| 241 | struct wally_psbt *new) |
| 242 | { |
| 243 | int result; |
| 244 | size_t i = 0, j = 0; |
| 245 | struct psbt_changeset *set; |
| 246 | |
| 247 | psbt_sort_by_serial_id(orig); |
| 248 | psbt_sort_by_serial_id(new); |
| 249 | |
| 250 | set = new_changeset(ctx); |
| 251 | |
| 252 | /* Find the input diff */ |
| 253 | while (i < orig->num_inputs || j < new->num_inputs) { |
| 254 | if (i >= orig->num_inputs) { |
| 255 | ADD(input, set->added_ins, new, j); |
| 256 | j++; |
| 257 | continue; |
| 258 | } |
| 259 | if (j >= new->num_inputs) { |
| 260 | ADD(input, set->rm_ins, orig, i); |
| 261 | i++; |
| 262 | continue; |
| 263 | } |
| 264 | |
| 265 | result = compare_serials(&orig->inputs[i].unknowns, |
| 266 | &new->inputs[j].unknowns); |
| 267 | if (result == -1) { |
| 268 | ADD(input, set->rm_ins, orig, i); |
| 269 | i++; |
| 270 | continue; |
| 271 | } |
| 272 | if (result == 1) { |
| 273 | ADD(input, set->added_ins, new, j); |
| 274 | j++; |
| 275 | continue; |
| 276 | } |
| 277 | |
| 278 | if (!input_identical(orig, i, new, j)) { |
| 279 | ADD(input, set->rm_ins, orig, i); |
| 280 | ADD(input, set->added_ins, new, j); |
| 281 | } |
| 282 | i++; |
| 283 | j++; |
| 284 | } |
| 285 | /* Find the output diff */ |
| 286 | i = 0; |
| 287 | j = 0; |
| 288 | while (i < orig->num_outputs || j < new->num_outputs) { |
| 289 | if (i >= orig->num_outputs) { |
| 290 | ADD(output, set->added_outs, new, j); |
| 291 | j++; |
| 292 | continue; |
| 293 | } |
| 294 | if (j >= new->num_outputs) { |
| 295 | ADD(output, set->rm_outs, orig, i); |
| 296 | i++; |