Accomodating for extra column blockheight in the db
This commit is contained in:
parent
0c2b5f30a8
commit
3f8aa20fff
@ -535,26 +535,42 @@ async def getVscoutDetails():
|
|||||||
|
|
||||||
@app.route('/api/v1.0/getLatestTransactionDetails', methods=['GET'])
|
@app.route('/api/v1.0/getLatestTransactionDetails', methods=['GET'])
|
||||||
async def getLatestTransactionDetails():
|
async def getLatestTransactionDetails():
|
||||||
|
|
||||||
|
numberOfLatestBlocks = request.args.get('numberOfLatestBlocks')
|
||||||
|
|
||||||
dblocation = dbfolder + '/latestCache.db'
|
dblocation = dbfolder + '/latestCache.db'
|
||||||
if os.path.exists(dblocation):
|
if os.path.exists(dblocation):
|
||||||
conn = sqlite3.connect(dblocation)
|
conn = sqlite3.connect(dblocation)
|
||||||
c = conn.cursor()
|
c = conn.cursor()
|
||||||
else:
|
else:
|
||||||
return 'Latest transactions db doesn\'t exist. This is unusual, please report on https://github.com/ranchimall/ranchimallflo-api'
|
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 latestTransactions ORDER BY id DESC LIMIT 10) ORDER BY id ASC;''')
|
|
||||||
latestTransactions = c.fetchall()
|
if numberOfLatestBlocks is not None:
|
||||||
c.close()
|
c.execute('SELECT * FROM latestTransactions WHERE blockNumber IN (SELECT blockNumber FROM latestBlocks ORDER BY blockNumber DESC LIMIT {}) ORDER BY id ASC;'.format(int(numberOfLatestBlocks)))
|
||||||
tempdict = []
|
latestTransactions = c.fetchall()
|
||||||
for idx, item in enumerate(latestTransactions):
|
c.close()
|
||||||
item = list(item)
|
tempdict = []
|
||||||
tx_parsed_details = {}
|
for idx, item in enumerate(latestTransactions):
|
||||||
tx_parsed_details['transactionDetails'] = json.loads(item[2])
|
item = list(item)
|
||||||
tx_parsed_details['parsedFloData'] = json.loads(item[4])
|
tx_parsed_details = {}
|
||||||
tx_parsed_details['parsedFloData']['transactionType'] = item[3]
|
tx_parsed_details['transactionDetails'] = json.loads(item[3])
|
||||||
response = requests.get('{}block/{}'.format(apiUrl,tx_parsed_details['transactionDetails']['blockhash']))
|
tx_parsed_details['parsedFloData'] = json.loads(item[5])
|
||||||
response = json.loads(response.content)
|
tx_parsed_details['parsedFloData']['transactionType'] = item[4]
|
||||||
tx_parsed_details['transactionDetails']['blockheight'] = response['height']
|
tx_parsed_details['transactionDetails']['blockheight'] = int(item[2])
|
||||||
tempdict.append(tx_parsed_details)
|
tempdict.append(tx_parsed_details)
|
||||||
|
else:
|
||||||
|
c.execute('''SELECT * FROM latestTransactions WHERE blockNumber IN (SELECT blockNumber FROM latestBlocks ORDER BY blockNumber DESC LIMIT 10) ORDER BY id ASC;''')
|
||||||
|
latestTransactions = c.fetchall()
|
||||||
|
c.close()
|
||||||
|
tempdict = []
|
||||||
|
for idx, item in enumerate(latestTransactions):
|
||||||
|
item = list(item)
|
||||||
|
tx_parsed_details = {}
|
||||||
|
tx_parsed_details['transactionDetails'] = json.loads(item[3])
|
||||||
|
tx_parsed_details['parsedFloData'] = json.loads(item[5])
|
||||||
|
tx_parsed_details['parsedFloData']['transactionType'] = item[4]
|
||||||
|
tx_parsed_details['transactionDetails']['blockheight'] = int(item[2])
|
||||||
|
tempdict.append(tx_parsed_details)
|
||||||
return jsonify(result='ok', latestTransactions=tempdict, temp=item)
|
return jsonify(result='ok', latestTransactions=tempdict, temp=item)
|
||||||
|
|
||||||
|
|
||||||
@ -566,7 +582,7 @@ async def getLatestBlockDetails():
|
|||||||
c = conn.cursor()
|
c = conn.cursor()
|
||||||
else:
|
else:
|
||||||
return 'Latest transactions db doesn\'t exist. This is unusual, please report on https://github.com/ranchimall/ranchimallflo-api'
|
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 id DESC LIMIT 4) ORDER BY id ASC;''')
|
c.execute('''SELECT * FROM ( SELECT * FROM latestBlocks ORDER BY blockNumber DESC LIMIT 4) ORDER BY id ASC;''')
|
||||||
latestBlocks = c.fetchall()
|
latestBlocks = c.fetchall()
|
||||||
c.close()
|
c.close()
|
||||||
tempdict = []
|
tempdict = []
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user