Ejemplo n.º 1
0
def post_addresses_unspent(addresses_hash):
    start = None

    if not check_if_address_post_key_is_valid(addresses_hash):
        return "Bad post request", 400

    addresses_hash_no_json = addresses_hash['addresses']
    if 'start' in addresses_hash:
        start = addresses_hash['start']
        if start and (not isinstance(start, int)):
            return "Start too large", 400

    for address_hash in addresses_hash_no_json:
        if not validate_address(address_hash):
            return "Invalid address hash", 400

    unspent = db.post_addresses_unspent(addresses_hash_no_json,
                                        start,
                                        limit=50)

    if len(unspent) == 50:
        last_unspent_transaction = unspent[len(unspent) - 1]

        return {
            "next": last_unspent_transaction['blocktime'],
            "addresses": addresses_hash['addresses'],
            "utxo":
            [UnspentTransactionSerializer.to_web(tr) for tr in unspent]
        }

    return {
        "addresses": addresses_hash_no_json,
        "utxo": [UnspentTransactionSerializer.to_web(tr) for tr in unspent],
        "next": None
    }
Ejemplo n.º 2
0
def get_address_unspent(address_hash, start=None):
    if not validate_address(address_hash):
        return "Invalid address hash", 400
    if start and (not isinstance(start, int)):
        return "Start too large", 400

    unspent = db.get_address_unspent(address_hash, start, limit=50)
    if unspent:
        unspent_transaction_address = unspent[0]['vout']['addresses'][0]
    else:
        unspent_transaction_address = unspent

    if len(unspent) == 50:
        last_unspent_transaction = unspent[len(unspent) - 1]
        return {
            "next":
            "/addresses/%s/unspent?start=%s" %
            (address_hash, last_unspent_transaction['blocktime']),
            "address":
            unspent_transaction_address,
            "utxo":
            [UnspentTransactionSerializer.to_web(tr) for tr in unspent]
        }

    return {
        "address": unspent_transaction_address,
        "utxo": [UnspentTransactionSerializer.to_web(tr) for tr in unspent],
        "next": None
    }
Ejemplo n.º 3
0
def post_addresses_transactions(addresses_hash):
    # Start must be declared None, in case that start doesn't
    # exist in the post body
    start = None

    if not check_if_address_post_key_is_valid(addresses_hash):
        return "Bad post request", 400

    addresses_hash_no_json = addresses_hash['addresses']

    for address_hash in addresses_hash_no_json:
        if not validate_address(address_hash):
            return "Invalid address hash", 400

    if 'start' in addresses_hash:
        start = addresses_hash['start']
        if start and (not isinstance(start, int)):
            return "Start too large", 400

    trs = db.post_addresses_transactions(addresses_hash_no_json,
                                         start,
                                         limit=50)

    if len(trs) == 50:
        last_transaction = trs[len(trs) - 1]
        return {
            "transactions": [TransactionSerializer.to_web(tr) for tr in trs],
            "next": last_transaction['blocktime']
        }
    else:
        return {
            "transactions": [TransactionSerializer.to_web(tr) for tr in trs],
            "next": None
        }
Ejemplo n.º 4
0
def post_addresses_balance(addresses_hash):
    if not check_if_address_post_key_is_valid(addresses_hash):
        return "Bad post request", 400

    addresses_hash_no_json = addresses_hash['addresses']

    for address_hash in addresses_hash_no_json:
        if not validate_address(address_hash):
            return "Invalid address hash", 400

    balance = db.post_addresses_balance(addresses_hash_no_json)
    return BalanceSerializer.to_web(addresses_hash_no_json, balance)
Ejemplo n.º 5
0
def post_addresses_num_transactions(addresses_hash):

    if not check_if_address_post_key_is_valid(addresses_hash):
        return "Bad post request", 400

    addresses_hash_no_json = addresses_hash['addresses']
    for address_hash in addresses_hash_no_json:
        if not validate_address(address_hash):
            return "Invalid address hash", 400

    tr_count = db.post_addresses_num_transactions(addresses_hash_no_json)
    return TransactoinCountSerializer.to_web(addresses_hash_no_json, tr_count)
Ejemplo n.º 6
0
def post_addresses_volume(addresses_hash):

    if not check_if_address_post_key_is_valid(addresses_hash):
        return "Bad post request", 400

    addresses_hash_no_json = addresses_hash['addresses']

    for address_hash in addresses_hash_no_json:
        if not validate_address(address_hash):
            return "Invalid address hash", 400

    total_volume = db.post_addresses_volume(addresses_hash_no_json)
    return VolumeSerializer.to_web(addresses_hash_no_json, total_volume)
Ejemplo n.º 7
0
def get_address_transactions(address_hash, start=None):
    if start and (not isinstance(start, int)):
        return "Start too large", 400
    if not validate_address(address_hash):
        return "Invalid address hash", 400
    trs = db.get_address_transactions(address_hash, start, limit=51)

    if len(trs) == 51:
        last_transaction = trs[len(trs) - 1]
        return {
            "transactions": [TransactionSerializer.to_web(tr) for tr in trs],
            "next":
            "/addresses/%s?start=%s" %
            (address_hash, last_transaction['blocktime'])
        }
    else:
        return {
            "transactions": [TransactionSerializer.to_web(tr) for tr in trs],
            "next": None
        }
Ejemplo n.º 8
0
def get_address_balance(address_hash):
    if not validate_address(address_hash):
        return "Invalid address hash", 400
    balance = db.get_address_balance(address_hash)
    return BalanceSerializer.to_web(address_hash, balance)
Ejemplo n.º 9
0
def get_address_unspent(address_hash):
    if not validate_address(address_hash):
        return "Invalid address hash", 400
    unspent = db.get_address_unspent(address_hash)
    return unspent
Ejemplo n.º 10
0
def get_address_volume(address_hash):
    if not validate_address(address_hash):
        return "Invalid address hash", 400
    volume = db.get_address_volume(address_hash)
    return VolumeSerializer.to_web(address_hash, volume)
Ejemplo n.º 11
0
def get_address_num_transactions(address_hash):
    if not validate_address(address_hash):
        return "Invalid address hash", 400
    tr_count = db.get_address_num_transactions(address_hash)
    return TransactoinCountSerializer.to_web(address_hash, tr_count)