Ejemplo n.º 1
0
    def get_names(self, address):

        if not is_b58check_address(address):
            raise ValueError('"address" must be a valid cryptocurrency address')
        url = self.base_url + "/addresses/" + address + "/names"

        return self._get_request(url)
Ejemplo n.º 2
0
    def get_names(self, address):

        if not is_b58check_address(address):
            raise ValueError(
                '"address" must be a valid cryptocurrency address')
        url = self.base_url + "/addresses/" + address + "/names"

        return self._get_request(url)
Ejemplo n.º 3
0
def register_user():
    REGISTRATION_MESSAGE = ("This profile was registered using the Onename"
                            " API - https://api.onename.com")

    data = json.loads(request.data)

    username = data['username']

    user_lookup = api_user(username)

    if 'error' in user_lookup.data and user_lookup.status_code == 200:
        if 'profile' in data:
            zone_file = str(data['profile'])
            if isinstance(zone_file, dict):
                zone_file = json.dumps(zone_file)
        elif 'zone_file' in data:
            zone_file = str(data['zone_file'])
        else:
            zone_file = json.dumps({
                'status': 'registered',
                'message': REGISTRATION_MESSAGE
            })
    else:
        raise UsernameTakenError()

    if not isinstance(zone_file, str):
        raise InvalidZoneFileTypeError()

    if zone_file_is_too_big(zone_file):
        raise InvalidZoneFileSizeError()

    if not is_b58check_address(str(data['recipient_address'])):
        raise InvalidAddressError(data['recipient_address'])

    matching_records = Blockchainid.objects(username=username)

    if len(matching_records):
        """ Someone else already tried registering this name
            but the username is not yet registered on the blockchain.
            Don't tell the client that someone else's request is processing.
        """
        pass
    else:
        new_entry = Blockchainid(username=username,
                                 profile=zone_file,
                                 transfer_address=data['recipient_address'])
        try:
            new_entry.save()
        except Exception as e:
            raise DatabaseSaveError()

    resp = {'status': 'success'}

    return jsonify(resp), 200
Ejemplo n.º 4
0
def validAddress(address):

    try:
        validAddress = is_b58check_address(str(address))
    except Exception as e:
        log.debug(e)

    if validAddress:
        return True
    else:
        return False
Ejemplo n.º 5
0
 def register_user(self, username, address):
     if not isinstance(username, (str, unicode)):
         raise ValueError('"username" must be a string')
     if not is_b58check_address(address):
         raise ValueError('"address" must be a valid cryptocurrency address')
     url = self.base_url + "/users"
     payload = {
         'passname': username,
         'recipient_address': address
     }
     return self._post_request(url, payload)
Ejemplo n.º 6
0
    def register_user(self, username, address):

        if not isinstance(username, (str, unicode)):
            raise ValueError('"username" must be a string')

        if not is_b58check_address(address):
            raise ValueError(
                '"address" must be a valid cryptocurrency address')

        url = self.base_url + "/users"

        payload = {'username': username, 'recipient_address': address}

        return self._post_request(url, payload)
Ejemplo n.º 7
0
def get_address_names(addresses):

    resp = {}
    results = []

    addresses = addresses.split(',')

    for address in addresses:

        data = {}
        names_owned = []

        invalid_address = False

        try:
            is_b58check_address(str(address))
        except:
            data['error'] = "Invalid address"
            invalid_address = True

        if not invalid_address:
            bs_client = Proxy(BLOCKSTORED_IP, BLOCKSTORED_PORT)

            try:
                resp = bs_client.get_names_owned_by_address(address)
                names_owned = resp[0]
            except:
                pass

        data['address'] = address
        data['names'] = names_owned

        results.append(data)

    resp = {'results': results}

    return jsonify(resp), 200
Ejemplo n.º 8
0
def get_btc_address(profile):

    validAddress = False

    if 'bitcoin' in profile:

        try:
            btc_address = profile['bitcoin']
            btc_address = btc_address['address']
        except:
            pass

    try:
        validAddress = is_b58check_address(str(btc_address))
    except Exception as e:
        pass

    if validAddress:
        return btc_address
    else:
        return None
