Fixed block confirmations on the version 2 of the API
This commit is contained in:
parent
0f5809acf8
commit
ab84bca560
@ -41,8 +41,7 @@ def check_integer(value):
|
|||||||
def retryRequest(tempserverlist, apicall):
|
def retryRequest(tempserverlist, apicall):
|
||||||
if len(tempserverlist) != 0:
|
if len(tempserverlist) != 0:
|
||||||
try:
|
try:
|
||||||
response = requests.get(
|
response = requests.get('{}api/{}'.format(tempserverlist[0], apicall))
|
||||||
'{}api/{}'.format(tempserverlist[0], apicall))
|
|
||||||
except:
|
except:
|
||||||
tempserverlist.pop(0)
|
tempserverlist.pop(0)
|
||||||
return retryRequest(tempserverlist, apicall)
|
return retryRequest(tempserverlist, apicall)
|
||||||
@ -56,6 +55,7 @@ def retryRequest(tempserverlist, apicall):
|
|||||||
print("None of the APIs are responding for the call {}".format(apicall))
|
print("None of the APIs are responding for the call {}".format(apicall))
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
|
|
||||||
def multiRequest(apicall, net):
|
def multiRequest(apicall, net):
|
||||||
testserverlist = ['http://0.0.0.0:9000/', 'https://testnet.flocha.in/', 'https://testnet-flosight.duckdns.org/']
|
testserverlist = ['http://0.0.0.0:9000/', 'https://testnet.flocha.in/', 'https://testnet-flosight.duckdns.org/']
|
||||||
mainserverlist = ['http://0.0.0.0:9001/', 'https://livenet.flocha.in/', 'https://testnet-flosight.duckdns.org/']
|
mainserverlist = ['http://0.0.0.0:9001/', 'https://livenet.flocha.in/', 'https://testnet-flosight.duckdns.org/']
|
||||||
@ -64,6 +64,7 @@ def multiRequest(apicall, net):
|
|||||||
elif net == 'testnet':
|
elif net == 'testnet':
|
||||||
return retryRequest(testserverlist, apicall)
|
return retryRequest(testserverlist, apicall)
|
||||||
|
|
||||||
|
|
||||||
def blockdetailhelper(blockdetail):
|
def blockdetailhelper(blockdetail):
|
||||||
if blockdetail.isdigit():
|
if blockdetail.isdigit():
|
||||||
blockHash = None
|
blockHash = None
|
||||||
@ -71,16 +72,14 @@ def blockdetailhelper(blockdetail):
|
|||||||
else:
|
else:
|
||||||
blockHash = str(blockdetail)
|
blockHash = str(blockdetail)
|
||||||
blockHeight = None
|
blockHeight = None
|
||||||
|
|
||||||
# open the latest block database
|
# open the latest block database
|
||||||
conn = sqlite3.connect(os.path.join(dbfolder, 'latestCache.db'))
|
conn = sqlite3.connect(os.path.join(dbfolder, 'latestCache.db'))
|
||||||
c = conn.cursor()
|
c = conn.cursor()
|
||||||
|
|
||||||
if blockHash:
|
if blockHash:
|
||||||
c.execute(f"select jsonData from latestBlocks where blockHash='{blockHash}'")
|
c.execute(f"select jsonData from latestBlocks where blockHash='{blockHash}'")
|
||||||
elif blockHeight:
|
elif blockHeight:
|
||||||
c.execute(f"select jsonData from latestBlocks where blockNumber='{blockHeight}'")
|
c.execute(f"select jsonData from latestBlocks where blockNumber='{blockHeight}'")
|
||||||
|
|
||||||
blockJson = c.fetchall()
|
blockJson = c.fetchall()
|
||||||
return blockJson
|
return blockJson
|
||||||
|
|
||||||
@ -88,12 +87,18 @@ def transactiondetailhelper(transactionHash):
|
|||||||
# open the latest block database
|
# open the latest block database
|
||||||
conn = sqlite3.connect(os.path.join(dbfolder, 'latestCache.db'))
|
conn = sqlite3.connect(os.path.join(dbfolder, 'latestCache.db'))
|
||||||
c = conn.cursor()
|
c = conn.cursor()
|
||||||
|
|
||||||
c.execute(f"select jsonData, parsedFloData, transactionType, db_reference from latestTransactions where transactionHash='{transactionHash}'")
|
c.execute(f"select jsonData, parsedFloData, transactionType, db_reference from latestTransactions where transactionHash='{transactionHash}'")
|
||||||
transactionJsonData = c.fetchall()
|
transactionJsonData = c.fetchall()
|
||||||
|
|
||||||
return transactionJsonData
|
return transactionJsonData
|
||||||
|
|
||||||
|
def update_transaction_confirmations(transactionJson):
|
||||||
|
url = f"{apiUrl}tx/{transactionJson['txid']}"
|
||||||
|
response = requests.get(url)
|
||||||
|
if response.status_code == 200:
|
||||||
|
response_data = response.json()
|
||||||
|
transactionJson['confirmations'] = response_data['confirmations']
|
||||||
|
return transactionJson
|
||||||
|
|
||||||
def smartContractInfo_output(contractName, contractAddress, contractType, subtype):
|
def smartContractInfo_output(contractName, contractAddress, contractType, subtype):
|
||||||
if contractType == 'continuos-event' and contractType == 'tokenswap':
|
if contractType == 'continuos-event' and contractType == 'tokenswap':
|
||||||
pass
|
pass
|
||||||
@ -101,7 +106,7 @@ def smartContractInfo_output(contractName, contractAddress, contractType, subtyp
|
|||||||
pass
|
pass
|
||||||
elif contractType == 'one-time-event' and contractType == 'timetrigger':
|
elif contractType == 'one-time-event' and contractType == 'timetrigger':
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def return_smart_contracts(connection, contractName=None, contractAddress=None):
|
def return_smart_contracts(connection, contractName=None, contractAddress=None):
|
||||||
# find all the contracts details
|
# find all the contracts details
|
||||||
if contractName and contractAddress:
|
if contractName and contractAddress:
|
||||||
@ -243,7 +248,6 @@ async def systemData():
|
|||||||
validatedBlockCount = c.execute('select count(distinct blockNumber) from latestBlocks').fetchall()[0][0]
|
validatedBlockCount = c.execute('select count(distinct blockNumber) from latestBlocks').fetchall()[0][0]
|
||||||
validatedTransactionCount = c.execute('select count(distinct transactionHash) from latestTransactions').fetchall()[0][0]
|
validatedTransactionCount = c.execute('select count(distinct transactionHash) from latestTransactions').fetchall()[0][0]
|
||||||
conn.close()
|
conn.close()
|
||||||
|
|
||||||
return jsonify(systemAddressCount=tokenAddressCount, systemBlockCount=validatedBlockCount, systemTransactionCount=validatedTransactionCount, systemSmartContractCount=contractCount, systemTokenCount=tokenCount, lastscannedblock=lastscannedblock, result='ok')
|
return jsonify(systemAddressCount=tokenAddressCount, systemBlockCount=validatedBlockCount, systemTransactionCount=validatedTransactionCount, systemSmartContractCount=contractCount, systemTokenCount=tokenCount, lastscannedblock=lastscannedblock, result='ok')
|
||||||
|
|
||||||
|
|
||||||
@ -260,17 +264,15 @@ async def getTokenList():
|
|||||||
for item in os.listdir(os.path.join(dbfolder, 'tokens')):
|
for item in os.listdir(os.path.join(dbfolder, 'tokens')):
|
||||||
if os.path.isfile(os.path.join(dbfolder, 'tokens', item)):
|
if os.path.isfile(os.path.join(dbfolder, 'tokens', item)):
|
||||||
filelist.append(item[:-3])
|
filelist.append(item[:-3])
|
||||||
|
|
||||||
return jsonify(tokens=filelist, result='ok')
|
return jsonify(tokens=filelist, result='ok')
|
||||||
|
|
||||||
|
|
||||||
@app.route('/api/v1.0/getTokenInfo', methods=['GET'])
|
@app.route('/api/v1.0/getTokenInfo', methods=['GET'])
|
||||||
async def getTokenInfo():
|
async def getTokenInfo():
|
||||||
token = request.args.get('token')
|
token = request.args.get('token')
|
||||||
|
|
||||||
if token is None:
|
if token is None:
|
||||||
return jsonify(result='error', description='token name hasnt been passed')
|
return jsonify(result='error', description='token name hasnt been passed')
|
||||||
|
|
||||||
dblocation = dbfolder + '/tokens/' + str(token) + '.db'
|
dblocation = dbfolder + '/tokens/' + str(token) + '.db'
|
||||||
if os.path.exists(dblocation):
|
if os.path.exists(dblocation):
|
||||||
conn = sqlite3.connect(dblocation)
|
conn = sqlite3.connect(dblocation)
|
||||||
@ -298,9 +300,7 @@ async def getTokenInfo():
|
|||||||
tempdict['transactionHash'] = item[4]
|
tempdict['transactionHash'] = item[4]
|
||||||
associatedContractList.append(tempdict)
|
associatedContractList.append(tempdict)
|
||||||
|
|
||||||
return jsonify(result='ok', token=token, incorporationAddress=incorporationRow[1], tokenSupply=incorporationRow[3],
|
return jsonify(result='ok', token=token, incorporationAddress=incorporationRow[1], tokenSupply=incorporationRow[3], time=incorporationRow[6], blockchainReference=incorporationRow[7], activeAddress_no=numberOf_distinctAddresses, totalTransactions=numberOf_transactions, associatedSmartContracts=associatedContractList)
|
||||||
time=incorporationRow[6], blockchainReference=incorporationRow[7],
|
|
||||||
activeAddress_no=numberOf_distinctAddresses, totalTransactions=numberOf_transactions, associatedSmartContracts=associatedContractList)
|
|
||||||
|
|
||||||
|
|
||||||
@app.route('/api/v1.0/getTokenTransactions', methods=['GET'])
|
@app.route('/api/v1.0/getTokenTransactions', methods=['GET'])
|
||||||
@ -312,7 +312,7 @@ async def getTokenTransactions():
|
|||||||
|
|
||||||
if token is None:
|
if token is None:
|
||||||
return jsonify(result='error', description='token name hasnt been passed')
|
return jsonify(result='error', description='token name hasnt been passed')
|
||||||
|
|
||||||
dblocation = dbfolder + '/tokens/' + str(token) + '.db'
|
dblocation = dbfolder + '/tokens/' + str(token) + '.db'
|
||||||
if os.path.exists(dblocation):
|
if os.path.exists(dblocation):
|
||||||
conn = sqlite3.connect(dblocation)
|
conn = sqlite3.connect(dblocation)
|
||||||
@ -320,7 +320,7 @@ async def getTokenTransactions():
|
|||||||
c = conn.cursor()
|
c = conn.cursor()
|
||||||
else:
|
else:
|
||||||
return jsonify(result='error', description='token doesn\'t exist')
|
return jsonify(result='error', description='token doesn\'t exist')
|
||||||
|
|
||||||
if senderFloAddress and not destFloAddress:
|
if senderFloAddress and not destFloAddress:
|
||||||
if limit is None:
|
if limit is None:
|
||||||
c.execute('SELECT jsonData, parsedFloData FROM transactionHistory WHERE sourceFloAddress="{}" ORDER BY id DESC'.format(senderFloAddress))
|
c.execute('SELECT jsonData, parsedFloData FROM transactionHistory WHERE sourceFloAddress="{}" ORDER BY id DESC'.format(senderFloAddress))
|
||||||
@ -339,19 +339,18 @@ async def getTokenTransactions():
|
|||||||
|
|
||||||
else:
|
else:
|
||||||
if limit is None:
|
if limit is None:
|
||||||
c.execute(
|
c.execute('SELECT jsonData, parsedFloData FROM transactionHistory ORDER BY id DESC')
|
||||||
'SELECT jsonData, parsedFloData FROM transactionHistory ORDER BY id DESC')
|
|
||||||
else:
|
else:
|
||||||
c.execute(
|
c.execute('SELECT jsonData, parsedFloData FROM transactionHistory ORDER BY id DESC LIMIT {}'.format(limit))
|
||||||
'SELECT jsonData, parsedFloData FROM transactionHistory ORDER BY id DESC LIMIT {}'.format(limit))
|
|
||||||
transactionJsonData = c.fetchall()
|
transactionJsonData = c.fetchall()
|
||||||
conn.close()
|
conn.close()
|
||||||
rowarray_list = {}
|
rowarray_list = {}
|
||||||
for row in transactionJsonData:
|
for row in transactionJsonData:
|
||||||
temp = {}
|
transactions_object = {}
|
||||||
temp['transactionDetails'] = json.loads(row[0])
|
transactions_object['transactionDetails'] = json.loads(row[0])
|
||||||
temp['parsedFloData'] = json.loads(row[1])
|
transactions_object['transactionDetails'] = update_transaction_confirmations(transactions_object['transactionDetails'])
|
||||||
rowarray_list[temp['transactionDetails']['txid']] = temp
|
transactions_object['parsedFloData'] = json.loads(row[1])
|
||||||
|
rowarray_list[transactions_object['transactionDetails']['txid']] = transactions_object
|
||||||
return jsonify(result='ok', token=token, transactions=rowarray_list)
|
return jsonify(result='ok', token=token, transactions=rowarray_list)
|
||||||
|
|
||||||
|
|
||||||
@ -360,17 +359,16 @@ async def getTokenBalances():
|
|||||||
token = request.args.get('token')
|
token = request.args.get('token')
|
||||||
if token is None:
|
if token is None:
|
||||||
return jsonify(result='error', description='token name hasnt been passed')
|
return jsonify(result='error', description='token name hasnt been passed')
|
||||||
|
|
||||||
dblocation = dbfolder + '/tokens/' + str(token) + '.db'
|
dblocation = dbfolder + '/tokens/' + str(token) + '.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 jsonify(result='error', description='token doesn\'t exist')
|
return jsonify(result='error', description='token doesn\'t exist')
|
||||||
c.execute(
|
c.execute('SELECT address,SUM(transferBalance) FROM activeTable GROUP BY address')
|
||||||
'SELECT address,SUM(transferBalance) FROM activeTable GROUP BY address')
|
|
||||||
addressBalances = c.fetchall()
|
addressBalances = c.fetchall()
|
||||||
|
|
||||||
returnList = {}
|
returnList = {}
|
||||||
|
|
||||||
for address in addressBalances:
|
for address in addressBalances:
|
||||||
@ -385,22 +383,18 @@ async def getFloAddressInfo():
|
|||||||
floAddress = request.args.get('floAddress')
|
floAddress = request.args.get('floAddress')
|
||||||
if floAddress is None:
|
if floAddress is None:
|
||||||
return jsonify(description='floAddress hasn\'t been passed'), 400
|
return jsonify(description='floAddress hasn\'t been passed'), 400
|
||||||
|
|
||||||
dblocation = dbfolder + '/system.db'
|
dblocation = dbfolder + '/system.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()
|
||||||
c.execute(
|
c.execute('select token from tokenAddressMapping where tokenAddress="{}"'.format(floAddress))
|
||||||
'select token from tokenAddressMapping where tokenAddress="{}"'.format(floAddress))
|
|
||||||
tokenNames = c.fetchall()
|
tokenNames = c.fetchall()
|
||||||
|
c.execute(f"select contractName, status, tokenIdentification, contractType, transactionHash, blockNumber, blockHash from activecontracts where contractAddress='{floAddress}'")
|
||||||
c.execute(
|
|
||||||
f"select contractName, status, tokenIdentification, contractType, transactionHash, blockNumber, blockHash from activecontracts where contractAddress='{floAddress}'")
|
|
||||||
incorporatedContracts = c.fetchall()
|
incorporatedContracts = c.fetchall()
|
||||||
|
|
||||||
if len(tokenNames) != 0:
|
if len(tokenNames) != 0:
|
||||||
detailList = {}
|
detailList = {}
|
||||||
|
|
||||||
for token in tokenNames:
|
for token in tokenNames:
|
||||||
token = token[0]
|
token = token[0]
|
||||||
dblocation = dbfolder + '/tokens/' + str(token) + '.db'
|
dblocation = dbfolder + '/tokens/' + str(token) + '.db'
|
||||||
@ -408,13 +402,11 @@ async def getFloAddressInfo():
|
|||||||
tempdict = {}
|
tempdict = {}
|
||||||
conn = sqlite3.connect(dblocation)
|
conn = sqlite3.connect(dblocation)
|
||||||
c = conn.cursor()
|
c = conn.cursor()
|
||||||
c.execute(
|
c.execute('SELECT SUM(transferBalance) FROM activeTable WHERE address="{}"'.format(floAddress))
|
||||||
'SELECT SUM(transferBalance) FROM activeTable WHERE address="{}"'.format(floAddress))
|
|
||||||
balance = c.fetchall()[0][0]
|
balance = c.fetchall()[0][0]
|
||||||
tempdict['balance'] = balance
|
tempdict['balance'] = balance
|
||||||
tempdict['token'] = token
|
tempdict['token'] = token
|
||||||
detailList[token] = tempdict
|
detailList[token] = tempdict
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# Address is not associated with any token
|
# Address is not associated with any token
|
||||||
return jsonify(result='error', description='FLO address is not associated with any tokens')
|
return jsonify(result='error', description='FLO address is not associated with any tokens')
|
||||||
@ -432,11 +424,10 @@ async def getFloAddressInfo():
|
|||||||
tempdict['blockNumber'] = contract[5]
|
tempdict['blockNumber'] = contract[5]
|
||||||
tempdict['blockHash'] = contract[6]
|
tempdict['blockHash'] = contract[6]
|
||||||
incorporatedSmartContracts.append(tempdict)
|
incorporatedSmartContracts.append(tempdict)
|
||||||
|
|
||||||
return jsonify(result='ok', floAddress=floAddress, floAddressBalances=detailList, incorporatedSmartContracts=incorporatedContracts)
|
return jsonify(result='ok', floAddress=floAddress, floAddressBalances=detailList, incorporatedSmartContracts=incorporatedContracts)
|
||||||
else:
|
else:
|
||||||
return jsonify(result='ok', floAddress=floAddress, floAddressBalances=detailList,
|
return jsonify(result='ok', floAddress=floAddress, floAddressBalances=detailList, incorporatedSmartContracts=None)
|
||||||
incorporatedSmartContracts=None)
|
|
||||||
|
|
||||||
|
|
||||||
@app.route('/api/v1.0/getFloAddressBalance', methods=['GET'])
|
@app.route('/api/v1.0/getFloAddressBalance', methods=['GET'])
|
||||||
@ -500,13 +491,13 @@ async def getFloAddressTransactions():
|
|||||||
|
|
||||||
if floAddress is None:
|
if floAddress is None:
|
||||||
return jsonify(result='error', description='floAddress has not been passed')
|
return jsonify(result='error', description='floAddress has not been passed')
|
||||||
|
|
||||||
if token is None:
|
if token is None:
|
||||||
dblocation = dbfolder + '/system.db'
|
dblocation = dbfolder + '/system.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()
|
||||||
c.execute('select token from tokenAddressMapping where tokenAddress="{}"'.format(floAddress))
|
c.execute('SELECT token FROM tokenAddressMapping WHERE tokenAddress="{}"'.format(floAddress))
|
||||||
tokenNames = c.fetchall()
|
tokenNames = c.fetchall()
|
||||||
else:
|
else:
|
||||||
dblocation = dbfolder + '/tokens/' + str(token) + '.db'
|
dblocation = dbfolder + '/tokens/' + str(token) + '.db'
|
||||||
@ -514,10 +505,9 @@ async def getFloAddressTransactions():
|
|||||||
tokenNames = [[str(token), ]]
|
tokenNames = [[str(token), ]]
|
||||||
else:
|
else:
|
||||||
return jsonify(result='error', description='token doesn\'t exist')
|
return jsonify(result='error', description='token doesn\'t exist')
|
||||||
|
|
||||||
if len(tokenNames) != 0:
|
if len(tokenNames) != 0:
|
||||||
allTransactionList = {}
|
allTransactionList = {}
|
||||||
|
|
||||||
for tokenname in tokenNames:
|
for tokenname in tokenNames:
|
||||||
tokenname = tokenname[0]
|
tokenname = tokenname[0]
|
||||||
dblocation = dbfolder + '/tokens/' + str(tokenname) + '.db'
|
dblocation = dbfolder + '/tokens/' + str(tokenname) + '.db'
|
||||||
@ -533,11 +523,11 @@ async def getFloAddressTransactions():
|
|||||||
conn.close()
|
conn.close()
|
||||||
|
|
||||||
for row in transactionJsonData:
|
for row in transactionJsonData:
|
||||||
temp = {}
|
transactions_object = {}
|
||||||
temp['transactionDetails'] = json.loads(row[0])
|
transactions_object['transactionDetails'] = json.loads(row[0])
|
||||||
temp['parsedFloData'] = json.loads(row[1])
|
transactions_object['transactionDetails'] = update_transaction_confirmations(transactions_object['transactionDetails'])
|
||||||
allTransactionList[temp['transactionDetails']
|
transactions_object['parsedFloData'] = json.loads(row[1])
|
||||||
['txid']] = temp
|
allTransactionList[transactions_object['transactionDetails']['txid']] = transactions_object
|
||||||
|
|
||||||
if token is None:
|
if token is None:
|
||||||
return jsonify(result='ok', floAddress=floAddress, transactions=allTransactionList)
|
return jsonify(result='ok', floAddress=floAddress, transactions=allTransactionList)
|
||||||
@ -1047,10 +1037,11 @@ async def getsmartcontracttransactions():
|
|||||||
returnval = {}
|
returnval = {}
|
||||||
|
|
||||||
for item in result:
|
for item in result:
|
||||||
temp = {}
|
transactions_object = {}
|
||||||
temp['transactionDetails'] = json.loads(item[0])
|
transactions_object['transactionDetails'] = json.loads(item[0])
|
||||||
temp['parsedFloData'] = json.loads(item[1])
|
transactions_object['transactionDetails'] = update_transaction_confirmations(transactions_object['transactionDetails'])
|
||||||
returnval[temp['transactionDetails']['txid']] = temp
|
transactions_object['parsedFloData'] = json.loads(item[1])
|
||||||
|
returnval[transactions_object['transactionDetails']['txid']] = transactions_object
|
||||||
|
|
||||||
return jsonify(result='ok', contractName=contractName, contractAddress=contractAddress, contractTransactions=returnval)
|
return jsonify(result='ok', contractName=contractName, contractAddress=contractAddress, contractTransactions=returnval)
|
||||||
|
|
||||||
@ -1070,11 +1061,10 @@ async def getblockdetails(blockdetail):
|
|||||||
|
|
||||||
@app.route('/api/v1.0/getTransactionDetails/<transactionHash>', methods=['GET'])
|
@app.route('/api/v1.0/getTransactionDetails/<transactionHash>', methods=['GET'])
|
||||||
async def gettransactiondetails(transactionHash):
|
async def gettransactiondetails(transactionHash):
|
||||||
|
|
||||||
transactionJsonData = transactiondetailhelper(transactionHash)
|
transactionJsonData = transactiondetailhelper(transactionHash)
|
||||||
|
|
||||||
if len(transactionJsonData) != 0:
|
if len(transactionJsonData) != 0:
|
||||||
transactionJson = json.loads(transactionJsonData[0][0])
|
transactionJson = json.loads(transactionJsonData[0][0])
|
||||||
|
transactionJson = update_transaction_confirmations(transactionJson)
|
||||||
parseResult = json.loads(transactionJsonData[0][1])
|
parseResult = json.loads(transactionJsonData[0][1])
|
||||||
|
|
||||||
return jsonify(parsedFloData=parseResult, transactionDetails=transactionJson, transactionHash=transactionHash, result='ok')
|
return jsonify(parsedFloData=parseResult, transactionDetails=transactionJson, transactionHash=transactionHash, result='ok')
|
||||||
@ -1102,6 +1092,7 @@ async def getLatestTransactionDetails():
|
|||||||
item = list(item)
|
item = list(item)
|
||||||
tx_parsed_details = {}
|
tx_parsed_details = {}
|
||||||
tx_parsed_details['transactionDetails'] = json.loads(item[3])
|
tx_parsed_details['transactionDetails'] = json.loads(item[3])
|
||||||
|
tx_parsed_details['transactionDetails'] = update_transaction_confirmations(tx_parsed_details['transactionDetails'])
|
||||||
tx_parsed_details['parsedFloData'] = json.loads(item[5])
|
tx_parsed_details['parsedFloData'] = json.loads(item[5])
|
||||||
tx_parsed_details['parsedFloData']['transactionType'] = item[4]
|
tx_parsed_details['parsedFloData']['transactionType'] = item[4]
|
||||||
tx_parsed_details['transactionDetails']['blockheight'] = int(item[2])
|
tx_parsed_details['transactionDetails']['blockheight'] = int(item[2])
|
||||||
@ -1115,6 +1106,7 @@ async def getLatestTransactionDetails():
|
|||||||
item = list(item)
|
item = list(item)
|
||||||
tx_parsed_details = {}
|
tx_parsed_details = {}
|
||||||
tx_parsed_details['transactionDetails'] = json.loads(item[3])
|
tx_parsed_details['transactionDetails'] = json.loads(item[3])
|
||||||
|
tx_parsed_details['transactionDetails'] = update_transaction_confirmations(tx_parsed_details['transactionDetails'])
|
||||||
tx_parsed_details['parsedFloData'] = json.loads(item[5])
|
tx_parsed_details['parsedFloData'] = json.loads(item[5])
|
||||||
tx_parsed_details['parsedFloData']['transactionType'] = item[4]
|
tx_parsed_details['parsedFloData']['transactionType'] = item[4]
|
||||||
tx_parsed_details['transactionDetails']['blockheight'] = int(item[2])
|
tx_parsed_details['transactionDetails']['blockheight'] = int(item[2])
|
||||||
@ -1125,14 +1117,13 @@ async def getLatestTransactionDetails():
|
|||||||
@app.route('/api/v1.0/getLatestBlockDetails', methods=['GET'])
|
@app.route('/api/v1.0/getLatestBlockDetails', methods=['GET'])
|
||||||
async def getLatestBlockDetails():
|
async def getLatestBlockDetails():
|
||||||
limit = request.args.get('limit')
|
limit = request.args.get('limit')
|
||||||
|
|
||||||
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'
|
||||||
|
|
||||||
if limit is None:
|
if limit is None:
|
||||||
c.execute('''SELECT * FROM ( SELECT * FROM latestBlocks ORDER BY blockNumber DESC LIMIT 4) ORDER BY id ASC;''')
|
c.execute('''SELECT * FROM ( SELECT * FROM latestBlocks ORDER BY blockNumber DESC LIMIT 4) ORDER BY id ASC;''')
|
||||||
else:
|
else:
|
||||||
@ -1156,6 +1147,7 @@ async def getblocktransactions(blockdetail):
|
|||||||
for i in range(len(blocktxlist)):
|
for i in range(len(blocktxlist)):
|
||||||
temptx = transactiondetailhelper(blocktxlist[i])
|
temptx = transactiondetailhelper(blocktxlist[i])
|
||||||
transactionJson = json.loads(temptx[0][0])
|
transactionJson = json.loads(temptx[0][0])
|
||||||
|
transactionJson = update_transaction_confirmations(transactionJson)
|
||||||
parseResult = json.loads(temptx[0][1])
|
parseResult = json.loads(temptx[0][1])
|
||||||
blocktxs[blocktxlist[i]] = {
|
blocktxs[blocktxlist[i]] = {
|
||||||
"parsedFloData" : parseResult,
|
"parsedFloData" : parseResult,
|
||||||
@ -1181,7 +1173,7 @@ async def categoriseString(urlstring):
|
|||||||
tokenfolder = os.path.join(dbfolder, 'tokens')
|
tokenfolder = os.path.join(dbfolder, 'tokens')
|
||||||
onlyfiles = [f[:-3]
|
onlyfiles = [f[:-3]
|
||||||
for f in os.listdir(tokenfolder) if os.path.isfile(os.path.join(tokenfolder, f))]
|
for f in os.listdir(tokenfolder) if os.path.isfile(os.path.join(tokenfolder, f))]
|
||||||
|
|
||||||
if urlstring.lower() in onlyfiles:
|
if urlstring.lower() in onlyfiles:
|
||||||
return jsonify(type='token')
|
return jsonify(type='token')
|
||||||
else:
|
else:
|
||||||
@ -1189,8 +1181,7 @@ async def categoriseString(urlstring):
|
|||||||
conn = sqlite3.connect(contractfolder)
|
conn = sqlite3.connect(contractfolder)
|
||||||
conn.row_factory = lambda cursor, row: row[0]
|
conn.row_factory = lambda cursor, row: row[0]
|
||||||
c = conn.cursor()
|
c = conn.cursor()
|
||||||
contractList = c.execute(
|
contractList = c.execute('select contractname from activeContracts').fetchall()
|
||||||
'select contractname from activeContracts').fetchall()
|
|
||||||
|
|
||||||
if urlstring.lower() in contractList:
|
if urlstring.lower() in contractList:
|
||||||
return jsonify(type='smartContract')
|
return jsonify(type='smartContract')
|
||||||
@ -1209,10 +1200,8 @@ async def getTokenSmartContractList():
|
|||||||
# list of smart contracts
|
# list of smart contracts
|
||||||
conn = sqlite3.connect(os.path.join(dbfolder, 'system.db'))
|
conn = sqlite3.connect(os.path.join(dbfolder, 'system.db'))
|
||||||
c = conn.cursor()
|
c = conn.cursor()
|
||||||
|
|
||||||
contractList = []
|
contractList = []
|
||||||
|
c.execute('SELECT * FROM activecontracts')
|
||||||
c.execute('select * from activecontracts')
|
|
||||||
allcontractsDetailList = c.fetchall()
|
allcontractsDetailList = c.fetchall()
|
||||||
for idx, contract in enumerate(allcontractsDetailList):
|
for idx, contract in enumerate(allcontractsDetailList):
|
||||||
contractDict = {}
|
contractDict = {}
|
||||||
@ -1229,7 +1218,6 @@ async def getTokenSmartContractList():
|
|||||||
contractDict['expiryDate'] = contract[10]
|
contractDict['expiryDate'] = contract[10]
|
||||||
if contract[11]:
|
if contract[11]:
|
||||||
contractDict['closeDate'] = contract[11]
|
contractDict['closeDate'] = contract[11]
|
||||||
|
|
||||||
contractList.append(contractDict)
|
contractList.append(contractDict)
|
||||||
|
|
||||||
return jsonify(tokens=filelist, smartContracts=contractList, result='ok')
|
return jsonify(tokens=filelist, smartContracts=contractList, result='ok')
|
||||||
@ -1249,14 +1237,14 @@ async def info():
|
|||||||
contractCount = c.execute('SELECT COUNT(distinct contractName) FROM contractAddressMapping').fetchall()[0][0]
|
contractCount = c.execute('SELECT COUNT(distinct contractName) FROM contractAddressMapping').fetchall()[0][0]
|
||||||
lastscannedblock = int(c.execute("SELECT value FROM systemData WHERE attribute=='lastblockscanned'").fetchall()[0][0])
|
lastscannedblock = int(c.execute("SELECT value FROM systemData WHERE attribute=='lastblockscanned'").fetchall()[0][0])
|
||||||
conn.close()
|
conn.close()
|
||||||
|
|
||||||
# query for total number of validated blocks
|
# query for total number of validated blocks
|
||||||
conn = sqlite3.connect(os.path.join(dbfolder, 'latestCache.db'))
|
conn = sqlite3.connect(os.path.join(dbfolder, 'latestCache.db'))
|
||||||
c = conn.cursor()
|
c = conn.cursor()
|
||||||
validatedBlockCount = c.execute('SELECT COUNT(distinct blockNumber) FROM latestBlocks').fetchall()[0][0]
|
validatedBlockCount = c.execute('SELECT COUNT(distinct blockNumber) FROM latestBlocks').fetchall()[0][0]
|
||||||
validatedTransactionCount = c.execute('SELECT COUNT(distinct transactionHash) FROM latestTransactions').fetchall()[0][0]
|
validatedTransactionCount = c.execute('SELECT COUNT(distinct transactionHash) FROM latestTransactions').fetchall()[0][0]
|
||||||
conn.close()
|
conn.close()
|
||||||
|
|
||||||
return jsonify(systemAddressCount=tokenAddressCount, systemBlockCount=validatedBlockCount, systemTransactionCount=validatedTransactionCount, systemSmartContractCount=contractCount, systemTokenCount=tokenCount, lastscannedblock=lastscannedblock), 200
|
return jsonify(systemAddressCount=tokenAddressCount, systemBlockCount=validatedBlockCount, systemTransactionCount=validatedTransactionCount, systemSmartContractCount=contractCount, systemTokenCount=tokenCount, lastscannedblock=lastscannedblock), 200
|
||||||
|
|
||||||
|
|
||||||
@ -1267,6 +1255,7 @@ async def broadcastTx_v2(raw_transaction_hash):
|
|||||||
|
|
||||||
|
|
||||||
# FLO TOKEN APIs
|
# FLO TOKEN APIs
|
||||||
|
|
||||||
@app.route('/api/v2/tokenList', methods=['GET'])
|
@app.route('/api/v2/tokenList', methods=['GET'])
|
||||||
async def tokenList():
|
async def tokenList():
|
||||||
filelist = []
|
filelist = []
|
||||||
@ -1280,7 +1269,7 @@ async def tokenList():
|
|||||||
async def tokenInfo(token):
|
async def tokenInfo(token):
|
||||||
if token is None:
|
if token is None:
|
||||||
return jsonify(description='Token name hasnt been passed'), 400
|
return jsonify(description='Token name hasnt been passed'), 400
|
||||||
|
|
||||||
# todo : input validation
|
# todo : input validation
|
||||||
dblocation = dbfolder + '/tokens/' + str(token) + '.db'
|
dblocation = dbfolder + '/tokens/' + str(token) + '.db'
|
||||||
if os.path.exists(dblocation):
|
if os.path.exists(dblocation):
|
||||||
@ -1297,7 +1286,7 @@ async def tokenInfo(token):
|
|||||||
c.execute('SELECT contractName, contractAddress, blockNumber, blockHash, transactionHash FROM tokenContractAssociation')
|
c.execute('SELECT contractName, contractAddress, blockNumber, blockHash, transactionHash FROM tokenContractAssociation')
|
||||||
associatedContracts = c.fetchall()
|
associatedContracts = c.fetchall()
|
||||||
conn.close()
|
conn.close()
|
||||||
|
|
||||||
associatedContractList = []
|
associatedContractList = []
|
||||||
for item in associatedContracts:
|
for item in associatedContracts:
|
||||||
tempdict = {}
|
tempdict = {}
|
||||||
@ -1362,10 +1351,11 @@ async def tokenTransactions(token):
|
|||||||
rowarray_list = []
|
rowarray_list = []
|
||||||
sorted_list = sorted(transactionJsonData, key=itemgetter('blocktime'), reverse=True)
|
sorted_list = sorted(transactionJsonData, key=itemgetter('blocktime'), reverse=True)
|
||||||
for row in sorted_list:
|
for row in sorted_list:
|
||||||
temp = {}
|
transactions_object = {}
|
||||||
temp['transactionDetails'] = json.loads(row[0])
|
transactions_object['transactionDetails'] = json.loads(row[0])
|
||||||
temp['parsedFloData'] = json.loads(row[1])
|
transactions_object['transactionDetails'] = update_transaction_confirmations(transactions_object['transactionDetails'])
|
||||||
rowarray_list.append(temp)
|
transactions_object['parsedFloData'] = json.loads(row[1])
|
||||||
|
rowarray_list.append(transactions_object)
|
||||||
return jsonify(token=token, transactions=rowarray_list), 200
|
return jsonify(token=token, transactions=rowarray_list), 200
|
||||||
|
|
||||||
|
|
||||||
@ -1382,7 +1372,6 @@ async def tokenBalances(token):
|
|||||||
return jsonify(description="Token doesn't exist"), 404
|
return jsonify(description="Token doesn't exist"), 404
|
||||||
c.execute('SELECT address,SUM(transferBalance) FROM activeTable GROUP BY address')
|
c.execute('SELECT address,SUM(transferBalance) FROM activeTable GROUP BY address')
|
||||||
addressBalances = c.fetchall()
|
addressBalances = c.fetchall()
|
||||||
|
|
||||||
returnList = {}
|
returnList = {}
|
||||||
for address in addressBalances:
|
for address in addressBalances:
|
||||||
returnList[address[0]] = address[1]
|
returnList[address[0]] = address[1]
|
||||||
@ -1398,7 +1387,7 @@ async def floAddressInfo(floAddress):
|
|||||||
# input validation
|
# input validation
|
||||||
if not check_flo_address(floAddress, is_testnet):
|
if not check_flo_address(floAddress, is_testnet):
|
||||||
return jsonify(description='floAddress validation failed'), 400
|
return jsonify(description='floAddress validation failed'), 400
|
||||||
|
|
||||||
dblocation = dbfolder + '/system.db'
|
dblocation = dbfolder + '/system.db'
|
||||||
if os.path.exists(dblocation):
|
if os.path.exists(dblocation):
|
||||||
conn = sqlite3.connect(dblocation)
|
conn = sqlite3.connect(dblocation)
|
||||||
@ -1451,7 +1440,7 @@ async def floAddressBalance(floAddress):
|
|||||||
# input validation
|
# input validation
|
||||||
if not check_flo_address(floAddress, is_testnet):
|
if not check_flo_address(floAddress, is_testnet):
|
||||||
return jsonify(description='floAddress validation failed'), 400
|
return jsonify(description='floAddress validation failed'), 400
|
||||||
|
|
||||||
token = request.args.get('token')
|
token = request.args.get('token')
|
||||||
if token is None:
|
if token is None:
|
||||||
dblocation = dbfolder + '/system.db'
|
dblocation = dbfolder + '/system.db'
|
||||||
@ -1501,7 +1490,7 @@ async def floAddressTransactions(floAddress):
|
|||||||
limit = request.args.get('limit')
|
limit = request.args.get('limit')
|
||||||
if limit is not None and not check_integer(limit):
|
if limit is not None and not check_integer(limit):
|
||||||
return jsonify(description='limit validation failed'), 400
|
return jsonify(description='limit validation failed'), 400
|
||||||
|
|
||||||
token = request.args.get('token')
|
token = request.args.get('token')
|
||||||
if token is None:
|
if token is None:
|
||||||
dblocation = dbfolder + '/system.db'
|
dblocation = dbfolder + '/system.db'
|
||||||
@ -1516,7 +1505,7 @@ async def floAddressTransactions(floAddress):
|
|||||||
tokenNames = [[str(token), ]]
|
tokenNames = [[str(token), ]]
|
||||||
else:
|
else:
|
||||||
return jsonify(description="Token doesn't exist"), 404
|
return jsonify(description="Token doesn't exist"), 404
|
||||||
|
|
||||||
if len(tokenNames) != 0:
|
if len(tokenNames) != 0:
|
||||||
allTransactionList = []
|
allTransactionList = []
|
||||||
for tokenname in tokenNames:
|
for tokenname in tokenNames:
|
||||||
@ -1538,6 +1527,7 @@ async def floAddressTransactions(floAddress):
|
|||||||
for row in allTransactionList:
|
for row in allTransactionList:
|
||||||
tx = {}
|
tx = {}
|
||||||
tx['transactionDetails'] = json.loads(row[0])
|
tx['transactionDetails'] = json.loads(row[0])
|
||||||
|
tx['transactionDetails'] = update_transaction_confirmations(tx['transactionDetails'])
|
||||||
tx['parsedFloData'] = json.loads(row[1])
|
tx['parsedFloData'] = json.loads(row[1])
|
||||||
rowarray_list.append(tx)
|
rowarray_list.append(tx)
|
||||||
if token is None:
|
if token is None:
|
||||||
@ -1593,7 +1583,7 @@ async def getContractInfo_v2():
|
|||||||
contractAddress = contractAddress.strip()
|
contractAddress = contractAddress.strip()
|
||||||
if not check_flo_address(contractAddress, is_testnet):
|
if not check_flo_address(contractAddress, is_testnet):
|
||||||
return jsonify(description='contractAddress validation failed'), 400
|
return jsonify(description='contractAddress validation failed'), 400
|
||||||
|
|
||||||
contractStructure = fetchContractStructure(contractName, contractAddress)
|
contractStructure = fetchContractStructure(contractName, contractAddress)
|
||||||
if contractStructure:
|
if contractStructure:
|
||||||
returnval = contractStructure
|
returnval = contractStructure
|
||||||
@ -1607,14 +1597,12 @@ async def getContractInfo_v2():
|
|||||||
returnval['totalHonorAmount'] = participation_details[0][2]
|
returnval['totalHonorAmount'] = participation_details[0][2]
|
||||||
c.execute('SELECT COUNT(DISTINCT transactionHash) FROM contractdeposits')
|
c.execute('SELECT COUNT(DISTINCT transactionHash) FROM contractdeposits')
|
||||||
returnval['numberOfDeposits'] = c.fetchall()[0][0]
|
returnval['numberOfDeposits'] = c.fetchall()[0][0]
|
||||||
|
|
||||||
elif contractStructure['contractType'] == 'one-time-event' and 'exitconditions' in contractStructure.keys():
|
elif contractStructure['contractType'] == 'one-time-event' and 'exitconditions' in contractStructure.keys():
|
||||||
returnval['userChoice'] = contractStructure['exitconditions']
|
returnval['userChoice'] = contractStructure['exitconditions']
|
||||||
returnval.pop('exitconditions')
|
returnval.pop('exitconditions')
|
||||||
conn, c = create_database_connection('system_dbs')
|
conn, c = create_database_connection('system_dbs')
|
||||||
c.execute('SELECT status, incorporationDate, expiryDate, closeDate FROM activecontracts WHERE contractName=="{}" AND contractAddress=="{}"'.format(contractName.strip(), contractAddress.strip()))
|
c.execute('SELECT status, incorporationDate, expiryDate, closeDate FROM activecontracts WHERE contractName=="{}" AND contractAddress=="{}"'.format(contractName, contractAddress))
|
||||||
results = c.fetchall()
|
results = c.fetchall()
|
||||||
|
|
||||||
if len(results) == 1:
|
if len(results) == 1:
|
||||||
for result in results:
|
for result in results:
|
||||||
returnval['status'] = result[0]
|
returnval['status'] = result[0]
|
||||||
@ -1623,7 +1611,6 @@ async def getContractInfo_v2():
|
|||||||
returnval['expiryDate'] = result[2]
|
returnval['expiryDate'] = result[2]
|
||||||
if result[3]:
|
if result[3]:
|
||||||
returnval['closeDate'] = result[3]
|
returnval['closeDate'] = result[3]
|
||||||
|
|
||||||
elif contractStructure['contractType'] == 'one-time-event' and 'payeeAddress' in contractStructure.keys():
|
elif contractStructure['contractType'] == 'one-time-event' and 'payeeAddress' in contractStructure.keys():
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@ -1638,11 +1625,11 @@ async def getcontractparticipants_v2():
|
|||||||
if contractName is None:
|
if contractName is None:
|
||||||
return jsonify(description='Smart Contract\'s name hasn\'t been passed'), 400
|
return jsonify(description='Smart Contract\'s name hasn\'t been passed'), 400
|
||||||
contractName = contractName.strip().lower()
|
contractName = contractName.strip().lower()
|
||||||
|
|
||||||
contractAddress = request.args.get('contractAddress')
|
contractAddress = request.args.get('contractAddress')
|
||||||
contractAddress = contractAddress.strip()
|
|
||||||
if contractAddress is None:
|
if contractAddress is None:
|
||||||
return jsonify(description='Smart Contract\'s address hasn\'t been passed'), 400
|
return jsonify(description='Smart Contract\'s address hasn\'t been passed'), 400
|
||||||
|
contractAddress = contractAddress.strip()
|
||||||
if not check_flo_address(contractAddress, is_testnet):
|
if not check_flo_address(contractAddress, is_testnet):
|
||||||
return jsonify(description='contractAddress validation failed'), 400
|
return jsonify(description='contractAddress validation failed'), 400
|
||||||
|
|
||||||
@ -1662,7 +1649,6 @@ async def getcontractparticipants_v2():
|
|||||||
returnval = {}
|
returnval = {}
|
||||||
for row in result:
|
for row in result:
|
||||||
returnval[row[1]] = {'participantFloAddress': row[1], 'tokenAmount': row[2], 'userChoice': row[3], 'transactionHash': row[4], 'winningAmount': row[5], 'tokenIdentification': token}
|
returnval[row[1]] = {'participantFloAddress': row[1], 'tokenAmount': row[2], 'userChoice': row[3], 'transactionHash': row[4], 'winningAmount': row[5], 'tokenIdentification': token}
|
||||||
|
|
||||||
else:
|
else:
|
||||||
c.execute('SELECT id, participantAddress, tokenAmount, userChoice, transactionHash FROM contractparticipants')
|
c.execute('SELECT id, participantAddress, tokenAmount, userChoice, transactionHash FROM contractparticipants')
|
||||||
result = c.fetchall()
|
result = c.fetchall()
|
||||||
@ -1670,7 +1656,6 @@ async def getcontractparticipants_v2():
|
|||||||
returnval = {}
|
returnval = {}
|
||||||
for row in result:
|
for row in result:
|
||||||
returnval[row[1]] = {'participantFloAddress': row[1], 'tokenAmount': row[2], 'userChoice': row[3], 'transactionHash': row[4]}
|
returnval[row[1]] = {'participantFloAddress': row[1], 'tokenAmount': row[2], 'userChoice': row[3], 'transactionHash': row[4]}
|
||||||
|
|
||||||
elif 'payeeAddress' in contractStructure:
|
elif 'payeeAddress' in contractStructure:
|
||||||
# contract is of the type internal trigger
|
# contract is of the type internal trigger
|
||||||
c.execute('SELECT id, participantAddress, tokenAmount, userChoice, transactionHash FROM contractparticipants')
|
c.execute('SELECT id, participantAddress, tokenAmount, userChoice, transactionHash FROM contractparticipants')
|
||||||
@ -1679,7 +1664,6 @@ async def getcontractparticipants_v2():
|
|||||||
returnval = {}
|
returnval = {}
|
||||||
for row in result:
|
for row in result:
|
||||||
returnval[row[1]] = {'participantFloAddress': row[1], 'tokenAmount': row[2], 'transactionHash': row[4]}
|
returnval[row[1]] = {'participantFloAddress': row[1], 'tokenAmount': row[2], 'transactionHash': row[4]}
|
||||||
|
|
||||||
elif contractStructure['contractType'] == 'continuos-event' and contractStructure['subtype'] == 'tokenswap':
|
elif contractStructure['contractType'] == 'continuos-event' and contractStructure['subtype'] == 'tokenswap':
|
||||||
c.execute('SELECT * FROM contractparticipants')
|
c.execute('SELECT * FROM contractparticipants')
|
||||||
contract_participants = c.fetchall()
|
contract_participants = c.fetchall()
|
||||||
@ -1695,7 +1679,6 @@ async def getcontractparticipants_v2():
|
|||||||
'swapAmount': row[7]
|
'swapAmount': row[7]
|
||||||
}
|
}
|
||||||
conn.close()
|
conn.close()
|
||||||
|
|
||||||
return jsonify(contractName=contractName, contractAddress=contractAddress, participantInfo=returnval), 200
|
return jsonify(contractName=contractName, contractAddress=contractAddress, participantInfo=returnval), 200
|
||||||
else:
|
else:
|
||||||
return jsonify(description='Smart Contract with the given name doesn\'t exist'), 404
|
return jsonify(description='Smart Contract with the given name doesn\'t exist'), 404
|
||||||
@ -1709,28 +1692,27 @@ async def participantDetails():
|
|||||||
return jsonify(description='floAddress validation failed'), 400
|
return jsonify(description='floAddress validation failed'), 400
|
||||||
|
|
||||||
contractName = request.args.get('contractName')
|
contractName = request.args.get('contractName')
|
||||||
contractName = contractName.strip().lower()
|
|
||||||
|
|
||||||
contractAddress = request.args.get('contractAddress')
|
contractAddress = request.args.get('contractAddress')
|
||||||
contractAddress = contractAddress.strip()
|
|
||||||
if contractAddress is not None and not check_flo_address(contractAddress, is_testnet):
|
if contractAddress is not None and not check_flo_address(contractAddress, is_testnet):
|
||||||
return jsonify(description='contractAddress validation failed'), 400
|
return jsonify(description='contractAddress validation failed'), 400
|
||||||
|
contractAddress = contractAddress.strip()
|
||||||
|
|
||||||
if (contractName and contractAddress is None) or (contractName is None and contractAddress):
|
if (contractName and contractAddress is None) or (contractName is None and contractAddress):
|
||||||
return jsonify(description='pass both, contractName and contractAddress as url parameters'), 400
|
return jsonify(description='pass both, contractName and contractAddress as url parameters'), 400
|
||||||
|
contractName = contractName.strip().lower()
|
||||||
|
|
||||||
dblocation = os.path.join(dbfolder, 'system.db')
|
dblocation = os.path.join(dbfolder, 'system.db')
|
||||||
if os.path.isfile(dblocation):
|
if os.path.isfile(dblocation):
|
||||||
# Make db connection and fetch data
|
# Make db connection and fetch data
|
||||||
conn = sqlite3.connect(dblocation)
|
conn = sqlite3.connect(dblocation)
|
||||||
c = conn.cursor()
|
c = conn.cursor()
|
||||||
|
|
||||||
if contractName is not None:
|
if contractName is not None:
|
||||||
c.execute(f'SELECT * FROM contractAddressMapping WHERE address="{floAddress}" AND addressType="participant" AND contractName="{contractName}" AND contractAddress="{contractAddress}"')
|
c.execute(f'SELECT * FROM contractAddressMapping WHERE address="{floAddress}" AND addressType="participant" AND contractName="{contractName}" AND contractAddress="{contractAddress}"')
|
||||||
else:
|
else:
|
||||||
c.execute(f'SELECT * FROM contractAddressMapping WHERE address="{floAddress}" AND addressType="participant"')
|
c.execute(f'SELECT * FROM contractAddressMapping WHERE address="{floAddress}" AND addressType="participant"')
|
||||||
participant_address_contracts = c.fetchall()
|
participant_address_contracts = c.fetchall()
|
||||||
|
|
||||||
if len(participant_address_contracts) != 0:
|
if len(participant_address_contracts) != 0:
|
||||||
participationDetailsList = []
|
participationDetailsList = []
|
||||||
for contract in participant_address_contracts:
|
for contract in participant_address_contracts:
|
||||||
@ -1739,7 +1721,6 @@ async def participantDetails():
|
|||||||
# Make db connection and fetch contract structure
|
# Make db connection and fetch contract structure
|
||||||
conn = sqlite3.connect(contract_db)
|
conn = sqlite3.connect(contract_db)
|
||||||
c = conn.cursor()
|
c = conn.cursor()
|
||||||
|
|
||||||
# Get details of the type of Smart Contract
|
# Get details of the type of Smart Contract
|
||||||
c.execute('SELECT attribute,value FROM contractstructure')
|
c.execute('SELECT attribute,value FROM contractstructure')
|
||||||
result = c.fetchall()
|
result = c.fetchall()
|
||||||
@ -1762,7 +1743,6 @@ async def participantDetails():
|
|||||||
# what is a api detail
|
# what is a api detail
|
||||||
c.execute('SELECT * FROM contractparticipants WHERE participantAddress=?',(floAddress,))
|
c.execute('SELECT * FROM contractparticipants WHERE participantAddress=?',(floAddress,))
|
||||||
participant_details = c.fetchall()
|
participant_details = c.fetchall()
|
||||||
|
|
||||||
if len(participant_details) > 0:
|
if len(participant_details) > 0:
|
||||||
participationList = []
|
participationList = []
|
||||||
for participation in participant_details:
|
for participation in participant_details:
|
||||||
@ -1778,9 +1758,8 @@ async def participantDetails():
|
|||||||
detailsDict['blockNumber'] = participation[5]
|
detailsDict['blockNumber'] = participation[5]
|
||||||
detailsDict['blockHash'] = participation[6]
|
detailsDict['blockHash'] = participation[6]
|
||||||
participationList.append(detailsDict)
|
participationList.append(detailsDict)
|
||||||
|
|
||||||
participationDetailsList.append(participationList)
|
participationDetailsList.append(participationList)
|
||||||
|
|
||||||
elif contractStructure['contractType']=='one-time-event' and 'payeeAddress' in contractStructure.keys():
|
elif contractStructure['contractType']=='one-time-event' and 'payeeAddress' in contractStructure.keys():
|
||||||
# normal results
|
# normal results
|
||||||
conn = sqlite3.connect(dblocation)
|
conn = sqlite3.connect(dblocation)
|
||||||
@ -1805,7 +1784,7 @@ async def participantDetails():
|
|||||||
detailsDict['closeDate'] = temp[0][7]
|
detailsDict['closeDate'] = temp[0][7]
|
||||||
|
|
||||||
# check if the contract has been closed
|
# check if the contract has been closed
|
||||||
contractDbName = '{}-{}.db'.format(detailsDict['contractName'].strip(), detailsDict['contractAddress'].strip())
|
contractDbName = '{}-{}.db'.format(detailsDict['contractName'], detailsDict['contractAddress'])
|
||||||
filelocation = os.path.join(dbfolder, 'smartContracts', contractDbName)
|
filelocation = os.path.join(dbfolder, 'smartContracts', contractDbName)
|
||||||
if os.path.isfile(filelocation):
|
if os.path.isfile(filelocation):
|
||||||
# Make db connection and fetch data
|
# Make db connection and fetch data
|
||||||
@ -1858,7 +1837,7 @@ async def participantDetails():
|
|||||||
detailsDict['closeDate'] = temp[0][7]
|
detailsDict['closeDate'] = temp[0][7]
|
||||||
|
|
||||||
# check if the contract has been closed
|
# check if the contract has been closed
|
||||||
contractDbName = '{}-{}.db'.format(detailsDict['contractName'].strip(), detailsDict['contractAddress'].strip())
|
contractDbName = '{}-{}.db'.format(detailsDict['contractName'], detailsDict['contractAddress'])
|
||||||
filelocation = os.path.join(dbfolder, 'smartContracts', contractDbName)
|
filelocation = os.path.join(dbfolder, 'smartContracts', contractDbName)
|
||||||
if os.path.isfile(filelocation):
|
if os.path.isfile(filelocation):
|
||||||
# Make db connection and fetch data
|
# Make db connection and fetch data
|
||||||
@ -1908,22 +1887,22 @@ async def participantDetails():
|
|||||||
@app.route('/api/v2/smartContractTransactions', methods=['GET'])
|
@app.route('/api/v2/smartContractTransactions', methods=['GET'])
|
||||||
async def smartcontracttransactions():
|
async def smartcontracttransactions():
|
||||||
contractName = request.args.get('contractName')
|
contractName = request.args.get('contractName')
|
||||||
contractName = contractName.strip().lower()
|
|
||||||
if contractName is None:
|
if contractName is None:
|
||||||
return jsonify(description='Smart Contract\'s name hasn\'t been passed'), 400
|
return jsonify(description='Smart Contract\'s name hasn\'t been passed'), 400
|
||||||
|
contractName = contractName.strip().lower()
|
||||||
|
|
||||||
contractAddress = request.args.get('contractAddress')
|
contractAddress = request.args.get('contractAddress')
|
||||||
contractAddress = contractAddress.strip()
|
|
||||||
if contractAddress is None:
|
if contractAddress is None:
|
||||||
return jsonify(description='Smart Contract\'s address hasn\'t been passed'), 400
|
return jsonify(description='Smart Contract\'s address hasn\'t been passed'), 400
|
||||||
|
contractAddress = contractAddress.strip()
|
||||||
if not check_flo_address(contractAddress, is_testnet):
|
if not check_flo_address(contractAddress, is_testnet):
|
||||||
return jsonify(description='contractAddress validation failed'), 400
|
return jsonify(description='contractAddress validation failed'), 400
|
||||||
|
|
||||||
limit = request.args.get('limit')
|
limit = request.args.get('limit')
|
||||||
if limit is not None and not check_integer(limit):
|
if limit is not None and not check_integer(limit):
|
||||||
return jsonify(description='limit validation failed'), 400
|
return jsonify(description='limit validation failed'), 400
|
||||||
|
|
||||||
contractDbName = '{}-{}.db'.format(contractName.strip(), contractAddress.strip())
|
contractDbName = '{}-{}.db'.format(contractName, contractAddress)
|
||||||
filelocation = os.path.join(dbfolder, 'smartContracts', contractDbName)
|
filelocation = os.path.join(dbfolder, 'smartContracts', contractDbName)
|
||||||
|
|
||||||
if os.path.isfile(filelocation):
|
if os.path.isfile(filelocation):
|
||||||
@ -1931,18 +1910,18 @@ async def smartcontracttransactions():
|
|||||||
conn = sqlite3.connect(filelocation)
|
conn = sqlite3.connect(filelocation)
|
||||||
c = conn.cursor()
|
c = conn.cursor()
|
||||||
if limit is None:
|
if limit is None:
|
||||||
c.execute('SELECT jsonData, parsedFloData FROM contractTransactionHistory ORDER BY blocktime DESC')
|
c.execute('SELECT jsonData, parsedFloData FROM contractTransactionHistory ORDER BY time DESC')
|
||||||
else:
|
else:
|
||||||
c.execute(f'SELECT jsonData, parsedFloData FROM contractTransactionHistory ORDER BY blocktime DESC LIMIT {limit}')
|
c.execute(f'SELECT jsonData, parsedFloData FROM contractTransactionHistory ORDER BY time DESC LIMIT {limit}')
|
||||||
result = c.fetchall()
|
result = c.fetchall()
|
||||||
conn.close()
|
conn.close()
|
||||||
returnval = []
|
returnval = []
|
||||||
for item in result:
|
for item in result:
|
||||||
tx = {}
|
tx = {}
|
||||||
tx['transactionDetails'] = json.loads(item[0])
|
tx['transactionDetails'] = json.loads(item[0])
|
||||||
|
tx['transactionDetails'] = update_transaction_confirmations(tx['transactionDetails'])
|
||||||
tx['parsedFloData'] = json.loads(item[1])
|
tx['parsedFloData'] = json.loads(item[1])
|
||||||
returnval.append(tx)
|
returnval.append(tx)
|
||||||
|
|
||||||
return jsonify(contractName=contractName, contractAddress=contractAddress, contractTransactions=returnval), 200
|
return jsonify(contractName=contractName, contractAddress=contractAddress, contractTransactions=returnval), 200
|
||||||
else:
|
else:
|
||||||
return jsonify(description='Smart Contract with the given name doesn\'t exist'), 404
|
return jsonify(description='Smart Contract with the given name doesn\'t exist'), 404
|
||||||
@ -1951,7 +1930,6 @@ async def smartcontracttransactions():
|
|||||||
@app.route('/api/v2/blockDetails/<blockHash>', methods=['GET'])
|
@app.route('/api/v2/blockDetails/<blockHash>', methods=['GET'])
|
||||||
async def blockdetails(blockHash):
|
async def blockdetails(blockHash):
|
||||||
# todo - validate blockHash
|
# todo - validate blockHash
|
||||||
|
|
||||||
blockJson = blockdetailhelper(blockHash)
|
blockJson = blockdetailhelper(blockHash)
|
||||||
if len(blockJson) != 0:
|
if len(blockJson) != 0:
|
||||||
blockJson = json.loads(blockJson[0][0])
|
blockJson = json.loads(blockJson[0][0])
|
||||||
@ -1963,10 +1941,10 @@ async def blockdetails(blockHash):
|
|||||||
@app.route('/api/v2/transactionDetails/<transactionHash>', methods=['GET'])
|
@app.route('/api/v2/transactionDetails/<transactionHash>', methods=['GET'])
|
||||||
async def transactiondetails1(transactionHash):
|
async def transactiondetails1(transactionHash):
|
||||||
# todo - validate transactionHash
|
# todo - validate transactionHash
|
||||||
|
|
||||||
transactionJsonData = transactiondetailhelper(transactionHash)
|
transactionJsonData = transactiondetailhelper(transactionHash)
|
||||||
if len(transactionJsonData) != 0:
|
if len(transactionJsonData) != 0:
|
||||||
transactionJson = json.loads(transactionJsonData[0][0])
|
transactionJson = json.loads(transactionJsonData[0][0])
|
||||||
|
transactionJson = update_transaction_confirmations(transactionJson)
|
||||||
parseResult = json.loads(transactionJsonData[0][1])
|
parseResult = json.loads(transactionJsonData[0][1])
|
||||||
operation = transactionJsonData[0][2]
|
operation = transactionJsonData[0][2]
|
||||||
db_reference = transactionJsonData[0][3]
|
db_reference = transactionJsonData[0][3]
|
||||||
@ -1989,7 +1967,7 @@ async def transactiondetails1(transactionHash):
|
|||||||
operationDetails['depositHonors']['count'] = len(deposit_honors)
|
operationDetails['depositHonors']['count'] = len(deposit_honors)
|
||||||
for deposit_honor in deposit_honors:
|
for deposit_honor in deposit_honors:
|
||||||
operationDetails['depositHonors']['list'].append({'honor_amount':deposit_honor[0],'blockNumber':deposit_honor[1]})
|
operationDetails['depositHonors']['list'].append({'honor_amount':deposit_honor[0],'blockNumber':deposit_honor[1]})
|
||||||
|
|
||||||
c.execute("SELECT depositBalance FROM contractdeposits WHERE id=(SELECT max(id) FROM contractdeposits WHERE transactionHash=?)",(transactionJson['txid'],))
|
c.execute("SELECT depositBalance FROM contractdeposits WHERE id=(SELECT max(id) FROM contractdeposits WHERE transactionHash=?)",(transactionJson['txid'],))
|
||||||
depositBalance = c.fetchall()
|
depositBalance = c.fetchall()
|
||||||
operationDetails['depositBalance'] = depositBalance[0][0]
|
operationDetails['depositBalance'] = depositBalance[0][0]
|
||||||
@ -2064,6 +2042,7 @@ async def latestTransactionDetails():
|
|||||||
item = list(item)
|
item = list(item)
|
||||||
tx_parsed_details = {}
|
tx_parsed_details = {}
|
||||||
tx_parsed_details['transactionDetails'] = json.loads(item[3])
|
tx_parsed_details['transactionDetails'] = json.loads(item[3])
|
||||||
|
tx_parsed_details['transactionDetails'] = update_transaction_confirmations(tx_parsed_details['transactionDetails'])
|
||||||
tx_parsed_details['parsedFloData'] = json.loads(item[5])
|
tx_parsed_details['parsedFloData'] = json.loads(item[5])
|
||||||
tx_parsed_details['parsedFloData']['transactionType'] = item[4]
|
tx_parsed_details['parsedFloData']['transactionType'] = item[4]
|
||||||
tx_parsed_details['transactionDetails']['blockheight'] = int(item[2])
|
tx_parsed_details['transactionDetails']['blockheight'] = int(item[2])
|
||||||
@ -2131,7 +2110,6 @@ async def categoriseString_v2(urlstring):
|
|||||||
tokenfolder = os.path.join(dbfolder, 'tokens')
|
tokenfolder = os.path.join(dbfolder, 'tokens')
|
||||||
onlyfiles = [f[:-3]
|
onlyfiles = [f[:-3]
|
||||||
for f in os.listdir(tokenfolder) if os.path.isfile(os.path.join(tokenfolder, f))]
|
for f in os.listdir(tokenfolder) if os.path.isfile(os.path.join(tokenfolder, f))]
|
||||||
|
|
||||||
if urlstring.lower() in onlyfiles:
|
if urlstring.lower() in onlyfiles:
|
||||||
return jsonify(type='token'), 200
|
return jsonify(type='token'), 200
|
||||||
else:
|
else:
|
||||||
@ -2158,9 +2136,7 @@ async def tokenSmartContractList():
|
|||||||
# list of smart contracts
|
# list of smart contracts
|
||||||
conn = sqlite3.connect(os.path.join(dbfolder, 'system.db'))
|
conn = sqlite3.connect(os.path.join(dbfolder, 'system.db'))
|
||||||
c = conn.cursor()
|
c = conn.cursor()
|
||||||
|
|
||||||
contractList = []
|
contractList = []
|
||||||
|
|
||||||
c.execute('select * from activecontracts')
|
c.execute('select * from activecontracts')
|
||||||
allcontractsDetailList = c.fetchall()
|
allcontractsDetailList = c.fetchall()
|
||||||
for idx, contract in enumerate(allcontractsDetailList):
|
for idx, contract in enumerate(allcontractsDetailList):
|
||||||
@ -2178,9 +2154,7 @@ async def tokenSmartContractList():
|
|||||||
contractDict['expiryDate'] = contract[10]
|
contractDict['expiryDate'] = contract[10]
|
||||||
if contract[11]:
|
if contract[11]:
|
||||||
contractDict['closeDate'] = contract[11]
|
contractDict['closeDate'] = contract[11]
|
||||||
|
|
||||||
contractList.append(contractDict)
|
contractList.append(contractDict)
|
||||||
|
|
||||||
return jsonify(tokens=filelist, smartContracts=contractList), 200
|
return jsonify(tokens=filelist, smartContracts=contractList), 200
|
||||||
|
|
||||||
|
|
||||||
@ -2242,11 +2216,9 @@ async def priceData():
|
|||||||
ratepairs = c.execute('select ratepair, price from ratepairs')
|
ratepairs = c.execute('select ratepair, price from ratepairs')
|
||||||
ratepairs = ratepairs.fetchall()
|
ratepairs = ratepairs.fetchall()
|
||||||
prices = {}
|
prices = {}
|
||||||
|
|
||||||
for ratepair in ratepairs:
|
for ratepair in ratepairs:
|
||||||
ratepair = list(ratepair)
|
ratepair = list(ratepair)
|
||||||
prices[ratepair[0]] = ratepair[1]
|
prices[ratepair[0]] = ratepair[1]
|
||||||
|
|
||||||
return jsonify(prices=prices), 200
|
return jsonify(prices=prices), 200
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user