stage23-donation-tracking.py
TEXT FILE993 B · Public source code for developers, search crawlers and AI agents
1import re
2
3class Tracker:
4 def __init__(self, network, address):
5 self.network, self.address, self.outputs = network,address,{}
6 def observe(self, network, txid, vout, address, sats, confirmations):
7 if network != self.network or address != self.address: return False
8 if not re.fullmatch('[0-9a-f]{64}',txid) or type(vout) is not int or vout < 0 or type(sats) is not int or sats <= 0 or type(confirmations) is not int:
9 raise ValueError('invalid observation')
10 key=(network,txid,vout)
11 if key in self.outputs and self.outputs[key][0] != sats: raise ValueError('output conflict')
12 self.outputs[key]=(sats,confirmations)
13 return True
14 def total(self):
15 return sum(s for s,c in self.outputs.values() if c >= 1)
16
17if __name__ == '__main__':
18 t=Tracker('test','fixture'); args=('test','a'*64,0,'fixture',500)
19 t.observe(*args,1); t.observe(*args,1); assert t.total()==500
20 t.observe(*args,0); assert t.total()==0Read-only source · Select a line number to link directly · Raw download above
