Example #1
0
def address_info(address):
    with db.new_session() as session:
        with QueryDataPostProcessor() as pp:
            info = session.address_info(address)
            if info == None:
                return make404()

            info['mutations'] = pp.get_reflink_object('/address/' + address + '/mutations/')
            info['utxos'] = pp.get_reflink_object_or_data('/address/' + address + '/utxos/', 'utxos', lambda: session.address_utxos(address, limit=pp.MAX_OBJECTS_PER_PAGE))

            # FIXME: Move this some place else?
            if ADDRESS_TRANSLATIONS is not None and 'address' in info and info['address'] is not None:
                aliases = []
                try:
                    address_type, address_version, pubkeyhash = decode_any_address(info['address'])
                    for translation in ADDRESS_TRANSLATIONS.items():
                        if translation[1] == (address_type, address_version):
                            try:
                                aliases.append(encode_address(translation[0][0], translation[0][1], pubkeyhash))
                            except ValueError:
                                pass
                    info['aliases'] = aliases
                except ValueError:
                    pass

            return pp.process_raw(info).json()
Example #2
0
def address_info(address):
    with db.new_session() as session:
        with QueryDataPostProcessor() as pp:
            info = session.address_info(address)
            if info == None:
                return make404()

            info['mutations'] = {
                'href':
                QueryDataPostProcessor.API_ENDPOINT + '/address/' + address +
                '/mutations/'
            }

            # FIXME: Move this some place else?
            if ADDRESS_TRANSLATIONS is not None and 'address' in info and info[
                    'address'] is not None:
                aliases = []
                try:
                    address_type, address_version, pubkeyhash = decode_any_address(
                        info['address'])
                    for translation in ADDRESS_TRANSLATIONS.items():
                        if translation[1] == (address_type, address_version):
                            try:
                                aliases.append(
                                    encode_address(translation[0][0],
                                                   translation[0][1],
                                                   pubkeyhash))
                            except ValueError:
                                pass
                    info['aliases'] = aliases
                except ValueError:
                    pass

            return pp.process_raw(info).json()
Example #3
0
def transactions():
    with db.new_session() as session:
        with QueryDataPostProcessor() as pp:
            pp.pagination()
            pp.baseurl('/transactions/<Transaction.txid>/')
            pp.reflinks('mutations', 'inputs', 'outputs')
            pp.reflink('block', '/blocks/<query:transaction.block.hash>/',
                       ['hash', 'height'])
            pp.reflink('miner', '/blocks/<query:transaction.block.hash>/miner')
            pp.autoexpand()
            pp.reflink('transactions',
                       '/blocks/<query:transaction.block.hash>/transactions/')

            query_confirmed = request.args.get('confirmed')
            if query_confirmed is None or query_confirmed == '':
                data = session.latest_transactions(limit=pp.limit)
            elif query_confirmed == 'true':
                data = session.latest_transactions(limit=pp.limit,
                                                   confirmed_only=True)
            elif query_confirmed == 'false':
                data = session.mempool()
            else:
                data = []

            return pp.process(data).json()
Example #4
0
def transaction_output(txid, index):
    with db.new_session() as session:
        with QueryDataPostProcessor() as pp:
            transaction = session.transaction(txid, include_confirmation_info=False)
            if transaction == None:
                return make404()

            return pp.process_raw(transaction.outputs[int(index)]).json()
Example #5
0
def transaction_mutations(txid):
    with db.new_session() as session:
        with QueryDataPostProcessor() as pp:
            transaction = session.transaction(txid, include_confirmation_info=False)
            if transaction == None:
                return make404()

            return pp.process_raw(transaction.mutations).json()
Example #6
0
def network_coin_stats():
    since = datetime.fromtimestamp(int(request.args.get('since') or 0))
    with db.new_session() as session:
        with QueryDataPostProcessor() as pp:
            data = pp.process_raw(session.network_stats(since=since, ignore=['blocks', 'totalfees', 'transactions', 'transactedvalue', 'coindaysdestroyed'])).data
            return pp.process_raw({
                'released':     data['coinsreleased']
            }).json()
Example #7
0
def address_pending(address):
    with db.new_session() as session:
        with QueryDataPostProcessor() as pp:
            pending_balance = session.address_pending_balance(address)
            if pending_balance == None:
                return make404()

            return pp.process_raw(pending_balance).json()
Example #8
0
def network_transaction_stats():
    since = datetime.fromtimestamp(int(request.args.get('since') or 0))
    with db.new_session() as session:
        with QueryDataPostProcessor() as pp:
            data = pp.process_raw(session.transaction_stats(since=since)).data
            return pp.process_raw({
                'amount': data['transactions'],
                'totalvalue': data['transactedvalue']
            }).json()
Example #9
0
def address_mutations(address):
    with db.new_session() as session:
        with QueryDataPostProcessor() as pp:
            pp.pagination()

            mutations = session.address_mutations(address, confirmed=param_true('confirmed'), start=pp.start, limit=pp.limit)
            for mutation in mutations:
                mutation['transaction'] = _make_transaction_ref(mutation['txid'])
                del mutation['txid']

            return pp.process_raw(mutations).json()
