MCPcopy Create free account
hub / github.com/ElementsProject/lightning / find_txo_set

Function find_txo_set

plugins/bkpr/recorder.c:87–154  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

85}
86
87static 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);

Callers 1

find_txo_chainFunction · 0.85

Calls 4

find_txos_for_txFunction · 0.85
new_txo_pairFunction · 0.85
mvt_tag_strFunction · 0.85
tal_freeFunction · 0.85

Tested by

no test coverage detected