-
Notifications
You must be signed in to change notification settings - Fork 0
/
genAddress.py
87 lines (71 loc) · 3.6 KB
/
genAddress.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
# 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, addresses
from PyQt5.QtCore import *
from PyQt5 import QtWidgets
from rpcworker import progress_fn, thread_complete, Worker, WorkerSignals
#from resource import resource_path
def resource_path(relative_path):
if hasattr(sys, '_MEIPASS'):
return os.path.join(sys._MEIPASS, relative_path)
return os.path.join(os.path.abspath('.'), relative_path)
def new_addresses_sync(uname, pwd):
global new_address, pub_key
new_address = ''
pub_key = ''
try:
#cmd = "bin/pktctl -u "+ uname +" -P "+ pwd +" --wallet getnewaddress"
#new_address = (subprocess.Popen(resource_path(cmd), shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()[0]).decode("utf-8")
new_address = (subprocess.Popen([resource_path('bin/pktctl'), '-u', uname, '-P', pwd, '--wallet', 'getnewaddress'], shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()[0]).decode("utf-8")
if new_address:
pubkey_cmd = "bin/pktctl -u "+ uname +" -P "+ pwd +" --wallet validateaddress " + new_address
try:
pub_key = json.loads(subprocess.Popen(resource_path(pubkey_cmd), shell=True, stdout=subprocess.PIPE).communicate()[0])["pubkey"]
#pub_key = (json.loads(subprocess.Popen([resource_path('bin/pktctl'), '-u', uname, '-P', pwd, '--wallet', 'validateaddress', new_address], shell=False, stdout=subprocess.PIPE).communicate()[0]))["pubkey"]
print(pub_key)
except subprocess.CalledProcessError as e:
print(e.output)
else:
print('Failed to create new addresses')
except subprocess.CalledProcessError as e:
print('Failed to create new addresses', e.output)
return new_address, pub_key
def new_addresses(uname, pwd, progress_callback):
global new_address, pub_key
new_address = ''
pub_key = ''
try:
cmd = "bin/pktctl -u "+ uname +" -P "+ pwd +" --wallet getnewaddress"
new_address = (subprocess.Popen(resource_path(cmd), shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()[0]).decode("utf-8")
'''
if new_address:
pubkey_cmd = "bin/pktctl -u "+ uname +" -P "+ pwd +" --wallet validateaddress " + new_address
try:
pub_key = json.loads(subprocess.Popen(resource_path(pubkey_cmd), shell=True, stdout=subprocess.PIPE).communicate()[0])["pubkey"]
except subprocess.CalledProcessError as e:
print(e.output)
else:
print('Failed to create new addresses')
'''
except subprocess.CalledProcessError as e:
print('Failed to create new addresses', e.output)
return new_address, pub_key
def get_new_address(u, p, win, state, pool):
global window, uname, pwd, worker_state_active, threadpool
window = win
uname = u
pwd = p
worker_state_active = state
threadpool = pool
# Pass the function to execute
if not worker_state_active['GET_NEW_ADDRESS']:
worker_state_active['GET_NEW_ADDRESS'] = True
print_address(new_addresses_sync(uname, pwd))
def print_address(list):
window.address_line.setText(list[0])
#window.pubkey_line.setText(list[1])
#window.pubkey_line.repaint()
#window.pubkey_line.setCursorPosition(0)
worker_state_active['GET_NEW_ADDRESS']= False
addresses.get_addresses(uname, pwd, window, "addresses", worker_state_active, threadpool)