forked from vanissoft/token_distribution_bitshares
-
Notifications
You must be signed in to change notification settings - Fork 2
/
wmain.py
259 lines (203 loc) · 6.36 KB
/
wmain.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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
#
# (c) 2017 elias/vanissoft
#
#
#
from browser import window, document, ajax, alert
import wglobals
import json
Callbacks = {}
Asset_data = None
AssetHold_data = None
Status_list = []
Msg_list = []
Msg_sel = 0
Cnt = 0
def gotasset(rtn):
global Asset_data
print("gotasset", rtn)
Asset_data = rtn['data']
document['lidasset'].innerHTML = rtn['data']['td_msg']
if AssetHold_data is not None:
document['btnsnapshot'].disabled = False
document['lblsnapshot_holders'].innerHTML = " ?"
document['lblsnapshot_balance'].innerHTML = " ?"
def gotassethold(rtn):
global AssetHold_data
AssetHold_data = rtn['data']
if Asset_data is not None:
document['btnsnapshot'].disabled = False
document['lidassethold'].innerHTML = rtn['data']['td_msg']
document['lblsnapshot_status'].innerHTML = "Ready"
document['btnsnapshot'].disabled = False
def query(url, callback):
global Cnt
url = url+"&nonce="+str(Cnt)
Callbacks[url] = callback
req = ajax.ajax()
req.open('GET', url, True)
req.send()
req.bind('complete', ajax_end)
Cnt += 1
def ajax_end(request):
global Cnt
try:
rtn = json.loads(request.responseText)
except Exception as err:
print(err.__repr__())
return
if rtn is None:
print("error\n"+request.responseText)
return
print(rtn['request'])
if rtn['request'] in Callbacks:
print("callback ok")
Callbacks[rtn['request']](rtn)
del Callbacks[rtn['request']]
def post(url, data, callback):
Callbacks[url] = callback
req = ajax.ajax()
req.open('POST', url, True)
req.send(json.dumps(data))
req.bind('complete', ajax_end)
def launch_requested(rtn):
global Msg_sel
document['table-container'].clear()
Msg_sel = 1
def snapshot_requested(rtn):
global Msg_sel
document['table-container'].clear()
Msg_sel = 0
def launch_distribution(dummy):
dat = {'form': {}}
dat['form']['key'] = document['fkey'].value
dat['form']['message'] = document['fmessage'].value
post("/post/launch?key=null", dat, launch_requested)
def launch_snapshot(dummy):
document['lblsnapshot_holders'].innerHTML = " ?"
document['lblsnapshot_balance'].innerHTML = " ?"
document['lblsnapshot_status'].innerHTML = " ?"
document['dcsv'].innerHTML = ''
dat = {'form': {}}
dat['form']['assethold_id'] = AssetHold_data['id']
dat['form']['asset_id'] = Asset_data['id']
dat['form']['amount'] = document['famount'].value
dat['form']['ratio'] = document['fratio'].value
dat['form']['hold_minimum'] = document['fholdminimum'].value
dat['form']['minimum'] = document['fminimum'].value
dat['form']['transfer_fee'] = document['ftransferfee'].value
post("/post/snapshot?key=null", dat, snapshot_requested)
def table_summary(dat):
from browser.html import TABLE, TR, TH, TD
from browser import html
tbl = TABLE()
row = TR()
for h in dat[0].split(";"):
row <= TH(h)
tbl <= row
for r in dat[1].split("#"):
row = TR()
for f in r.split(";"):
row <= TD(f)
tbl <= row
document['table-container'].clear()
document['table-container'] <= html.H5("Summary of first 10 accounts")
document['table-container'] <= tbl
def broker(op):
if op[0] == "snapshot_start":
document['lblsnapshot_status'].innerHTML = "<strong> {}</strong>".format("Calculating")
document['lblsnapshot_holders'].innerHTML = " ?"
document['lblsnapshot_balance'].innerHTML = " ?"
elif op[0] == "snapshot_end":
document['lblsnapshot_holders'].innerHTML = "<strong> {}</strong>".format(op[3])
document['lblsnapshot_balance'].innerHTML = "<strong> {}</strong>".format(op[2])
document['lblsnapshot_costs'].innerHTML = "<strong> {}</strong>".format(op[4])
document['lblsnapshot_status'].innerHTML = "<strong> {}</strong>".format("OK")
document['btnsnapshot'].disabled = False
document['btnlaunch'].disabled = False
elif op[0] == "csv_exported":
document['dcsv'].innerHTML = '<a href="{}">{}</a>'.format(op[2], "Top holders CSV")
elif op[0] == "csv_data":
table_summary(op[2:])
elif op[0] == "launch_error":
alert(op[1])
def status_act():
global Msg_list, Status_list, Msg_sel
while True:
if len(Msg_list) == 0:
print("No data.", end='')
break
print("status data")
msg = Msg_list.pop(0)
if msg[0] == "*": # action message
print("status data", msg)
broker(msg.split("|")[1:])
else:
Status_list.append(msg)
st = ''
for lin in Status_list[::-1]:
st += lin +"<br>"
Status_list = Status_list[-10:]
if Msg_sel == 0:
document['message-area1'].innerHTML = st
elif Msg_sel == 1:
document['message-area2'].innerHTML = st
print("status_act")
def gotmessage(rtn):
global Msg_list
if rtn['data'] == None:
print("no message.", end='')
return
Msg_list.extend(rtn['data'])
print(Msg_list)
status_act()
def messages_refresh():
query("/get/getmessage?key=null", gotmessage)
def famount_chg(ev):
if float(ev.target.value) > 0:
document['fratio'].value = 0
document['fratio'].disabled = True
else:
document['fratio'].disabled = False
def fratio_chg(ev):
if float(ev.target.value) > 0:
document['famount'].value = 0
document['famount'].disabled = True
else:
document['famount'].disabled = False
def faccount_chg(ev):
if ev.target.value.strip() == '':
return
query("/get/getaccount?account=" + ev.target.value, gotaccount)
def fasset_chg(ev):
if ev.target.value.strip() == '':
return
query("/get/getasset?asset=" + ev.target.value, gotasset)
def fassethold_chg(ev):
if ev.target.value.strip() == '':
return
query("/get/getasset?asset=" + ev.target.value, gotassethold)
#table_summary(["HEAD1;head2;head3","sadf;fgdfg;erwer#a234;32432;32434"])
document['fasset'].value = ''
document['fasset'].bind('change', fasset_chg)
document['fassethold'].value = ''
document['fassethold'].bind('change', fassethold_chg)
document['fkey'].value = ''
document['famount'].value = 0
document['famount'].bind('change', famount_chg)
document['fratio'].value = 0
document['fratio'].bind('change', fratio_chg)
document['fholdminimum'].value = 0
document['fminimum'].value = 0
document['ftransferfee'].value = 0.04
document['lidasset'].innerHTML = 'id: ???'
document['lidassethold'].innerHTML = 'id: ???'
document['lblsnapshot_holders'].innerHTML = " ?"
document['lblsnapshot_balance'].innerHTML = " ?"
document['lblsnapshot_status'].innerHTML = " ?"
document['dcsv'].innerHTML = ''
document['btnlaunch'].disabled = True
document['btnsnapshot'].disabled = True
document['btnlaunch'].bind('click', launch_distribution)
document['btnsnapshot'].bind('click', launch_snapshot)
wglobals.set_timer(0, messages_refresh, 2)