util: mv create_URI to create_bip21_uri, and small clean-up
This commit is contained in:
@@ -798,17 +798,25 @@ def parse_URI(uri: str, on_pr: Callable=None) -> dict:
|
||||
return out
|
||||
|
||||
|
||||
def create_URI(addr, amount, message):
|
||||
def create_bip21_uri(addr, amount_sat: Optional[int], message: Optional[str],
|
||||
*, extra_query_params: Optional[dict] = None) -> str:
|
||||
from . import bitcoin
|
||||
if not bitcoin.is_address(addr):
|
||||
return ""
|
||||
if extra_query_params is None:
|
||||
extra_query_params = {}
|
||||
query = []
|
||||
if amount:
|
||||
query.append('amount=%s'%format_satoshis_plain(amount))
|
||||
if amount_sat:
|
||||
query.append('amount=%s'%format_satoshis_plain(amount_sat))
|
||||
if message:
|
||||
query.append('message=%s'%urllib.parse.quote(message))
|
||||
for k, v in extra_query_params.items():
|
||||
if not isinstance(k, str) or k != urllib.parse.quote(k):
|
||||
raise Exception(f"illegal key for URI: {repr(k)}")
|
||||
v = urllib.parse.quote(v)
|
||||
query.append(f"{k}={v}")
|
||||
p = urllib.parse.ParseResult(scheme='bitcoin', netloc='', path=addr, params='', query='&'.join(query), fragment='')
|
||||
return urllib.parse.urlunparse(p)
|
||||
return str(urllib.parse.urlunparse(p))
|
||||
|
||||
|
||||
# Python bug (http://bugs.python.org/issue1927) causes raw_input
|
||||
|
||||
Reference in New Issue
Block a user