stage24-order-invoices.py
TEXT FILE734 B · Public source code for developers, search crawlers and AI agents
1from dataclasses import dataclass
2import secrets
3
4@dataclass(frozen=True)
5class Invoice:
6 invoice_id: str
7 order_id: str
8 network: str
9 address: str
10 expected_sat: int
11 expires_at: int
12
13def issue(order, net, address, sats, now, ttl):
14 if net not in ("main","test") or not order or not address or type(sats) is not int or sats <= 0 or type(ttl) is not int or ttl <= 0:
15 raise ValueError("invalid invoice")
16 return Invoice(secrets.token_hex(16),order,net,address,sats,now+ttl)
17
18if __name__ == "__main__":
19 a=issue("order-1","test","fixture-only",2000,100,60)
20 assert a.expires_at==160 and a.expected_sat==2000
21 assert a.invoice_id != issue("order-1","test","fixture-only",2000,100,60).invoice_idRead-only source · Select a line number to link directly · Raw download above
