getParticipantDetails : Added support for one-time-event internal trigger contract
This commit is contained in:
parent
7894562e0c
commit
5f7e497043
@ -816,7 +816,6 @@ async def getParticipantDetails():
|
|||||||
participationDetailsList = []
|
participationDetailsList = []
|
||||||
for contract in participant_address_contracts:
|
for contract in participant_address_contracts:
|
||||||
detailsDict = {}
|
detailsDict = {}
|
||||||
|
|
||||||
contract_db = os.path.join(dbfolder, 'smartContracts', f"{contract[3]}-{contract[4]}.db")
|
contract_db = os.path.join(dbfolder, 'smartContracts', f"{contract[3]}-{contract[4]}.db")
|
||||||
# Make db connection and fetch contract structure
|
# Make db connection and fetch contract structure
|
||||||
conn = sqlite3.connect(contract_db)
|
conn = sqlite3.connect(contract_db)
|
||||||
@ -848,7 +847,6 @@ async def getParticipantDetails():
|
|||||||
|
|
||||||
if len(participant_details) > 0:
|
if len(participant_details) > 0:
|
||||||
participationList = []
|
participationList = []
|
||||||
|
|
||||||
for participation in participant_details:
|
for participation in participant_details:
|
||||||
c.execute("SELECT value FROM contractstructure WHERE attribute='selling_token'")
|
c.execute("SELECT value FROM contractstructure WHERE attribute='selling_token'")
|
||||||
structure = c.fetchall()
|
structure = c.fetchall()
|
||||||
@ -867,17 +865,13 @@ async def getParticipantDetails():
|
|||||||
|
|
||||||
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
|
||||||
pass
|
|
||||||
elif contractStructure['contractType']=='one-time-event' and 'exitconditions' in contractStructure.keys():
|
|
||||||
# normal results + winning/losing details
|
|
||||||
conn = sqlite3.connect(dblocation)
|
conn = sqlite3.connect(dblocation)
|
||||||
c = conn.cursor()
|
c = conn.cursor()
|
||||||
|
|
||||||
detailsDict = {}
|
detailsDict = {}
|
||||||
detailsDict['contractName'] = row[3]
|
detailsDict['contractName'] = contract[3]
|
||||||
detailsDict['contractAddress'] = row[4]
|
detailsDict['contractAddress'] = contract[4]
|
||||||
detailsDict['tokenAmount'] = row[5]
|
detailsDict['tokenAmount'] = contract[5]
|
||||||
detailsDict['transactionHash'] = row[6]
|
detailsDict['transactionHash'] = contract[6]
|
||||||
|
|
||||||
c.execute(f"select status, tokenIdentification, contractType, blockNumber, blockHash, incorporationDate, expiryDate, closeDate from activecontracts where contractName='{detailsDict['contractName']}' and contractAddress='{detailsDict['contractAddress']}'")
|
c.execute(f"select status, tokenIdentification, contractType, blockNumber, blockHash, incorporationDate, expiryDate, closeDate from activecontracts where contractName='{detailsDict['contractName']}' and contractAddress='{detailsDict['contractAddress']}'")
|
||||||
temp = c.fetchall()
|
temp = c.fetchall()
|
||||||
@ -899,8 +893,60 @@ async def getParticipantDetails():
|
|||||||
# Make db connection and fetch data
|
# Make db connection and fetch data
|
||||||
conn = sqlite3.connect(filelocation)
|
conn = sqlite3.connect(filelocation)
|
||||||
c = conn.cursor()
|
c = conn.cursor()
|
||||||
c.execute(
|
c.execute('SELECT attribute,value FROM contractstructure')
|
||||||
'SELECT attribute,value FROM contractstructure')
|
result = c.fetchall()
|
||||||
|
contractStructure = {}
|
||||||
|
conditionDict = {}
|
||||||
|
counter = 0
|
||||||
|
for item in result:
|
||||||
|
if list(item)[0] == 'exitconditions':
|
||||||
|
conditionDict[counter] = list(item)[1]
|
||||||
|
counter = counter + 1
|
||||||
|
else:
|
||||||
|
contractStructure[list(item)[0]] = list(item)[1]
|
||||||
|
if len(conditionDict) > 0:
|
||||||
|
contractStructure['exitconditions'] = conditionDict
|
||||||
|
del counter, conditionDict
|
||||||
|
|
||||||
|
if 'payeeAddress' in contractStructure:
|
||||||
|
# contract is of the type external trigger
|
||||||
|
# check if the contract has been closed
|
||||||
|
c.execute(f"SELECT tokenAmount FROM contractparticipants where participantAddress='{floAddress}'")
|
||||||
|
result = c.fetchall()
|
||||||
|
conn.close()
|
||||||
|
detailsDict['tokenAmount'] = result[0][0]
|
||||||
|
|
||||||
|
elif contractStructure['contractType']=='one-time-event' and 'exitconditions' in contractStructure.keys():
|
||||||
|
# normal results + winning/losing details
|
||||||
|
conn = sqlite3.connect(dblocation)
|
||||||
|
c = conn.cursor()
|
||||||
|
detailsDict = {}
|
||||||
|
detailsDict['contractName'] = contract[3]
|
||||||
|
detailsDict['contractAddress'] = contract[4]
|
||||||
|
detailsDict['tokenAmount'] = contract[5]
|
||||||
|
detailsDict['transactionHash'] = contract[6]
|
||||||
|
|
||||||
|
c.execute(f"select status, tokenIdentification, contractType, blockNumber, blockHash, incorporationDate, expiryDate, closeDate from activecontracts where contractName='{detailsDict['contractName']}' and contractAddress='{detailsDict['contractAddress']}'")
|
||||||
|
temp = c.fetchall()
|
||||||
|
detailsDict['status'] = temp[0][0]
|
||||||
|
detailsDict['tokenIdentification'] = temp[0][1]
|
||||||
|
detailsDict['contractType'] = temp[0][2]
|
||||||
|
detailsDict['blockNumber'] = temp[0][3]
|
||||||
|
detailsDict['blockHash'] = temp[0][4]
|
||||||
|
detailsDict['incorporationDate'] = temp[0][5]
|
||||||
|
if temp[0][6]:
|
||||||
|
detailsDict['expiryDate'] = temp[0][6]
|
||||||
|
if temp[0][7]:
|
||||||
|
detailsDict['closeDate'] = temp[0][7]
|
||||||
|
|
||||||
|
# check if the contract has been closed
|
||||||
|
contractDbName = '{}-{}.db'.format(detailsDict['contractName'].strip(), detailsDict['contractAddress'].strip())
|
||||||
|
filelocation = os.path.join(dbfolder, 'smartContracts', contractDbName)
|
||||||
|
if os.path.isfile(filelocation):
|
||||||
|
# Make db connection and fetch data
|
||||||
|
conn = sqlite3.connect(filelocation)
|
||||||
|
c = conn.cursor()
|
||||||
|
c.execute('SELECT attribute,value FROM contractstructure')
|
||||||
result = c.fetchall()
|
result = c.fetchall()
|
||||||
contractStructure = {}
|
contractStructure = {}
|
||||||
conditionDict = {}
|
conditionDict = {}
|
||||||
@ -918,20 +964,17 @@ async def getParticipantDetails():
|
|||||||
if 'exitconditions' in contractStructure:
|
if 'exitconditions' in contractStructure:
|
||||||
# contract is of the type external trigger
|
# contract is of the type external trigger
|
||||||
# check if the contract has been closed
|
# check if the contract has been closed
|
||||||
c.execute(
|
c.execute('select * from contractTransactionHistory where transactionType="trigger"')
|
||||||
'select * from contractTransactionHistory where transactionType="trigger"')
|
|
||||||
trigger = c.fetchall()
|
trigger = c.fetchall()
|
||||||
|
|
||||||
if detailsDict['status'] == 'closed':
|
if detailsDict['status'] == 'closed':
|
||||||
c.execute(
|
c.execute(f"SELECT userChoice, winningAmount FROM contractparticipants where participantAddress='{floAddress}'")
|
||||||
f"SELECT userChoice, winningAmount FROM contractparticipants where participantAddress='{floAddress}'")
|
|
||||||
result = c.fetchall()
|
result = c.fetchall()
|
||||||
conn.close()
|
conn.close()
|
||||||
detailsDict['userChoice'] = result[0][0]
|
detailsDict['userChoice'] = result[0][0]
|
||||||
detailsDict['winningAmount'] = result[0][1]
|
detailsDict['winningAmount'] = result[0][1]
|
||||||
else:
|
else:
|
||||||
c.execute(
|
c.execute(f"SELECT userChoice FROM contractparticipants where participantAddress='{floAddress}'")
|
||||||
f"SELECT userChoice FROM contractparticipants where participantAddress='{floAddress}'")
|
|
||||||
result = c.fetchall()
|
result = c.fetchall()
|
||||||
conn.close()
|
conn.close()
|
||||||
detailsDict['userChoice'] = result[0][0]
|
detailsDict['userChoice'] = result[0][0]
|
||||||
@ -951,8 +994,6 @@ async def getsmartcontracttransactions():
|
|||||||
contractName = request.args.get('contractName')
|
contractName = request.args.get('contractName')
|
||||||
contractAddress = request.args.get('contractAddress')
|
contractAddress = request.args.get('contractAddress')
|
||||||
|
|
||||||
pdb.set_trace()
|
|
||||||
|
|
||||||
if contractName is None:
|
if contractName is None:
|
||||||
return jsonify(result='error', description='Smart Contract\'s name hasn\'t been passed')
|
return jsonify(result='error', description='Smart Contract\'s name hasn\'t been passed')
|
||||||
|
|
||||||
@ -1393,8 +1434,7 @@ if not os.path.isfile(f"system.db"):
|
|||||||
# create an empty db
|
# create an empty db
|
||||||
conn = sqlite3.connect('system.db')
|
conn = sqlite3.connect('system.db')
|
||||||
c = conn.cursor()
|
c = conn.cursor()
|
||||||
c.execute('''CREATE TABLE ratepairs
|
c.execute('''CREATE TABLE ratepairs (id integer primary key, ratepair text, price real)''')
|
||||||
(id integer primary key, ratepair text, price real)''')
|
|
||||||
c.execute("INSERT INTO ratepairs(ratepair, price) VALUES ('BTCBTC', 1)")
|
c.execute("INSERT INTO ratepairs(ratepair, price) VALUES ('BTCBTC', 1)")
|
||||||
c.execute("INSERT INTO ratepairs(ratepair, price) VALUES ('BTCUSD', -1)")
|
c.execute("INSERT INTO ratepairs(ratepair, price) VALUES ('BTCUSD', -1)")
|
||||||
c.execute("INSERT INTO ratepairs(ratepair, price) VALUES ('BTCINR', -1)")
|
c.execute("INSERT INTO ratepairs(ratepair, price) VALUES ('BTCINR', -1)")
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user