Fixed bug in /api/v2/smartContractList
This commit is contained in:
parent
ab84bca560
commit
e884e3fafe
@ -1542,11 +1542,16 @@ async def floAddressTransactions(floAddress):
|
|||||||
@app.route('/api/v2/smartContractList', methods=['GET'])
|
@app.route('/api/v2/smartContractList', methods=['GET'])
|
||||||
async def getContractList_v2():
|
async def getContractList_v2():
|
||||||
contractName = request.args.get('contractName')
|
contractName = request.args.get('contractName')
|
||||||
contractName = contractName.strip().lower()
|
if contractName is not None:
|
||||||
contractAddress = request.args.get('contractAddress')
|
contractName = contractName.strip().lower()
|
||||||
|
|
||||||
# todo - Add validation for contractAddress and contractName to prevent SQL injection attacks
|
# todo - Add validation for contractAddress and contractName to prevent SQL injection attacks
|
||||||
if contractAddress is not None and not check_flo_address(contractAddress, is_testnet):
|
contractAddress = request.args.get('contractAddress')
|
||||||
return jsonify(description='contractAddress validation failed'), 400
|
if contractAddress is not None:
|
||||||
|
contractAddress = contractAddress.strip()
|
||||||
|
if not check_flo_address(contractAddress, is_testnet):
|
||||||
|
return jsonify(description='contractAddress validation failed'), 400
|
||||||
|
|
||||||
|
|
||||||
contractList = []
|
contractList = []
|
||||||
conn = sqlite3.connect(os.path.join(dbfolder, 'system.db'))
|
conn = sqlite3.connect(os.path.join(dbfolder, 'system.db'))
|
||||||
@ -1646,30 +1651,33 @@ async def getcontractparticipants_v2():
|
|||||||
token = contractStructure['tokenIdentification']
|
token = contractStructure['tokenIdentification']
|
||||||
c.execute('SELECT id, participantAddress, tokenAmount, userChoice, transactionHash, winningAmount FROM contractparticipants')
|
c.execute('SELECT id, participantAddress, tokenAmount, userChoice, transactionHash, winningAmount FROM contractparticipants')
|
||||||
result = c.fetchall()
|
result = c.fetchall()
|
||||||
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}
|
participation = {'participantFloAddress': row[1], 'tokenAmount': row[2], 'userChoice': row[3], 'transactionHash': row[4], 'winningAmount': row[5], 'tokenIdentification': token}
|
||||||
|
returnval.append(participation)
|
||||||
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()
|
||||||
conn.close()
|
conn.close()
|
||||||
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]}
|
participation = {'participantFloAddress': row[1], 'tokenAmount': row[2], 'userChoice': row[3], 'transactionHash': row[4]}
|
||||||
|
returnval.append(participation)
|
||||||
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')
|
||||||
result = c.fetchall()
|
result = c.fetchall()
|
||||||
conn.close()
|
conn.close()
|
||||||
returnval = {}
|
returnval = []
|
||||||
for row in result:
|
for row in result:
|
||||||
returnval[row[1]] = {'participantFloAddress': row[1], 'tokenAmount': row[2], 'transactionHash': row[4]}
|
participation = {'participantFloAddress': row[1], 'tokenAmount': row[2], 'transactionHash': row[4]}
|
||||||
|
returnval.append(participation)
|
||||||
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()
|
||||||
returnval = {}
|
returnval = []
|
||||||
for row in contract_participants:
|
for row in contract_participants:
|
||||||
returnval[row[1]] = {
|
participation = {
|
||||||
'participantFloAddress': row[1],
|
'participantFloAddress': row[1],
|
||||||
'participationAmount': row[2],
|
'participationAmount': row[2],
|
||||||
'swapPrice': float(row[3]),
|
'swapPrice': float(row[3]),
|
||||||
@ -1678,6 +1686,7 @@ async def getcontractparticipants_v2():
|
|||||||
'blockHash': row[6],
|
'blockHash': row[6],
|
||||||
'swapAmount': row[7]
|
'swapAmount': row[7]
|
||||||
}
|
}
|
||||||
|
returnval.append(participation)
|
||||||
conn.close()
|
conn.close()
|
||||||
return jsonify(contractName=contractName, contractAddress=contractAddress, participantInfo=returnval), 200
|
return jsonify(contractName=contractName, contractAddress=contractAddress, participantInfo=returnval), 200
|
||||||
else:
|
else:
|
||||||
@ -1927,6 +1936,31 @@ async def smartcontracttransactions():
|
|||||||
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
|
||||||
|
|
||||||
|
|
||||||
|
@app.route('/api/v2/smartContractDeposits', methods=['GET'])
|
||||||
|
async def smartcontractdeposits():
|
||||||
|
contractName = request.args.get('contractName')
|
||||||
|
if contractName is None:
|
||||||
|
return jsonify(description='Smart Contract\'s name hasn\'t been passed'), 400
|
||||||
|
contractName = contractName.strip().lower()
|
||||||
|
|
||||||
|
contractAddress = request.args.get('contractAddress')
|
||||||
|
if contractAddress is None:
|
||||||
|
return jsonify(description='Smart Contract\'s address hasn\'t been passed'), 400
|
||||||
|
contractAddress = contractAddress.strip()
|
||||||
|
if not check_flo_address(contractAddress, is_testnet):
|
||||||
|
return jsonify(description='contractAddress validation failed'), 400
|
||||||
|
|
||||||
|
contractDbName = '{}-{}.db'.format(contractName, contractAddress)
|
||||||
|
filelocation = os.path.join(dbfolder, 'smartContracts', contractDbName)
|
||||||
|
|
||||||
|
if os.path.isfile(filelocation):
|
||||||
|
# active deposits
|
||||||
|
#
|
||||||
|
return 'complete API'
|
||||||
|
else:
|
||||||
|
return jsonify(description='Smart Contract with the given name doesn\'t exist'), 404
|
||||||
|
|
||||||
|
|
||||||
@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
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user