| 165 | } |
| 166 | |
| 167 | bool find_txo_chain(const tal_t *ctx, |
| 168 | const struct bkpr *bkpr, |
| 169 | struct command *cmd, |
| 170 | const struct account *acct, |
| 171 | struct txo_set ***sets) |
| 172 | { |
| 173 | struct bitcoin_txid **txids; |
| 174 | struct chain_event *open_ev; |
| 175 | bool is_complete = true; |
| 176 | const char *start_acct_name; |
| 177 | |
| 178 | /* If we have lost our database and used recovery, this can be |
| 179 | * NULL. That's the least of our problems though! */ |
| 180 | if (!acct->open_event_db_id) { |
| 181 | plugin_log(cmd->plugin, LOG_BROKEN, |
| 182 | "Cannot find the open_event for %s: did we lose our db?", |
| 183 | acct->name); |
| 184 | return false; |
| 185 | } |
| 186 | open_ev = find_chain_event_by_id(ctx, bkpr, cmd, |
| 187 | *acct->open_event_db_id); |
| 188 | |
| 189 | if (sets) |
| 190 | *sets = tal_arr(ctx, struct txo_set *, 0); |
| 191 | txids = tal_arr(ctx, struct bitcoin_txid *, 0); |
| 192 | tal_arr_expand(&txids, &open_ev->outpoint.txid); |
| 193 | |
| 194 | /* We only want to filter by the account for the very |
| 195 | * first utxo that we get the tree for, so we |
| 196 | * start w/ this acct id... */ |
| 197 | start_acct_name = open_ev->acct_name; |
| 198 | |
| 199 | for (size_t i = 0; i < tal_count(txids); i++) { |
| 200 | struct txo_set *set; |
| 201 | bool set_complete; |
| 202 | |
| 203 | set = find_txo_set(ctx, bkpr, cmd, txids[i], |
| 204 | start_acct_name, |
| 205 | &set_complete); |
| 206 | |
| 207 | /* After first use, we free the acct dbid ptr, |
| 208 | * which will pass in NULL and not filter by |
| 209 | * account for any subsequent txo_set hunt */ |
| 210 | start_acct_name = NULL; |
| 211 | |
| 212 | is_complete &= set_complete; |
| 213 | for (size_t j = 0; j < tal_count(set->pairs); j++) { |
| 214 | struct txo_pair *pr = set->pairs[j]; |
| 215 | |
| 216 | /* Has this been resolved? */ |
| 217 | if ((pr->txo |
| 218 | && is_channel_account(pr->txo->acct_name)) |
| 219 | && !pr->spend) |
| 220 | is_complete = false; |
| 221 | |
| 222 | /* wallet accts and zero-fee-htlc anchors |
| 223 | * might overlap txids */ |
| 224 | if (pr->spend |
no test coverage detected