example.py
TEXT FILE1.2 KB · Public source code for developers, search crawlers and AI agents
1# SPDX-License-Identifier: 0BSD
2import json
3import re
4
5
6def unique_object(pairs):
7 result = {}
8 for key, value in pairs:
9 if key in result:
10 raise ValueError("duplicate JSON key")
11 result[key] = value
12 return result
13
14
15def parse_sats(text):
16 if not re.fullmatch(r"[1-9][0-9]{0,15}", text):
17 raise ValueError("invalid integer sats")
18 return int(text)
19
20
21def validate(candidate):
22 if type(candidate) is not dict or set(candidate) != {"invoice_id", "amount_sat", "network"}:
23 raise ValueError("invalid invoice shape")
24 if type(candidate["invoice_id"]) is not str or not re.fullmatch(r"[A-Za-z0-9_-]{1,64}", candidate["invoice_id"]):
25 raise ValueError("invalid invoice identifier")
26 amount = candidate["amount_sat"]
27 if type(amount) is not int or not 1 <= amount <= 100000:
28 raise ValueError("outside illustrative review limit")
29 if candidate["network"] != "test":
30 raise ValueError("Testnet only")
31 return {"invoice": dict(candidate), "status": "review_required"}
32
33
34def extract(proposal):
35 if type(proposal) is not dict or set(proposal) != {"invoice_id", "amount_sat", "network"}:
36 raise ValueError("unexpected proposal")
37 return proposalRead-only source · Select a line number to link directly · Raw download above
