Adding support for tokens
This commit is contained in:
parent
e5280ff279
commit
deb6354af6
@ -8,12 +8,96 @@ from flask import Flask
|
||||
dbfolder = ''
|
||||
app = Flask(__name__)
|
||||
|
||||
@app.route('/api/v1.0/getsmartContractlist', methods=['GET'])
|
||||
def getcontractlist():
|
||||
'''token = request.args.get('token')
|
||||
# FLO TOKEN APIs
|
||||
|
||||
@app.route('/api/v1.0/getaddressbalance', methods=['GET'])
|
||||
def getaddressbalance():
|
||||
address = request.args.get('address')
|
||||
token = request.args.get('token')
|
||||
|
||||
if address is None or token is None:
|
||||
return jsonify(result='error')
|
||||
|
||||
dblocation = dbfolder + token + '.db'
|
||||
if os.path.exists(dblocation):
|
||||
conn = sqlite3.connect(dblocation)
|
||||
c = conn.cursor()
|
||||
else:
|
||||
return 'Token doesn\'t exist'
|
||||
c.execute('SELECT SUM(transferBalance) FROM activeTable WHERE address="{}"'.format(address))
|
||||
balance = c.fetchall()[0][0]
|
||||
conn.close()
|
||||
return jsonify(result='ok', token=token, address=address, balance=balance)
|
||||
|
||||
|
||||
@app.route('/api/v1.0/gettokeninfo', methods=['GET'])
|
||||
def gettokeninfo():
|
||||
token = request.args.get('token')
|
||||
|
||||
if token is None:
|
||||
return jsonify(result='error')'''
|
||||
return jsonify(result='error')
|
||||
|
||||
dblocation = dbfolder + token + '.db'
|
||||
if os.path.exists(dblocation):
|
||||
conn = sqlite3.connect(dblocation)
|
||||
c = conn.cursor()
|
||||
else:
|
||||
return 'Token doesn\'t exist'
|
||||
c.execute('SELECT * FROM transactionHistory WHERE id=1')
|
||||
incorporationRow = c.fetchall()[0]
|
||||
c.execute('SELECT COUNT (DISTINCT address) FROM activeTable')
|
||||
numberOf_distinctAddresses = c.fetchall()[0][0]
|
||||
conn.close()
|
||||
return jsonify(result='ok', token=token, incorporationAddress=incorporationRow[2], tokenSupply=incorporationRow[3],
|
||||
transactionHash=incorporationRow[6], blockchainReference=incorporationRow[7],
|
||||
activeAddress_no=numberOf_distinctAddresses)
|
||||
|
||||
|
||||
@app.route('/api/v1.0/gettransactions', methods=['GET'])
|
||||
def gettransactions():
|
||||
token = request.args.get('token')
|
||||
senderFloAddress = request.args.get('senderFloAddress')
|
||||
destFloAddress = request.args.get('destFloAddress')
|
||||
|
||||
if token is None:
|
||||
return jsonify(result='error')
|
||||
|
||||
dblocation = dbfolder + token + '.db'
|
||||
if os.path.exists(dblocation):
|
||||
conn = sqlite3.connect(dblocation)
|
||||
conn.row_factory = sqlite3.Row
|
||||
c = conn.cursor()
|
||||
else:
|
||||
return 'Token doesn\'t exist'
|
||||
|
||||
if senderFloAddress and not destFloAddress:
|
||||
c.execute(
|
||||
'SELECT blockNumber, sourceFloAddress, destFloAddress, transferAmount, blockchainReference FROM transactionHistory WHERE sourceFloAddress="{}" ORDER BY id DESC LIMIT 100'.format(
|
||||
senderFloAddress))
|
||||
if not senderFloAddress and destFloAddress:
|
||||
c.execute(
|
||||
'SELECT blockNumber, sourceFloAddress, destFloAddress, transferAmount, blockchainReference FROM transactionHistory WHERE destFloAddress="{}" ORDER BY id DESC LIMIT 100'.format(
|
||||
destFloAddress))
|
||||
if senderFloAddress and destFloAddress:
|
||||
c.execute(
|
||||
'SELECT blockNumber, sourceFloAddress, destFloAddress, transferAmount, blockchainReference FROM transactionHistory WHERE sourceFloAddress="{}" OR destFloAddress="{}" ORDER BY id DESC LIMIT 100'.format(
|
||||
senderFloAddress, destFloAddress))
|
||||
|
||||
else:
|
||||
c.execute(
|
||||
'SELECT blockNumber, sourceFloAddress, destFloAddress, transferAmount, blockchainReference FROM transactionHistory ORDER BY id DESC LIMIT 100')
|
||||
latestTransactions = c.fetchall()
|
||||
conn.close()
|
||||
rowarray_list = []
|
||||
for row in latestTransactions:
|
||||
d = dict(zip(row.keys(), row)) # a dict with column names as keys
|
||||
rowarray_list.append(d)
|
||||
return jsonify(result='ok', transactions=rowarray_list)
|
||||
|
||||
# SMART CONTRACT APIs
|
||||
|
||||
@app.route('/api/v1.0/getsmartContractlist', methods=['GET'])
|
||||
def getcontractlist():
|
||||
filelist = []
|
||||
for item in os.listdir(os.path.join(dbfolder,'smartContracts')):
|
||||
if os.path.isfile(os.path.join(dbfolder, 'smartContracts', item)):
|
||||
|
||||
Loading…
Reference in New Issue
Block a user