Ejemplo n.º 9
0
def get_btc_address(profile):

    validAddress = False

    if 'bitcoin' in profile:

        try:
            btc_address = profile['bitcoin']
            btc_address = btc_address['address']
        except:
            pass

    try:
        validAddress = is_b58check_address(str(btc_address))
    except Exception as e:
        pass

    if validAddress:
        return btc_address
    else:
        return None
Ejemplo n.º 10
0
def get_btc_address(profile):

    addressValid = False

    if "bitcoin" in profile:

        try:
            btc_address = profile["bitcoin"]
            btc_address = btc_address["address"]
        except:
            pass

    try:
        addressValid = is_b58check_address(str(btc_address))
    except Exception as e:
        pass

    if addressValid:
        return btc_address
    else:
        return None
Ejemplo n.º 11
0
def tests_for_update_and_transfer(fqu, transfer_address=None):
    """ Any update or transfer operation
        should pass these tests
    """

    if not nameRegistered(fqu):
        exit_with_error("%s is not registered yet." % fqu)

    payment_address, owner_address = get_addresses_from_file()

    if not ownerName(fqu, owner_address):
        exit_with_error("%s is not in your possession." % fqu)

    tx_fee_satoshi = approx_tx_fees(num_tx=1)
    tx_fee = satoshis_to_btc(tx_fee_satoshi)

    if not hasEnoughBalance(payment_address, tx_fee):
        msg = "Address %s doesn't have enough balance." % payment_address
        exit_with_error(msg)

    if dontuseAddress(payment_address):
        msg = "Address %s has pending transactions." % payment_address
        msg += " Wait and try later."
        exit_with_error(msg)

    if transfer_address is not None:

        try:
            resp = is_b58check_address(str(transfer_address))
        except:
            msg = "Address %s is not a valid Bitcoin address." % transfer_address
            exit_with_error(msg)

        if recipientNotReady(transfer_address):
            msg = "Address %s owns too many names already." % transfer_address
            exit_with_error(msg)
Ejemplo n.º 12
0
def transfer_user(username):

    reply = {}

    try:
        user = get_authenticated_user(request.authorization)
    except Exception as e:
        raise GenericError(str(e))

    try:
        hex_privkey = aes_decrypt(user.encrypted_privkey, SECRET_KEY)
    except Exception as e:
        raise GenericError(str(e))

    wallet = HDWallet(hex_privkey)
    data = json.loads(request.data)

    fqu = username + "." + DEFAULT_NAMESPACE
    transfer_address = data['transfer_address']
    owner_pubkey = data['owner_pubkey']

    try:
        blockchain_record = bs_client.get_name_blockchain_record(fqu)
    except Exception as e:
        raise GenericError(str(e))

    if 'value_hash' not in blockchain_record:
        raise GenericError("Not yet registered %s" % fqu)

    owner_address = blockchain_record['address']

    check_address = get_address_from_pubkey(str(owner_pubkey))

    if check_address != owner_address:
        raise GenericError("Given pubkey/address doesn't own this name.")

    if not is_b58check_address(transfer_address):
        raise InvalidAddressError(transfer_address)

    if USE_DEFAULT_PAYMENT and PAYMENT_PRIVKEY is not None:

        payment_privkey = BitcoinPrivateKey(PAYMENT_PRIVKEY)
        payment_privkey = payment_privkey.to_hex()
    else:
        pubkey, payment_privkey = wallet.get_next_keypair()

        if payment_privkey is None:
            raise PaymentError(
                addresses=wallet.get_keypairs(DEFAULT_CHILD_ADDRESSES))

    resp = {}

    try:
        resp = bs_client.transfer_subsidized(fqu,
                                             transfer_address,
                                             keep_data=True,
                                             public_key=owner_pubkey,
                                             subsidy_key=payment_privkey)
    except Exception as e:
        reply['error'] = str(e)
        return jsonify(reply), 200

    if 'subsidized_tx' in resp:
        reply['unsigned_tx'] = resp['subsidized_tx']
    else:
        if 'error' in resp:
            reply['error'] = resp['error']
        else:
            reply['error'] = resp

    return jsonify(reply), 200