Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCore.py
More file actions
Latest commit
executable file
·170 lines (146 loc) · 4.86 KB
/
Copy pathCore.py
File metadata and controls
executable file
·170 lines (146 loc) · 4.86 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
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
importos
fromdatetimeimportdatetime
fromErrorimport*
HISTORIC="historic"
TRANSFER="transfer"
GET_BALANCE="get-balance"
SET_TOKEN_TYPE="set-token-type"
CREATE_ACCOUNT="create-account"
GET_RAW_PRIVATE_KEY="get-raw-prik"
GET_PRIVATE_KEY="get-prik"
GET_ADDRESS="get-address"
GET_PUBLIC_KEY="get-pubk"
GET_TX_STATUS="get-tx-status"
CREATE_WALLET="create-wallet"
SET_PROVIDER="set-provider"
SET_ACCOUNT="set-account"
SET_WALLET_PASSPHRASE="set-passphrase"
UNLOCK_WALLET="unlock-wallet"
LOCK_WALLET="lock-wallet"
CHANGE_PASSPHRASE="change-passphrase"
GET_FEE="get-fee"
SET_FEE="set-fee"
ACTION_ERRORS= {
HISTORIC: 30,
TRANSFER: 40,
GET_BALANCE: 50,
GET_PRIVATE_KEY: 51,
GET_RAW_PRIVATE_KEY: 52,
GET_ADDRESS: 53,
GET_FEE: 54,
GET_PUBLIC_KEY: 55,
GET_TX_STATUS: 56,
SET_ACCOUNT: 60,
SET_FEE: 61,
SET_PROVIDER: 62,
SET_WALLET_PASSPHRASE: 63,
CREATE_ACCOUNT: 70,
CREATE_WALLET: 71,
CHANGE_PASSPHRASE: 80,
UNLOCK_WALLET: 81,
LOCK_WALLET: 82
}
current_action=None
current_env=None
path=os.path.join(os.path.abspath(os.path.curdir), ".cache")
classDocumentation:
name="undefined"
documentation="none"
commands= {}
def__init__(self, name, documentation):
self.name=name
self.documentation=documentation
def__str__(self):
returnself.documentation
defput(self, command, documentation):
key_value=list()
forkeyinself.commands:
key_value.append((key, self.commands.get(key)))
key_value.append((command, documentation))
self.commands=dict(key_value)
returnself
defget(self, command=None):
ifcommandisNone:
returnf"{self.documentation}"
else:
res=self.commands.get(command)
ifresisNone:
returnf"Cannot find the documentation for {command}..."
returnf"{res}"
classTools:
def__init__(self):
pass
classCache:
@staticmethod
defother_time_action(cache_id, value):
content=""
withopen(os.path.join(path, str(cache_id)), "r") asfile:
content=file.readlines()
withopen(os.path.join(path, str(cache_id)), "w+") asfile:
temp=""
foriincontent[1:]:
temp+=i
file.write(f"{Cache.get_timestamp()},\n{temp},\n{current_env}: {value}")
@staticmethod
deffirst_time_action(value):
ifnotos.path.exists(path):
os.mkdir(path)
elifos.path.exists(path) andnotos.path.isdir(path):
os.remove(path)
os.mkdir(path)
cache=os.listdir(path)
my_id=len(cache)+1
withopen(os.path.join(path, str(my_id)), "w") asfile:
file.write(f"{Cache.get_timestamp()}\n{current_env}: {value}")
returnmy_id
@staticmethod
defget_all_of(cache_id):
withopen(os.path.join(path, str(cache_id)), "r") asfile:
returnfile.read()
@staticmethod
defget(cache_id, command, limit=-1, last=False):
res= []
try:
withopen(os.path.join(path, str(cache_id)), "r") asfile:
data=file.readlines()
iflast:
limit=1
data.reverse()
fordatindata:
try:
ifdat.split(":")[0] ==command:
res.append(dat.split(":")[1:])
if0<limit==len(res):
returnres
exceptIndexError:
return []
exceptFileNotFoundError:
raiseTFBlockchainError(error_code=ECACHENOTLOCATED, message="Please try to use a command first or use "
"env historic new or env historic use "
"CACHE_ID")
returnres
@staticmethod
defcheck_cache():
cache=os.listdir(path)
cache.sort()
forcache_fileincache:
withopen(cache_file, "r") asfile:
print(file.readlines()[0])
@staticmethod
defget_timestamp():
returndatetime.now().timestamp()
classTFBlockchainError(BaseException):
error_code=0
message=""
def__init__(self, action_name=None, message="An exception occurred", error_code=None):
super(TFBlockchainError, self).__init__()
ifaction_nameisnotNone:
self.__error_code__(action_name)
eliferror_codeisnotNone:
self.error_code=error_code
self.message=message
def__error_code__(self, action):
try:
self.error_code=ACTION_ERRORS.get(action)
exceptException:
self.error_code=-1