-
Notifications
You must be signed in to change notification settings - Fork 0
/
aquachain-tk
executable file
·188 lines (166 loc) · 6.84 KB
/
aquachain-tk
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
#!/usr/bin/env python3
from tkinter import Tk, Label, Button, Frame, IntVar, PhotoImage
from aquachain.aquatool import AquaTool
from aquachain.aquakeys import Keystore
from aquachaintk.scenes import StartPage, ThemedFrame, LogoPath
from aquachaintk.scenes import PageNone, PageAbout, PageReceive, PageWallets
from aquachaintk.filterlooper import LogFilterLooper, LogQueue
from datetime import datetime
from aquachaintk.blockcache import BlockFormatter
from argparse import ArgumentParser
from aquachaintk.toolbar import Toolbar, NoButton
import os
def default_keystore_dir():
import sys
data_dir = 'aquakeys'
if sys.platform == 'darwin':
data_dir = os.path.expanduser(os.path.join(
"~",
"Library",
"AquaChain",
"aquakeys",
))
elif sys.platform in {'linux', 'linux2', 'linux3'}:
data_dir = os.path.expanduser(os.path.join(
"~",
".aquachain",
"aquakeys",
))
elif sys.platform == 'win32':
data_dir = os.path.expanduser(os.path.join(
"\\",
"~",
"AppData",
"Roaming",
"AquaChain",
"aquakeys",
))
return data_dir
DEFAULT_REFRESH_TIME=5
DEFAULT_KEYSTORE_DIR=default_keystore_dir()
parser = ArgumentParser(description='Aquachain TK wallet', epilog='ONE of -r or -i flags must be set. Preferably -i because its faster and uses local node (with no http rpc) to learn more: https://aquachain.github.io')
flag = parser.add_argument
flag( '-r', '--rpchost', dest='rpchost', help='rpc host (with https:// prefix)')
flag('-i', '--ipcpath', dest='ipcpath', help='ipc path (filename)')
flag( '-t', '--refresh', dest='refresh', type=int, default=DEFAULT_REFRESH_TIME, help=f'refresh rate (in seconds), default: {DEFAULT_REFRESH_TIME}')
flag('-k', '--keystore', dest='keystore', default=DEFAULT_KEYSTORE_DIR, help=f'keystore directory, default: {DEFAULT_KEYSTORE_DIR}')
ARGS = parser.parse_args()
if ARGS.rpchost == None and ARGS.ipcpath == None:
print("Please select aquachain node to connect to with the '-r' OR '-i' flag (or -h for help)")
quit()
if ARGS.rpchost != None and ARGS.ipcpath != None:
print("Please select ONE aquachain node to connect to with the '-r' OR '-i' flag (or -h for help)")
quit()
def now():
return datetime.utcnow()
class Application(Tk):
def __init__(self):
Tk.__init__(self)
# self.wm_geometry(newGeometry='800x400-100+100')
self.version = 'Aquachain TK v0.0.3'
self.configure(background='black')
self.logo = PhotoImage(file=LogoPath)
self.head_difficulty = IntVar()
self.head_number = IntVar()
self.head_timing = IntVar()
self.head_timestamp = IntVar()
self.total_supply = IntVar()
self.head_difficulty.set(0)
self.head_number.set(0)
self.head_timing.set(0)
self.head_timestamp.set(0)
self.total_supply.set(0)
# connect to aquachain node
self.aqua = None
if ARGS.rpchost == None:
self.aqua = AquaTool(ipcpath=ARGS.ipcpath)
else:
self.aqua = AquaTool(rpchost=ARGS.rpchost)
# get latest block from aquachain node
self.head = self.aqua.gethead()
self.rehead()
# keys
self.keystore = Keystore(directory=ARGS.keystore)
self.hdkeys = []
self.addresses = []
# start new-block filter
self.queue = LogQueue()
event_filter = self.aqua.w3.eth.filter('latest')
self.looper = LogFilterLooper(self, self.queue, event_filter, ARGS.refresh, aqua=self.aqua)
self.looper.start()
# TK
self._mainframe = Frame(self, background='green')
self._mainframe.pack(side='top', anchor='n', expand=True, fill='both')
self._framename = ''
self.buttons = btns = {
'Quit': NoButton(text='Quit',
command=self.quit, width=13),
'Lock': NoButton(text='Lock',
command=self.lock, width=13),
'PageWallets': NoButton(text='Wallets',
command=self.switch_frame, arg=PageWallets, width=13),
'PageAbout': NoButton(text='About',
command=self.switch_frame, arg=PageAbout, width=13),
'PageReceive': NoButton(text='Recv',
command=self.switch_frame, arg=PageReceive, width=13),
}
self._toolbar = Toolbar(self._mainframe, app=self, logo=self.logo)
self._toolbar.addbtns(btns)
self._toolbar.grid(sticky='nw', columnspan=1, column=0, row=0)
self._frame = ThemedFrame(self._mainframe, app=self, background='teal', height='100')
# take it away
self.homepage()
# def keygen(self):
# from tkinter import messagebox
# if messagebox.askokcancel(title='Generate New Key', message='You sure you want to generate a new key and save to disk?'):
# self.keystore.save_phrase(self.aqua.generate_phrase())
# self.switch_frame(PageWallets)
# else:
# print('cancled keygen')
def lock(self):
print('LOCKING WALLET')
self.hdkeys.clear()
self.addresses.clear()
print('SHOULD BE EMPTY:', self.hdkeys)
self.homepage()
def rehead(self):
print('new head block:', BlockFormatter(self.head))
self.head_number.set(int(self.head['number'], 16))
self.head_difficulty.set(int(self.head['difficulty'], 16))
timestamp = int(self.head['timestamp'], 16)
last = self.head_timestamp.get()
if last == 0:
last = int(self.aqua.getblockbyhash(self.head['parentHash'])['timestamp'], 16)
self.head_timing.set(timestamp-last)
self.head_timestamp.set(timestamp)
if ARGS.ipcpath != None:
self.total_supply.set(self.aqua.from_wei(int(self.aqua.Result('admin_supply', []), 16)))
def homepage(self):
# self.switch_frame(/StartPage)
self.switch_frame(StartPage)
def switch_frame(self, frame_class):
"""Destroys current frame and replaces it with a new one."""
self._framename = frame_class.__name__
new_frame = frame_class(parent=self._mainframe,app=self)
if self._frame is not None:
print('deleting:',self._frame)
self._frame.destroy()
self._frame = new_frame
self._frame.grid(sticky='ne',ipadx=100, column=1, row=0)
print('switchin to framename:', self._framename)
if __name__ == "__main__":
app = None
try:
app = Application()
app.mainloop()
except Exception as e:
print('fatality:', e)
# if not app is None:
if app:
print('got killed, stopping log filter thread')
app.looper.stop()
raise e
if app not in [None]:
print('stopping log filter thread')
app.looper.stop()
print("Have a nice day!")