From b4f65f0d7291e04c9ef1017ceb37274f3bb68ef6 Mon Sep 17 00:00:00 2001 From: Vivek Teega Date: Sun, 6 Oct 2019 06:17:54 +0530 Subject: [PATCH] Adding limit parameter to view all block details --- ranchimallflo_api.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/ranchimallflo_api.py b/ranchimallflo_api.py index 0a3f168..67e71b1 100644 --- a/ranchimallflo_api.py +++ b/ranchimallflo_api.py @@ -702,7 +702,7 @@ async def getLatestTransactionDetails(): tx_parsed_details['transactionDetails']['blockheight'] = int(item[2]) tempdict.append(tx_parsed_details) else: - c.execute('''SELECT * FROM latestTransactions WHERE blockNumber IN (SELECT DISTINCT blockNumber FROM latestTransactions ORDER BY blockNumber DESC LIMIT 10) ORDER BY id ASC;''') + c.execute('''SELECT * FROM latestTransactions WHERE blockNumber IN (SELECT DISTINCT blockNumber FROM latestTransactions ORDER BY blockNumber DESC LIMIT 100) ORDER BY id ASC;''') latestTransactions = c.fetchall() c.close() tempdict = [] @@ -719,13 +719,21 @@ async def getLatestTransactionDetails(): @app.route('/api/v1.0/getLatestBlockDetails', methods=['GET']) async def getLatestBlockDetails(): + + limit = request.args.get('limit') + int(limit) + dblocation = dbfolder + '/latestCache.db' if os.path.exists(dblocation): conn = sqlite3.connect(dblocation) c = conn.cursor() else: return 'Latest transactions db doesn\'t exist. This is unusual, please report on https://github.com/ranchimall/ranchimallflo-api' - c.execute('''SELECT * FROM ( SELECT * FROM latestBlocks ORDER BY blockNumber DESC LIMIT 4) ORDER BY id ASC;''') + + if limit is None: + c.execute('''SELECT * FROM ( SELECT * FROM latestBlocks ORDER BY blockNumber DESC LIMIT 4) ORDER BY id ASC;''') + else: + c.execute('SELECT * FROM ( SELECT * FROM latestBlocks ORDER BY blockNumber DESC LIMIT {}) ORDER BY id ASC;'.format(limit)) latestBlocks = c.fetchall() c.close() tempdict = []