Example #10
0
def blockminer(blockid):
    with db.new_session() as session:
        with QueryDataPostProcessor() as pp:
            pp.resolve_keys(Block.miner)
            pp.reflink('block', '/blocks/<query:transaction.block.hash>/', ['hash', 'height'])

            block = session.block(blockid)
            if block == None:
                return make404()

            return pp.process(block)['miner'].json()
Example #11
0
def blocks():
    with db.new_session() as session:
        with QueryDataPostProcessor() as pp:
            pp.pagination(backwards_indexes=True, tipresolver=(lambda: session.chaintip().height + 1), allow_interval=True)
            pp.baseurl('/blocks/<Block.hash>/')
            pp.reflinks('miner', 'transactions')
            pp.reflink('mutations', '/transactions/<Transaction.txid>/mutations')
            pp.reflink('inputs', '/transactions/<Transaction.txid>/inputs')
            pp.reflink('outputs', '/transactions/<Transaction.txid>/outputs')
            pp.reflink('coinbase', '/transactions/<Transaction.txid>/coinbase')
            pp.autoexpand()
            pp.reflink('block', '/blocks/<query:transaction.block.hash>/', ['hash', 'height'])
            return pp.process(session.blocks(pp.start, pp.limit, pp.interval)).json()
Example #12
0
def transaction(txid):
    with db.new_session() as session:
        with QueryDataPostProcessor() as pp:
            pp.baseurl('/transactions/<Transaction.txid>/')
            pp.reflinks('mutations', 'inputs', 'outputs', 'coinbase')
            pp.reflink('block', '/blocks/<query:transaction.block.hash>/', ['hash', 'height'])
            pp.reflink('miner', '/blocks/<query:transaction.block.hash>/miner')
            pp.autoexpand()
            pp.reflink('transactions', '/blocks/<query:transaction.block.hash>/transactions/')

            transaction = session.transaction(txid, include_confirmation_info=True)
            if transaction == None:
                return make404()

            return pp.process(transaction).json()
Example #13
0
def blocktransactions(blockid):
    with db.new_session() as session:
        with QueryDataPostProcessor() as pp:
            pp.reflink('mutations', '/transactions/<Transaction.txid>/mutations')
            pp.reflink('inputs', '/transactions/<Transaction.txid>/inputs')
            pp.reflink('outputs', '/transactions/<Transaction.txid>/outputs')
            pp.reflink('coinbase', '/transactions/<Transaction.txid>/coinbase')
            pp.autoexpand()
            pp.resolve_keys('Block.transactions', 'Transaction.block', 'Transaction.mutations', 'Transaction.inputs', 'Transaction.outputs', 'Transaction.coinbase')
            pp.reflink('block', '/blocks/<query:transaction.block.hash>/', ['hash', 'height'])

            block = session.block(blockid)
            if block == None:
                return make404()

            return pp.process(block)['transactions'].json()
Example #14
0
def block(blockid):
    with db.new_session() as session:
        with QueryDataPostProcessor() as pp:
            pp.baseurl('/blocks/<Block.hash>/')
            pp.reflinks('miner', 'transactions')
            pp.reflink('mutations',
                       '/transactions/<Transaction.txid>/mutations')
            pp.reflink('inputs', '/transactions/<Transaction.txid>/inputs')
            pp.reflink('outputs', '/transactions/<Transaction.txid>/outputs')
            pp.autoexpand()
            pp.reflink('block', '/blocks/<query:transaction.block.hash>/',
                       ['hash', 'height'])

            block = session.block(blockid)
            if block == None:
                return make404()

            return pp.process(block).json()
Example #15
0
def total_coins_in_addresses():
    with db.new_session() as session:
        with QueryDataPostProcessor() as pp:
            return pp.process_raw(float(
                session.total_coins_in_addresses())).json()
Example #16
0
def total_coins():
    with db.new_session() as session:
        with QueryDataPostProcessor() as pp:
            return pp.process_raw(session.total_coins_info())['total'].json()
Example #17
0
def richlist():
    with db.new_session() as session:
        with QueryDataPostProcessor() as pp:
            pp.pagination()
            return pp.process_raw(
                session.richlist(start=pp.start, limit=pp.limit)).json()
Example #18
0
def poolstats():
    since = datetime.fromtimestamp(int(request.args.get('since')))
    with db.new_session() as session:
        with QueryDataPostProcessor() as pp:
            return pp.process_raw(session.pool_stats(since=since)).json()
Example #19
0
def total_transactions():
    since = datetime.fromtimestamp(int(request.args.get('since') or 0))
    with db.new_session() as session:
        with QueryDataPostProcessor() as pp:
            return pp.process_raw(
                session.total_transactions_since(since=since)).json()
Example #20
0
def address_utxos(address):
    with db.new_session() as session:
        with QueryDataPostProcessor() as pp:
            pp.pagination(default_limit=pp.MAX_OBJECTS_PER_PAGE)
            utxos = session.address_utxos(address, confirmed=param_true('confirmed'), start=pp.start, limit=pp.limit)
            return pp.process_raw(utxos).json()
Example #21
0
def transactions_coindays_stats():
    since = datetime.fromtimestamp(int(request.args.get('since') or 0))
    interval = int(request.args.get('interval') or 0)
    with db.new_session() as session:
        with QueryDataPostProcessor() as pp:
            return pp.process_raw(session.coindays_destroyed(since=since, interval=interval if interval > 0 else None)).json()