-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathviews.py
113 lines (104 loc) · 4.72 KB
/
views.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
from DBUtils.PooledDB import PooledDB,SharedDBConnection
from django.shortcuts import render
from commands.constants import DATABASE_DEFAULT_ADDRESS, DATABASE_DEFAULT_PORT, DATABASE_DEFAULT_USER, DATABASE_DEFAULT_PASSWORD, DATABASE_DEFAULT_DATABASE
from commands.mysql_pool import MysqlPool
from commands.poseidon_deploy import deployPoseidon
from commands.zeth_token_deploy import deploy_asset
from commands.zeth_deploy import deploy
from commands.event_sync import event_sync
import threading
import pymysql
BACTYPE = "bac"
MIXERTYPE = "mixer"
mysql_pool = MysqlPool()
db = mysql_pool.conn()
cursor = db.cursor()
# Create your views here.
ownerAddr = "0xf1585b8d0e08a0a00fff662e24d67ba95a438256"
'''
def create_table():
print("check whether existed tables")
sqlSearch = "show tables"
cursor.execute(sqlSearch)
tables = cursor.fetchall()
db.commit()
tables_list = re.findall('(\'.*?\')',str(tables))
tables_list = [re.sub("'",'',each) for each in tables_list]
mertab = "merkletree"
contab = "contract"
tratab = "transactions"
if not mertab in tables_list:
print("create table merkletree")
sqlCreateMer = "create table merkletree (MID int, tree_data text(40000), blockNumber int)"
cursor.execute(sqlCreateMer)
db.commit()
if not contab in tables_list:
print("create table contract")
sqlCreateCon = "create table contract (conName char(20), conType char(20), conAddr text(500), time char(60), owner text(500), totalAmount bigint, shortName char(20))"
cursor.execute(sqlCreateCon)
db.commit()
if not tratab in tables_list:
print("create table transactions")
sqlCreateTra = "create table transactions (traType char(20), username char(20), vin int, vout int, input_notes char(40), output_specs text(2000), time char(60))"
cursor.execute(sqlCreateTra)
db.commit()
'''
def deploy_contract():
print("check whether existed bac token contract and mixer contract")
sqlSearchBac = "select * from contract where conType = %s"
db.ping(reconnect=True)
cursor.execute(sqlSearchBac, [BACTYPE])
resultBac = cursor.fetchall()
db.commit()
if resultBac:
sqlSearchMixer = "select * from contract where conType = %s"
cursor.execute(sqlSearchMixer, [MIXERTYPE])
resultMixer = cursor.fetchall()
db.commit()
if resultMixer:
print("all contract existed")
return
else:
token_address = resultBac[0]['conAddr']
print("deploy mixer contract on bac token contract of: ", token_address)
poseidon_address = deployPoseidon()
mixer_address = deploy(token_address, poseidon_address)
if mixer_address:
print("save mixer contract to database, address: ", mixer_address)
sqlInsertMixer = "insert into contract (conName, conType, conAddr, owner, totalAmount, shortName) values (%s, %s, %s, %s, %s, %s);"
conName = "Groth16Mixer"
shortName = "mixer_test"
cursor.execute(sqlInsertMixer, [conName, MIXERTYPE, mixer_address, ownerAddr, 0, shortName])
db.commit()
else:
print("deploy bac token contract")
shortName = "zk-AAA-demo"
minUnit = 18
totalAmount = 50000000000
token_address = deploy_asset("bac token test contract", shortName, minUnit, totalAmount)
if token_address:
print("save bac token contract to database, address: ", token_address)
sqlInsertBac = "insert into contract (conName, conType, conAddr, owner, totalAmount, shortName) values (%s, %s, %s, %s, %s, %s);"
conName = "BAC001"
cursor.execute(sqlInsertBac, [conName, BACTYPE, token_address, ownerAddr, totalAmount, shortName])
db.commit()
print("deploy mixer contract on bac token contract of: ", token_address)
poseidon_address = deployPoseidon()
mixer_address = deploy(token_address, poseidon_address)
if mixer_address:
print("save mixer contract to database, address: ", mixer_address)
sqlInsertMixer = "insert into contract (conName, conType, conAddr, owner, totalAmount, shortName) values (%s, %s, %s, %s, %s, %s);"
conNameMixer = "Groth16Mixer"
shortNameMixer = "mixer_test"
cursor.execute(sqlInsertMixer, [conNameMixer, MIXERTYPE, mixer_address, ownerAddr, 0, shortNameMixer])
db.commit()
#create_table()
deploy_contract()
class TaskThread(threading.Thread):
def run(self):
event_sync()
def eventSyncTask():
taskThread = TaskThread()
print("sync the event in new thread")
taskThread.start()
eventSyncTask()