def requeststat_aspx(): #print request.args args=request.args if 'stat' not in args: return jsonify({"error":"invalid request"}) stat=args['stat'] if stat=='balance': if 'prop' not in args or 'address' not in args: return jsonify({"error":"invalid request"}) prop=args['prop'] address=args['address'] #if is_valid_bitcoin_address(address): #jsonify encapsulates in a string, just return number return balance_propid(address,prop) #else: # return jsonify({"error":"invalid address"}) elif stat=='gettx': if 'txid' not in args: return jsonify({"error":"invalid request, missing txid"}) #weird formatting, to match legacy oe need to remove curly brackets return json.dumps(gettxjson(args['txid']))[1:][:-1] elif stat=='getblocktx': if 'block' not in args: return jsonify({"error":"invalid request, missing block"}) return jsonify(getblocktxjson(args['block'])) else: return jsonify({"error":"unsupported call","args": args })
def search(): try: query = re.sub(r'\W+', '', request.form['query']) # strip and get query except: return jsonify({ 'status': 400, 'data': 'Invalid/No query found in request' }) ckey = "data:search:" + str(query) print "ckey", ckey try: response = json.loads(lGet(ckey)) print("redis-response:", response) print_debug(("cache looked success", ckey), 7) except: print_debug(("cache looked failed", ckey), 7) asset = [] adrbal = {} txj = {} if query.isdigit(): if int(query) == 2: asset = dbSelect( "select PropertyID, propertyname,Issuer,flags from smartproperties where ecosystem='Test' and protocol='Omni' order by propertyid" ) elif int(query) == 1: asset = dbSelect( "select PropertyID, propertyname,Issuer,flags from smartproperties where ecosystem='Production' and protocol='Omni' order by propertyid" ) else: asset = dbSelect( "select PropertyID, propertyname,Issuer,flags from smartproperties where PropertyID = %s and protocol='Omni' order by propertyid limit 10", [str(query)]) else: wq = '%' + str(query) + '%' asset = dbSelect( "select PropertyID, propertyname,Issuer,flags from smartproperties where (LOWER(PropertyName) like LOWER(%s) or LOWER(issuer) like LOWER(%s)) and protocol='Omni' order by propertyid limit 10", (wq, wq)) if 25 < len(query) < 45: adrbal = balance_full(query) elif len(query) == 64: txj = gettxjson(query) else: pass response = { 'status': 200, 'query': query, 'data': { 'tx': txj, 'address': adrbal, 'asset': asset } } #cache for 5 min lSet(ckey, json.dumps(response)) lExpire(ckey, 300) print("before return response", response) return jsonify(response)
def ask_aspx(): print_debug(request.args,4) args=request.args if "api" not in args: return jsonify({"error":"invalid request"}) api=args['api'] #getbalance prop, address Requests the available balance for a given property ID and address if api=="getbalance": if 'prop' not in args or 'address' not in args: return jsonify({"error":"invalid request"}) prop=args['prop'] address=args['address'] #if is_valid_bitcoin_address(address): #jsonify encapsulates in a string, just return number return balance_propid(address,prop) #else: # return jsonify({"error":"invalid address"}) #getreservedbalance prop, address Requests the reserved balance for a given property ID and address #getpropertybalances prop Requests the balances of all addresses holding tokens of a given property ID elif api=="getpropertybalances": if 'prop' not in args: return jsonify({"error":"invalid request, missing prop"}) #weird formatting, to match legacy oe need to remove curly brackets return jsonify(getpropdistraw(args['prop'])) #gettx txid Requests the transaction details for a given transaction ID elif api=="gettx": if 'txid' not in args: return jsonify({"error":"invalid request, missing txid"}) #weird formatting, to match legacy oe need to remove curly brackets return json.dumps(gettxjson(args['txid']))[1:][:-1] #gettxvalidity txid Requests the validity of a given transaction ID elif api=="gettxvalidity": if 'txid' not in args: return jsonify({"error":"invalid request, missing txid"}) #weird formatting, to match legacy oe need to remove curly brackets return json.dumps(gettxjson(args['txid'])['valid'])[1:][:-1] #gettxblock txid Requests the block number for a given transaction ID elif api=="gettxblock": if 'txid' not in args: return jsonify({"error":"invalid request, missing txid"}) #weird formatting, to match legacy oe need to remove curly brackets return json.dumps(gettxjson(args['txid'])['block']) #gettxconfirmations txid Requests the number of confirmations for a given transaction ID elif api=="gettxconfirmations": if 'txid' not in args: return jsonify({"error":"invalid request, missing txid"}) #weird formatting, to match legacy oe need to remove curly brackets return json.dumps(gettxjson(args['txid'])['confirmations'])[1:][:-1] #getblocktx block Requests the transaction details for all Omni Layer transactions in a given block elif api=="getblocktx": if 'block' not in args: return jsonify({"error":"invalid request, missing block"}) return jsonify(getblocktxjson(args['block'])) #getlastblockprocessed - Requests the last block processed by OmniExplorer.info elif api=="getlastblockprocessed": return json.dumps(raw_revision()['last_block']) #gethistory address Requests the historical transactions for a given address elif api=="gethistory": if 'address' not in args: return jsonify({"error":"invalid request"}) address=args['address'] #if is_valid_bitcoin_address(address): return jsonify( getaddrhist(address,'both')) #else: # return jsonify({"error":"invalid address"}) #getsenderhistory address Requests the historical transactions sent from a given address elif api=="getsenderhistory": if 'address' not in args: return jsonify({"error":"invalid request"}) address=args['address'] #if is_valid_bitcoin_address(address): return jsonify( getaddrhist(address,'send')) #else: # return jsonify({"error":"invalid address"}) #getrecipienthistory address Requests the historical transactions received by a given address elif api=="getrecipienthistory": if 'address' not in args: return jsonify({"error":"invalid request"}) address=args['address'] #if is_valid_bitcoin_address(address): return jsonify( getaddrhist(address,'receive')) #else: # return jsonify({"error":"invalid address"}) #getpropertyname prop Requests the display name for a given property ID elif api=="getpropertyname": try: if 'prop' not in args: raise "missing arg" pid=args['prop'] raw=getpropertyraw(pid) return raw['name'] except Exception, e: print_debug("getpropertyname error: "+str(e),4) return jsonify({"error":"invalid request"})