-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathXlite_privateKeysImport.py
More file actions
70 lines (62 loc) · 2.51 KB
/
Xlite_privateKeysImport.py
File metadata and controls
70 lines (62 loc) · 2.51 KB
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
#!/usr/bin/env python
# Script will import private keys for a coin into a active xlite session.
# It require a running Xlite or Xlite-daemon session on same host.
#
# EXAMPLE:
# edit script with token and keys to import.
# python Xlite_privateKeysImport.py
token = "BLOCK"
private_keys = ["pk1", "pk2", "etc"]
import os
import json
import sys
import platform
import psutil
from func_defs import rpc_call, get_settings_folder, run_bin, kill_bin, is_xlite_daemon_running
# Default value
only_funded_address = True
# Check command-line arguments
if len(sys.argv) > 1:
arg = sys.argv[1]
if arg.lower() in ['true', 't']:
only_funded_address = True
elif arg.lower() in ['false', 'f']:
only_funded_address = False
path = get_settings_folder()
if __name__ == '__main__':
external_daemon = True
if not is_xlite_daemon_running():
external_daemon = False
with open('wallet_password.json') as f:
xlite_password = json.load(f)
process = run_bin(xlite_password)
files = os.listdir(path)
for file in files:
if file.endswith('.json') and file != 'config-master.json':
file_path = os.path.join(path, file)
# for filename in glob.glob(os.path.join(path, '*.json')):
# if 'config-master.json' not in filename and 'null' not in filename:
file_without_extension = file.split('.')[0] # Get the part before the first dot
file_parts = file_without_extension.split('-') # Split the name using hyphens
coin = file_parts[-1]
f = open(file_path)
config = json.load(f)
f.close()
if config['rpcEnabled']:
rpc_password = config['rpcPassword']
rpc_user = config['rpcUsername']
rpc_port = config['rpcPort']
if coin == token:
for pk in private_keys:
result = rpc_call('importprivkey',
[pk],
'http://127.0.0.1',
rpc_user,
rpc_password,
rpc_port)
if result and "error" in result and result['error'] is None:
print(f"Token: {token} import pk: {pk} ok")
else:
print(f"Token: {token} import pk: {pk} error")
if not external_daemon:
kill_bin(process)