Ejemplo n.º 1
0
 def get_payment_request_thread():
     import paymentrequest as pr
     if name and sig:
         s = pr.serialize_request(out).SerializeToString()
         request = pr.PaymentRequest(s)
     else:
         request = pr.get_payment_request(r)
     on_pr(request)
Ejemplo n.º 2
0
 def get_payment_request_thread():
     import paymentrequest as pr
     if name and sig:
         s = pr.serialize_request(out).SerializeToString()
         request = pr.PaymentRequest(s)
     else:
         request = pr.get_payment_request(r)
     on_pr(request)
Ejemplo n.º 3
0
def parse_URI(uri, on_pr=None):
    COIN = 100000000

    if ':' not in uri:
        if not is_address(uri):
            raise BaseException("Not a bitcoin address")
        return {'address': uri}

    u = urllib.parse.urlparse(uri)
    if u.scheme != 'bitcoin':
        raise BaseException("Not a bitcoin URI")
    address = u.path

    # python for android fails to parse query
    if address.find('?') > 0:
        address, query = u.path.split('?')
        pq = urllib.parse.parse_qs(query)
    else:
        pq = urllib.parse.parse_qs(u.query)

    for k, v in pq.items():
        if len(v) != 1:
            raise Exception('Duplicate Key', k)

    out = {k: v[0] for k, v in pq.items()}
    if address:
        if not is_address(address):
            raise BaseException("Invalid bitcoin address:" + address)
        out['address'] = address
    if 'amount' in out:
        am = out['amount']
        m = re.match('([0-9\.]+)X([0-9])', am)
        if m:
            k = int(m.group(2)) - 8
            amount = Decimal(m.group(1)) * pow(Decimal(10), k)
        else:
            amount = Decimal(am) * COIN
        out['amount'] = int(amount)
    if 'message' in out:
        out['message'] = out['message']
        out['memo'] = out['message']
    if 'time' in out:
        out['time'] = int(out['time'])
    if 'exp' in out:
        out['exp'] = int(out['exp'])
    if 'sig' in out:
        out['sig'] = bh2u(base_decode(out['sig'], None, base=58))

    r = out.get('r')
    sig = out.get('sig')
    name = out.get('name')
    if on_pr and (r or (name and sig)):
        import paymentrequest as pr
        if name and sig:
            s = pr.serialize_request(out).SerializeToString()
            request = pr.PaymentRequest(s)
        else:
            request = pr.get_payment_request(r)
        if on_pr:
            on_pr(request)

    return out