stage11-micropayment-aggregation.py
TEXT FILE644 B · Public source code for developers, search crawlers and AI agents
1def aggregate(entries):
2 seen = set()
3 totals = {}
4 for event_id, payee, sat in entries:
5 if event_id in seen or type(sat) is not int or sat <= 0:
6 raise ValueError('invalid obligation')
7 seen.add(event_id)
8 totals[payee] = totals.get(payee,0) + sat
9 if totals[payee] > 21_000_000*100_000_000:
10 raise ValueError('amount overflow')
11 return totals
12
13if __name__ == '__main__':
14 assert aggregate([('a','merchant',3),('b','merchant',7)]) == {'merchant':10}
15 try: aggregate([('a','m',3),('a','m',3)])
16 except ValueError: pass
17 else: raise AssertionError('duplicate accepted')Read-only source · Select a line number to link directly · Raw download above
