def block(bindex): bindex = bindex.strip() try: bindex = int(bindex) bhash = aspire.gasp('getblockhash', [bindex]) if 'data' not in bhash: raise Exception(bhash) bhash = bhash['data'] except ValueError: bhash = bindex block = aspire.gasp('getblock', [bhash]) bindex = block['data']['height'] transactions = block['data']['tx'] block_info = aspire.aspired('get_blocks', {'block_indexes': [bindex]}) if block_info.get('message', '') == 'Server error': flash('A server error occured!', 'danger') if block_info.get('data'): flash(block_info.get('data'), 'warning') return render_template('index.html') block_info = block_info['result'][0] return render_template('block.html', bindex=bindex, block_info=block_info, block=block)
def transaction(thash): thash = thash.strip() tx = aspire.aspired('getrawtransaction', params={ "tx_hash": thash, 'verbose': True }) tx = tx['result'] # tx_info = aspire.aspired('get_tx_info', params={'tx_hex': tx['result']['hex']}) if 'blockhash' in tx: block = aspire.gasp('getblock', params=[tx['blockhash']]) if 'data' in block: if 'height' in block['data']: tx['blockheight'] = block['data']['height'] blockheight = aspire.gasp('getblockcount') tx['confirmations'] = blockheight['data'] - tx['blockheight'] new_assets = aspire.aspired( 'get_issuances', params={"filters": [{ 'field': 'tx_hash', 'op': '==', 'value': thash }]}) sends = aspire.aspired( 'get_sends', params={"filters": [{ 'field': 'tx_hash', 'op': '==', 'value': thash }]}) dividends = aspire.aspired( 'get_dividends', params={"filters": [{ 'field': 'tx_hash', 'op': '==', 'value': thash }]}) broadcasts = aspire.aspired( 'get_broadcasts', params={"filters": [{ 'field': 'tx_hash', 'op': '==', 'value': thash }]}) return render_template('transaction.html', thash=thash, tx=tx, new_assets=new_assets, sends=sends, dividends=dividends, broadcasts=broadcasts)
def transfers(): try: page = int(request.args.get('page', 1)) - 1 except ValueError: page = 0 try: limit = int(request.args.get('size', 15)) if limit > 15: limit = 15 except ValueError: limit = 15 sends = aspire.aspired('get_sends', params={ 'order_by': 'block_index', 'order_dir': 'DESC', 'limit': limit, 'offset': page * limit }) if 'result' in sends: sends = sends['result'] else: sends = [] for send in sends: txdata = aspire.gasp('getrawtransaction', params=[send['tx_hash'], True]) send['time'] = txdata['data']['blocktime'] return {'data': add_asset_info(sends), 'last_page': page + 1}
def validate(self): term = str(self.search_term.data).strip() # Check for block number try: block_id = int(term) block_data = aspire.gasp('getblockhash', params=[block_id]) if block_data.get('success', False): self.is_block = True return True except ValueError: pass # Check for block hash block_data = aspire.gasp('getblock', params=[term]) if block_data.get('success', False): self.is_block = True return True # Check for txid txid = aspire.gasp('getrawtransaction', params=[term]) if txid.get('success', False): self.is_transaction = True return True # Check for address address = aspire.gasp('validateaddress', params=[term]) if address.get('success', False) and address.get('data', {}).get('isvalid', False): self.is_address = True return True # Check for asset assetinfo = aspire.aspired('get_asset_info', params={"assets": [term]}) if 'result' in assetinfo and len(assetinfo['result']) > 0: self.is_asset = True return True return True
def address_sends(address): try: page = int(request.args.get('page', 1)) - 1 except ValueError: page = 0 try: limit = int(request.args.get('size', 15)) if limit > 15: limit = 15 except ValueError: limit = 15 sends = aspire.aspired('get_sends', params={ 'order_by': 'block_index', 'order_dir': 'DESC', 'limit': limit, 'offset': page * limit, "filters": [{ 'field': 'destination', 'op': '==', 'value': address }, { 'field': 'source', 'op': '==', 'value': address }], "filterop": "or" }) if 'result' in sends: sends = sends['result'] else: sends = [] for send in sends: txdata = aspire.gasp('getrawtransaction', params=[send['tx_hash'], True]) send['time'] = txdata['data']['blocktime'] return {'data': add_asset_info(sends), 'last_page': page + 1}
def address_transactions(address): try: page = int(request.args.get('page', 1)) - 1 except ValueError: page = 0 try: limit = int(request.args.get('size', 15)) if limit > 100: limit = 100 except ValueError: limit = 15 # params in searchrawtransactions = [verbose, skip, limit] txdata = aspire.gasp('searchrawtransactions', params=[address, 1, page * limit, limit, int(True)]) if 'data' in txdata: return {'data': txdata['data'], 'last_page': page + 1} else: return txdata
def address_gasptxs(addy): try: page = int(request.args.get('page', 1)) - 1 except ValueError: page = 0 try: limit = int(request.args.get('size', 25)) if limit > 100: limit = 100 except ValueError: limit = 25 addy = addy.strip() gasptxs = aspire.gasp('searchrawtransactions', params=[addy, 1, page * limit, limit, int(True)]) return render_template('address/gasptxs.html', addy=addy, gasptxs=gasptxs, page=page + 1, limit=limit)
def address_issuances(address): try: page = int(request.args.get('page', 1)) - 1 except ValueError: page = 0 try: limit = int(request.args.get('size', 15)) if limit > 15: limit = 15 except ValueError: limit = 15 issuances = aspire.aspired('get_issuances', params={ 'order_by': 'block_index', 'order_dir': 'DESC', 'limit': limit, 'offset': page * limit, "filters": [{ 'field': 'issuer', 'op': '==', 'value': address }] }) if 'result' in issuances: issuances = issuances['result'] else: issuances = [] for send in issuances: txdata = aspire.gasp('getrawtransaction', params=[send['tx_hash'], True]) send['time'] = txdata['data']['blocktime'] return {'data': issuances, 'last_page': page + 1}
def block(bhash): block_data = aspire.gasp('getblock', params=[bhash, True]) if block_data.get('success', False): return {'data': block_data['data']} return {'data': {}}
def tx(txid): block_data = aspire.gasp('getrawtransaction', params=[txid, True]) if block_data.get('success', False): return {'data': block_data['data']} return {'data': block_data}