Esempio n. 1
0
 def __init__(self, config):
     StoreDict.__init__(self, config, 'contacts')
     # backward compatibility
     for k, v in self.items():
         _type, n = v
         if _type == 'address' and stratis.is_address(n):
             self.pop(k)
             self[n] = ('address', k)
Esempio n. 2
0
 def getprivatekeys(self, address):
     """Get private keys of addresses. You may pass a single wallet address, or a list of wallet addresses."""
     if is_address(address):
         return self.wallet.get_private_key(address, self._password)
     domain = json_loads(address)
     return [
         self.wallet.get_private_key(address, self._password)
         for address in domain
     ]
Esempio n. 3
0
 def resolve(self, k):
     if stratis.is_address(k):
         return {'address': k, 'type': 'address'}
     if k in self.keys():
         _type, addr = self[k]
         if _type == 'address':
             return {'address': addr, 'type': 'contact'}
     out = self.resolve_openalias(k)
     if out:
         address, name, validated = out
         return {
             'address': address,
             'name': name,
             'type': 'openalias',
             'validated': validated
         }
     raise Exception("Invalid Stratis address or alias", k)
Esempio n. 4
0
def create_URI(addr, amount, message):
    import stratis
    if not stratis.is_address(addr):
        return ""
    query = []
    if amount:
        query.append('amount=%s' % format_satoshis_plain(amount))
    if message:
        if type(message) == unicode:
            message = message.encode('utf8')
        query.append('message=%s' % urllib.quote(message))
    p = urlparse.ParseResult(scheme='stratis',
                             netloc='',
                             path=addr,
                             params='',
                             query='&'.join(query),
                             fragment='')
    return urlparse.urlunparse(p)
Esempio n. 5
0
def parse_URI(uri, on_pr=None):
    import stratis
    from stratis import COIN

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

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

    # python for android fails to parse query
    if address.find('?') > 0:
        address, query = u.path.split('?')
        pq = urlparse.parse_qs(query)
    else:
        pq = urlparse.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 stratis.is_address(address):
            raise BaseException("Invalid stratis 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'].decode('utf8')
        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'] = stratis.base_decode(out['sig'], None,
                                         base=58).encode('hex')

    r = out.get('r')
    sig = out.get('sig')
    name = out.get('name')
    if r or (name and sig):

        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)

        t = threading.Thread(target=get_payment_request_thread)
        t.setDaemon(True)
        t.start()

    return out
Esempio n. 6
0
 def validateaddress(self, address):
     """Check that an address is valid. """
     return is_address(address)
Esempio n. 7
0
def is_address_list(text):
    parts = text.split()
    return bool(parts) and all(stratis.is_address(x) for x in parts)