-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstor.py
85 lines (69 loc) · 2.64 KB
/
stor.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
import os, datetime
import shutil
import json
class Stor:
def __init__(self) -> None:
self.report = None
@staticmethod
def get_secret(key, path):
try:
file = open(path, 'r')
data = file.read(1024)
data = data.strip()
data1 = data[1:-1]
secret = data1.split(',')
b = bytearray()
for s in secret:
x = bytes(s, encoding='utf8')
b.append(int(x))
return key, bytes(b)
except OSError as err:
raise err
except BaseException as err:
raise err
@staticmethod
def copy_keys(sourcefilelist, backuppath):
try:
if not os.path.exists(backuppath):
os.makedirs(backuppath)
newbackuppath = os.path.join(backuppath, datetime.datetime.now().strftime('%Y-%m-%d_%H-%M-%S'))
os.makedirs(newbackuppath)
for file in sourcefilelist:
shutil.copy2(file, newbackuppath)
return newbackuppath
except OSError as err:
raise err
except BaseException as err:
raise err
@staticmethod
def gen_spl_report(backuppath, pubkey_kppaths, mint_auth, inrtoken, accountpubkey, freezeauth, owner):
try:
reportfile = backuppath+ os.path.sep + "report.txt"
jsonobj = json.loads('{}')
jsonobj['signers'] = {}
file = open(reportfile, 'w', 512, 'utf8')
file.write("REPORT \r\n \r\n")
for key in list(pubkey_kppaths.keys()):
jsonobj['signers'][str(key)] = pubkey_kppaths[key]
# file.write(str(key)+" - ")
# file.write(pubkey_kppaths[key] + "\r\n")
jsonobj['auth'] = str(mint_auth)
jsonobj['token'] = str(inrtoken)
jsonobj['account'] = str(accountpubkey)
jsonobj['freezauth'] = str(freezeauth)
jsonobj['rokenowner'] = str(owner)
# file.write("\r\n \r\n")
# file.write("MINT AUTH: "+ str(mint_auth) + "\r\n")
# file.write("MINT TOKEN: "+ str(inrtoken) + "\r\n")
# file.write("MINT ACCOUNT: "+ str(accountpubkey) + "\r\n")
# file.write("FREEZE AUTH: "+ str(freezeauth) + "\r\n")
# file.write("TOKEN OWNER: "+ str(owner) + "\r\n")
#
file.write(json.dumps(jsonobj))
file.flush()
file.close()
return reportfile
except OSError as err:
raise err
except BaseException as err:
raise err