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

Function matchup_events

tests/utils.py:257–322  ·  view source on GitHub ↗
(u_set, evs, chans, tag_list)

Source from the content-addressed store, hash-verified

255
256
257def matchup_events(u_set, evs, chans, tag_list):
258 if len(u_set) != len(evs):
259 raise ValueError(f"utxo-set does not match expected (diff lens). exp {evs}, actual {u_set}")
260 if len(u_set) == 0:
261 raise ValueError(f"utxo-set is empty. exp {evs}, actual {u_set}")
262
263 def get_tags(utxo):
264 return [utxo['primary_tag']] + utxo['extra_tags']
265
266 txid = u_set[0][0]['utxo_txid']
267 # Stash the set for logging at end, if error
268 _u_set = u_set
269 for ev in evs:
270 found = False
271 for u in u_set:
272 # We use 'cid' as a placeholder for the channel id, since it's
273 # dyanmic, but we need to sub it in. 'chans' is a list of cids,
274 # which are mapped to `cid` tags' suffixes. eg. 'cid1' is the
275 # first cid in the chans list
276 if ev[0][:3] == 'cid':
277 idx = int(ev[0][3:])
278 acct = chans[idx - 1]
279 else:
280 acct = ev[0]
281
282 if u[0]['account_id'] != acct or get_tags(u[0]) != ev[1]:
283 continue
284
285 if ev[2] is None:
286 if u[1] is not None:
287 raise ValueError(f"Expected unspent utxo. exp {ev}, actual {u}")
288 found = True
289 u_set.remove(u)
290 break
291
292 # ugly hack to annotate two possible futures for a utxo
293 if type(ev[2]) is tuple:
294 tag = get_tags(u[1]) if u[1] else u[1]
295 if tag not in [x[0] for x in ev[2]]:
296 raise ValueError(f"Unable to find {tag} in event set {ev}")
297 if not u[1]:
298 found = True
299 u_set.remove(u)
300 break
301 for x in ev[2]:
302 if x[0] == get_tags(u[1]) and 'to_miner' not in get_tags(u[1]):
303 # Save the 'spent to' txid in the tag-list
304 tag_list[x[1]] = u[1]['spending_txid']
305 else:
306 if ev[2] != get_tags(u[1]):
307 raise ValueError(f"tags dont' match. exp {ev}, actual ({u[1]}) full utxo info: {u}")
308 # Save the 'spent to' txid in the tag-list
309 if 'to_miner' not in get_tags(u[1]):
310 tag_list[ev[3]] = u[1]['spending_txid']
311
312 found = True
313 u_set.remove(u)
314

Callers 1

check_utxos_channelFunction · 0.85

Calls 2

get_tagsFunction · 0.85
removeMethod · 0.45

Tested by

no test coverage detected