| 464 | } |
| 465 | |
| 466 | bool find_txo_chain(const tal_t *ctx, |
| 467 | struct db *db, |
| 468 | struct account *acct, |
| 469 | struct txo_set ***sets) |
| 470 | { |
| 471 | struct bitcoin_txid **txids; |
| 472 | struct chain_event *open_ev; |
| 473 | bool is_complete = true; |
| 474 | u64 *start_acct_id = tal(NULL, u64); |
| 475 | |
| 476 | assert(acct->open_event_db_id); |
| 477 | open_ev = find_chain_event_by_id(ctx, db, |
| 478 | *acct->open_event_db_id); |
| 479 | |
| 480 | if (sets) |
| 481 | *sets = tal_arr(ctx, struct txo_set *, 0); |
| 482 | txids = tal_arr(ctx, struct bitcoin_txid *, 0); |
| 483 | tal_arr_expand(&txids, &open_ev->outpoint.txid); |
| 484 | |
| 485 | /* We only want to filter by the account for the very |
| 486 | * first utxo that we get the tree for, so we |
| 487 | * start w/ this acct id... */ |
| 488 | *start_acct_id = open_ev->acct_db_id; |
| 489 | |
| 490 | for (size_t i = 0; i < tal_count(txids); i++) { |
| 491 | struct txo_set *set; |
| 492 | bool set_complete; |
| 493 | |
| 494 | set = find_txo_set(ctx, db, txids[i], |
| 495 | start_acct_id, |
| 496 | &set_complete); |
| 497 | |
| 498 | /* After first use, we free the acct dbid ptr, |
| 499 | * which will pass in NULL and not filter by |
| 500 | * account for any subsequent txo_set hunt */ |
| 501 | if (start_acct_id) |
| 502 | start_acct_id = tal_free(start_acct_id); |
| 503 | |
| 504 | is_complete &= set_complete; |
| 505 | for (size_t j = 0; j < tal_count(set->pairs); j++) { |
| 506 | struct txo_pair *pr = set->pairs[j]; |
| 507 | |
| 508 | /* Has this been resolved? */ |
| 509 | if ((pr->txo |
| 510 | && is_channel_acct(pr->txo)) |
| 511 | && !pr->spend) |
| 512 | is_complete = false; |
| 513 | |
| 514 | /* wallet accts and zero-fee-htlc anchors |
| 515 | * might overlap txids */ |
| 516 | if (pr->spend |
| 517 | && pr->spend->spending_txid |
| 518 | /* 'to_miner' outputs are skipped */ |
| 519 | && !streq(pr->spend->tag, "to_miner") |
| 520 | && !txid_in_list(txids, pr->spend->spending_txid) |
| 521 | /* We dont trace utxos for non related accts */ |
| 522 | && (pr->spend->acct_db_id == acct->db_id |
| 523 | /* Unless it's stealable, in which case |
no test coverage detected