| 85 | } |
| 86 | |
| 87 | static struct txo_set *find_txo_set(const tal_t *ctx, |
| 88 | const struct bkpr *bkpr, |
| 89 | struct command *cmd, |
| 90 | const struct bitcoin_txid *txid, |
| 91 | const char *acct_name, |
| 92 | bool *is_complete) |
| 93 | { |
| 94 | struct txo_pair *pr; |
| 95 | struct chain_event **evs; |
| 96 | struct txo_set *txos = tal(ctx, struct txo_set); |
| 97 | |
| 98 | /* In some special cases (the opening tx), we only |
| 99 | * want the outputs that pertain to a given account, |
| 100 | * most other times we want all utxos, regardless of account */ |
| 101 | evs = find_txos_for_tx(ctx, bkpr, cmd, txid); |
| 102 | txos->pairs = tal_arr(txos, struct txo_pair *, 0); |
| 103 | txos->txid = tal_dup(txos, struct bitcoin_txid, txid); |
| 104 | |
| 105 | pr = NULL; |
| 106 | |
| 107 | /* If there's nothing for this txid, we're missing data */ |
| 108 | if (is_complete) |
| 109 | *is_complete = tal_count(evs) > 0; |
| 110 | |
| 111 | for (size_t i = 0; i < tal_count(evs); i++) { |
| 112 | struct chain_event *ev = evs[i]; |
| 113 | |
| 114 | if (acct_name && !streq(ev->acct_name, acct_name)) |
| 115 | continue; |
| 116 | |
| 117 | if (ev->spending_txid) { |
| 118 | if (!pr) { |
| 119 | /* We're missing data!! */ |
| 120 | pr = new_txo_pair(txos->pairs); |
| 121 | if (is_complete) |
| 122 | *is_complete = false; |
| 123 | } else { |
| 124 | assert(pr->txo); |
| 125 | /* Make sure it's the same txo */ |
| 126 | assert(bitcoin_outpoint_eq(&pr->txo->outpoint, |
| 127 | &ev->outpoint)); |
| 128 | } |
| 129 | |
| 130 | pr->spend = tal_steal(pr, ev); |
| 131 | tal_arr_expand(&txos->pairs, pr); |
| 132 | pr = NULL; |
| 133 | } else { |
| 134 | /* We might not have a spend event |
| 135 | * for everything */ |
| 136 | if (pr) { |
| 137 | /* Disappear "channel_proposed" events */ |
| 138 | if (streq(pr->txo->tag, |
| 139 | mvt_tag_str(MVT_CHANNEL_PROPOSED))) |
| 140 | pr = tal_free(pr); |
| 141 | else |
| 142 | tal_arr_expand(&txos->pairs, pr); |
| 143 | } |
| 144 | pr = new_txo_pair(txos->pairs); |
no test coverage detected