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

Function onchain_tx_watched

lightningd/onchain_control.c:155–193  ·  view source on GitHub ↗

* Entrypoint for the txwatch callback, calls onchain_tx_depth. */

Source from the content-addressed store, hash-verified

153 * Entrypoint for the txwatch callback, calls onchain_tx_depth.
154 */
155static enum watch_result onchain_tx_watched(struct lightningd *ld,
156 struct channel *channel,
157 const struct bitcoin_txid *txid,
158 const struct bitcoin_tx *tx,
159 unsigned int depth)
160{
161 u32 blockheight = get_block_height(ld->topology);
162
163 if (tx != NULL) {
164 struct bitcoin_txid txid2;
165
166 bitcoin_txid(tx, &txid2);
167 if (!bitcoin_txid_eq(txid, &txid2)) {
168 channel_internal_error(channel, "Txid for %s is not %s",
169 type_to_string(tmpctx,
170 struct bitcoin_tx,
171 tx),
172 type_to_string(tmpctx,
173 struct bitcoin_txid,
174 txid));
175 return DELETE_WATCH;
176 }
177 }
178
179 if (depth == 0) {
180 log_unusual(channel->log, "Chain reorganization!");
181 channel_set_owner(channel, NULL);
182
183 /* We will most likely be freed, so this is a noop */
184 return KEEP_WATCHING;
185 }
186
187 /* Store the channeltx so we can replay later */
188 wallet_channeltxs_add(ld->wallet, channel,
189 WIRE_ONCHAIND_DEPTH, txid, 0, blockheight);
190
191 onchain_tx_depth(channel, txid, depth);
192 return KEEP_WATCHING;
193}
194
195static void watch_tx_and_outputs(struct channel *channel,
196 const struct bitcoin_tx *tx);

Callers

nothing calls this directly

Calls 7

channel_set_ownerFunction · 0.85
onchain_tx_depthFunction · 0.85
get_block_heightFunction · 0.70
bitcoin_txidClass · 0.70
channel_internal_errorFunction · 0.70
type_to_stringClass · 0.50
wallet_channeltxs_addFunction · 0.50

Tested by

no test coverage detected