stage22-payment-uri.py
TEXT FILE559 B · Public source code for developers, search crawlers and AI agents
1from urllib.parse import urlencode
2
3def payment_uri(validated_address, sats, label):
4 if type(sats) is not int or not 0<sats<=2100000000000000: raise ValueError('amount')
5 if not validated_address.isascii() or not validated_address.isalnum(): raise ValueError('address syntax')
6 whole, frac=divmod(sats,100000000)
7 return 'bitcoin:'+validated_address+'?'+urlencode({'amount':f'{whole}.{frac:08d}','label':label})
8
9if __name__=='__main__':
10 assert payment_uri('tb1qfixture',1234,'Order 7')=='bitcoin:tb1qfixture?amount=0.00001234&label=Order+7'Read-only source · Select a line number to link directly · Raw download above
