-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathipc_client.py
312 lines (280 loc) · 9.14 KB
/
ipc_client.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
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
#!/usr/bin/python
# -*- coding: utf-8 -*-
import os
import json
import time
write_path = "/opt/ipc/pipe.in"
read_path = "/opt/ipc/pipe.out"
wf = os.open(write_path, os.O_SYNC | os.O_CREAT | os.O_RDWR)
rf = os.open(read_path, os.O_RDONLY)
print("Welcome to the IPC client!!!")
def select():
print("Please choose the operation:")
print("A:Send transaction \nB:Modify the operating parameters \nC:Get node information \nD:Node book information \nE:Generate JWT Token")
choice = raw_input('input A, B, C , D or E:')
if choice not in ('A','B','C','D','E'):
return select()
return choice
def DA():
publicKeyHash = raw_input('input publicKeyHash:')
message = json.dumps({'type':'sendNonce','message':publicKeyHash})
os.write(wf, message)
print ("sent msg: %s" % message)
s = os.read(rf, 1024)
print ("received msg: %s" % s)
time.sleep(1)
os.close(rf)
def DB():
publicKeyHash = raw_input('input publicKeyHash:')
message = json.dumps({'type':'getBalance','message':publicKeyHash})
os.write(wf, message)
print ("sent msg: %s" % message)
s = os.read(rf, 1024)
print ("received msg: %s" % s)
time.sleep(1)
os.close(rf)
def DC():
message = json.dumps({'type':'height','message':''})
os.write(wf, message)
print ("sent msg: %s" % message)
s = os.read(rf, 1024)
print ("received msg: %s" % s)
time.sleep(1)
os.close(rf)
def DD():
txHash = raw_input('input txHash:')
message = json.dumps({'type':'blockHash','message':txHash})
os.write(wf, message)
print ("sent msg: %s" % message)
s = os.read(rf, 1024)
print ("received msg: %s" % s)
time.sleep(1)
os.close(rf)
def DE():
txHash = raw_input('input txHash:')
message = json.dumps({'type':'transactionConfirmed','message':txHash})
os.write(wf, message)
print ("sent msg: %s" % message)
s = os.read(rf, 1024)
print ("received msg: %s" % s)
time.sleep(1)
os.close(rf)
def DF():
height = input('input height:')
ty = input('input type:')
mes = json.dumps({'height':height,'type':ty})
message = json.dumps({'type':'getTransactionHeight','message':mes})
os.write(wf, message)
print ("sent msg: %s" % message)
s = os.read(rf, 1024)
print ("received msg: %s" % s)
time.sleep(1)
os.close(rf)
def DG():
txHash = raw_input('input txHash:')
message = json.dumps({'type':'transaction','message':txHash})
os.write(wf, message)
print ("sent msg: %s" % message)
s = os.read(rf, 1024)
print ("received msg: %s" % s)
time.sleep(1)
os.close(rf)
def DH():
blockHash = raw_input('input blockHash:')
ty = input('input type:')
mes = json.dumps({'blockHash':blockHash,'type':ty})
message = json.dumps({'type':'getTransactionBlock','message':mes})
os.write(wf, message)
print ("sent msg: %s" % message)
s = os.read(rf, 1024)
print ("received msg: %s" % s)
time.sleep(1)
os.close(rf)
def BA():
version = raw_input('input version:')
message = json.dumps({'type':'modifyVersion','message':version})
os.write(wf, message)
print ("sent msg: %s" % message)
s = os.read(rf, 1024)
print ("received msg: %s" % s)
time.sleep(1)
os.close(rf)
def BB():
print("Please enter whether only the native client can connect to false/true, if true, rpc will be disabled")
isLocalOnly = raw_input('input false or true:')
message = json.dumps({'type':'setIsLocalOnly','message':isLocalOnly})
os.write(wf, message)
print ("sent msg: %s" % message)
s = os.read(rf, 1024)
print ("received msg: %s" % s)
time.sleep(1)
os.close(rf)
def BC():
print("Whether to support json-rpc, true/false, true switch to rpc, false switch to grpc")
isRpc = bool(raw_input('input true or false:'))
global mode
if isRpc:
mode = 'rest'
else:
mode = 'grpc'
message = json.dumps({'type':'setP2PMode','message':mode})
os.write(wf, message)
print ("sent msg: %s" % message)
s = os.read(rf, 1024)
print ("received msg: %s" % s)
time.sleep(1)
os.close(rf)
def BD():
print("Whether to support gpc, true / false, true switch to grpc, false switch to rpc")
isGrpc = bool(raw_input('input true or false:'))
global mode
if isGrpc:
mode = 'grpc'
else:
mode = 'rest'
message = json.dumps({'type':'setP2PMode','message':mode})
os.write(wf, message)
print ("sent msg: %s" % message)
s = os.read(rf, 1024)
print ("received msg: %s" % s)
time.sleep(1)
os.close(rf)
def BE():
print("Modify the transaction limit of the queued queue. The default is 60000.")
queuedLimit = raw_input('input queued limit:')
message = json.dumps({'type':'setQueuedMaxSize','message':queuedLimit})
os.write(wf, message)
print ("sent msg: %s" % message)
s = os.read(rf, 1024)
print ("received msg: %s" % s)
time.sleep(1)
os.close(rf)
def BF():
print("Modify the transaction limit of the pending queue. The default is 30000.")
pendingLimit = raw_input('input pending limit:')
message = json.dumps({'type':'setPendingMaxSize','message':pendingLimit})
os.write(wf, message)
print ("sent msg: %s" % message)
s = os.read(rf, 1024)
print ("received msg: %s" % s)
time.sleep(1)
os.close(rf)
def BG():
print("Please enter the transaction into the memory pool minimum fee, the default is 200000")
feeLimit = raw_input('input feeLimit:')
message = json.dumps({'type':'modifyFeeLimit','message':feeLimit})
os.write(wf, message)
print ("sent msg: %s" % message)
s = os.read(rf, 1024)
print ("received msg: %s" % s)
time.sleep(1)
os.close(rf)
def BH():
print("Please enter a write cycle that is queued to pending, in the format: */5 * * * * ?")
queuedToPendingCycle = raw_input('input queuedToPendingCycle:')
message = json.dumps({'type':'modifyQueuedToPendingCycle','message':queuedToPendingCycle})
os.write(wf, message)
print ("sent msg: %s" % message)
s = os.read(rf, 1024)
print ("received msg: %s" % s)
time.sleep(1)
os.close(rf)
def BI():
print("The cleanup cycle of queued and pending, in the format: 0 */1 * * * ?")
clearCycle = raw_input('input clearCycle:')
message = json.dumps({'type':'modifyClearCycle','message':clearCycle})
os.write(wf, message)
print ("sent msg: %s" % message)
s = os.read(rf, 1024)
print ("received msg: %s" % s)
time.sleep(1)
os.close(rf)
def A():
tranInfo = raw_input('input tranInfo:')
message = json.dumps({'type':'sendTranInfo','message':tranInfo})
os.write(wf, message)
print ("sent msg: %s" % message)
s = os.read(rf, 1024)
print ("received msg: %s" % s)
time.sleep(1)
os.close(rf)
def B():
print("Please choose the operation:")
print("A:Modify version \nB:Modify whether only native clients can connect")
print("C:Whether to support json-rpc \nD:Whether to support grpc \nE:Modify the transaction limit of the queued queue \nF:Modify the transaction limit of the pending queue")
print("G:Modify the transaction into the memory pool minimum fee \nH:Queued to pending write cycle \nI:Queued and pending cleaning cycles")
choice = raw_input('input A ~ L :')
if choice not in ('A','B','C','D','E','F','G','H','I','J','K','L'):
B()
if choice == 'A':
BA()
if choice == 'B':
BB()
if choice == 'C':
BC()
if choice == 'D':
BD()
if choice == 'E':
BE()
if choice == 'F':
BF()
if choice == 'G':
BG()
if choice == 'H':
BH()
if choice == 'I':
BI()
def C():
message = json.dumps({'type':'getNodeInfo','message':""})
os.write(wf, message)
print ("sent msg: %s" % message)
s = os.read(rf, 1024)
print ("received msg: %s" % s)
time.sleep(1)
os.close(rf)
def D():
print("Please choose the operation:")
print("A:Get Nonce \nB:Get Balance \nC:Query the current block height \nD:Get the hash and height of the block based on the transaction hash \nE:Get block acknowledgment status based on transaction hash")
print("F:Get the transaction list based on the block height \nG:Get transaction through transaction hash \nH:Get the list of transactions by block hash")
choice = raw_input('input A ~ H :')
if choice not in ('A','B','C','D','E','F','G','H'):
D()
if choice == 'A':
DA()
if choice == 'B':
DB()
if choice == 'C':
DC()
if choice == 'D':
DD()
if choice == 'E':
DE()
if choice == 'F':
DF()
if choice == 'G':
DG()
if choice == 'H':
DH()
def E():
print("Please enter expiration time,One hour is 1000 * 60 * 60 ,in the format:3600000")
milliseconds = raw_input('input expiration time in milliseconds:')
message = json.dumps({'type':'getJWTToken','message':milliseconds})
os.write(wf, message)
print ("sent msg: %s" % message)
s = os.read(rf, 1024)
print ("received msg: %s" % s)
time.sleep(1)
os.close(rf)
value = select()
switch = {
"A":A,
"B":B,
"C":C,
"D":D,
"E":E
}
try:
switch[value]()
except Exception as e:
pass
os.close(wf)