From e61ac5fc91259d28e927e70ab4b025f6c9b8a01c Mon Sep 17 00:00:00 2001 From: Vivek Teega Date: Fri, 4 Oct 2019 20:58:26 +0530 Subject: [PATCH] Adding more parameters to getBlockDetails --- ranchimallflo_api.py | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/ranchimallflo_api.py b/ranchimallflo_api.py index 35ba6a1..7fe1978 100644 --- a/ranchimallflo_api.py +++ b/ranchimallflo_api.py @@ -552,15 +552,27 @@ async def getsmartcontracttransactions(): return jsonify(result='error', details='Smart Contract with the given name doesn\'t exist') -@app.route('/api/v1.0/getBlockDetails/', methods=['GET']) -async def getblockdetails(blockno): - blockhash = requests.get('{}block-index/{}'.format(apiUrl,blockno)) - blockhash = json.loads(blockhash.content) +@app.route('/api/v1.0/getBlockDetails', methods=['GET']) +async def getblockdetails(): + blockHash = request.args.get('blockHash') + blockHeight = request.args.get('blockHeight') - blockdetails = requests.get('{}block/{}'.format(apiUrl,blockhash['blockHash'])) - blockdetails = json.loads(blockdetails.content) + if blockHash is None and blockHeight is None: + return jsonify(result='error', details='Pass either blockHash or blockHeight') - return jsonify(blockdetails=blockdetails, blockno=blockno) + elif blockHash is not None and blockHeight is not None: + return jsonify(result='error', details='Pass either blockHash or blockHeight. Not both.') + elif blockHash: + blockdetails = requests.get('{}block/{}'.format(apiUrl,blockHash)) + blockdetails = json.loads(blockdetails.content) + return jsonify(blockDetails=blockdetails, blockHash=blockHash) + elif blockHeight: + blockhash = requests.get('{}block-index/{}'.format(apiUrl,blockHeight)) + blockhash = json.loads(blockhash.content) + + blockdetails = requests.get('{}block/{}'.format(apiUrl,blockhash['blockHash'])) + blockdetails = json.loads(blockdetails.content) + return jsonify(blockDetails=blockdetails, blockHeight=blockHeight) @app.route('/api/v1.0/getTransactionDetails/', methods=['GET']) @@ -646,6 +658,7 @@ async def gettransactiondetails(transactionHash): elif parseResult["type"] == "smartContractPays": print('smart contract pays') + return jsonify(parsedFloData=parseResult, transactionDetails=transactionDetails, transactionHash=transactionHash)