-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathingest.py
89 lines (75 loc) · 3.5 KB
/
ingest.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
# Copyright (c) 2020 Vishnu J. Seesahai
# Use of this source code is governed by an MIT
# license that can be found in the LICENSE file.
import subprocess, os, sys, json, threading, signal, traceback, rpcworker
from PyQt5.QtCore import *
from PyQt5 import QtWidgets
#from resource import resource_path
from rpcworker import progress_fn, thread_complete
_translate = QCoreApplication.translate
def resource_path(relative_path):
#dir = QDir.currentPath()
if hasattr(sys, '_MEIPASS'):
return os.path.join(sys._MEIPASS, relative_path)
return os.path.join(os.path.abspath('.'), relative_path)
def ingest_keys(uname, pwd, progress_callback):
global err, err_2
try:
cmd = "bin/pktctl -u "+ uname +" -P "+ pwd +" --wallet walletpassphrase " + passphrase + ' 1000'
result, err = (subprocess.Popen(resource_path(cmd), shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate())
result = result.decode('utf-8')
err = err.decode('utf-8')
if not err:
try:
for key in keys:
cmd_2 = "bin/pktctl -u "+ uname +" -P "+ pwd +" --wallet importprivkey " + key.strip()
result_2, err_2 = (subprocess.Popen(resource_path(cmd_2), shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate())
result_2 = result_2.decode('utf-8')
err_2 = err_2.decode('utf-8')
if err_2:
#window.import_text.clear()
#window.import_text.setPlaceholderText(_translate("MainWindow","Could not import, check key/s."))
break
else:
result_2 = 'success'
return result_2
except subprocess.CalledProcessError as e:
print('Failed to retrieve key.', e.output)
else:
print('error:',err)
except subprocess.CalledProcessError as e:
print('Failed to unlock wallet, check password.', e.output)
def all_keys(u, p, k, pp, win, state, pool):
global window, uname, pwd, worker_state_active, keys, passphrase
window = win
uname = u
pwd = p
worker_state_active = state
threadpool = pool
keys = k
passphrase = pp
window.import_text.clear()
window.import_text.setPlainText('Importing ...')
if not worker_state_active['IMP_PRIV_KEY']:
worker_state_active['IMP_PRIV_KEY'] = True
worker = rpcworker.Worker(ingest_keys, uname, pwd)
worker.signals.result.connect(print_result)
worker.signals.finished.connect(thread_complete)
worker.signals.progress.connect(progress_fn)
# Execute
threadpool.start(worker)
def print_result(result):
# Relock wallet.
lock = "bin/pktctl -u "+ uname +" -P "+ pwd +" --wallet walletlock"
result_lock, err_lock = subprocess.Popen(resource_path(lock), shell=True, stdout=subprocess.PIPE).communicate()
window.import_text.clear()
if result:
window.import_text.setPlaceholderText(_translate("MainWindow","Keys successfully added."))
i = window.stackedWidget.indexOf(window.added_keys_page)
window.stackedWidget.setCurrentIndex(i)
elif err:
if 'ErrWrongPassphrase' in err:
window.import_text.setPlaceholderText(_translate("MainWindow","Wrong wallet password entered."))
else:
window.import_text.setPlaceholderText(_translate("MainWindow","Could not import, check key/s."))
worker_state_active['IMP_PRIV_KEY'] = False