From d520da7c68426c1ecf73ca1f9b59b476bc041730 Mon Sep 17 00:00:00 2001 From: Vivek Teega Date: Wed, 29 May 2019 11:40:25 +0530 Subject: [PATCH] Adding gettokenbalances API --- ranchimallflo_api.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/ranchimallflo_api.py b/ranchimallflo_api.py index df124f1..ec8ce24 100644 --- a/ranchimallflo_api.py +++ b/ranchimallflo_api.py @@ -108,6 +108,32 @@ def gettransactions(): return jsonify(result='ok', transactions=rowarray_list) +@app.route('/api/v1.0/gettokenbalances', methods=['GET']) +def gettokenbalances(): + token = request.args.get('token') + if token is None: + return jsonify(result='error') + + dblocation = dbfolder + '/tokens/' + str(token) + '.db' + if os.path.exists(dblocation): + conn = sqlite3.connect(dblocation) + c = conn.cursor() + else: + return 'Token doesn\'t exist' + c.execute('SELECT address,SUM(transferBalance) FROM activeTable GROUP BY address') + addressBalances = c.fetchall() + + returnList = [] + + for address in addressBalances: + tempdict = {} + tempdict['address'] = address[0] + tempdict['balance'] = address[1] + returnList.append(tempdict) + + return jsonify(result='ok', balances=returnList) + + # SMART CONTRACT APIs @app.route('/api/v1.0/getsmartContractlist', methods=['GET'])