forked from hclivess/Bismuth
-
Notifications
You must be signed in to change notification settings - Fork 0
/
commands.py
271 lines (220 loc) · 7.57 KB
/
commands.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
import socks, connections, time, sys
#print ('Number of arguments:', len(sys.argv), 'arguments.')
#print ('Argument List:', str(sys.argv))
try:
command = sys.argv[1]
except:
pass
try:
arg1 = sys.argv[2]
except:
pass
try:
arg2 = sys.argv[3]
except:
pass
try:
arg3 = sys.argv[4]
except:
pass
try:
arg4 = sys.argv[5]
except:
pass
try:
arg5 = sys.argv[6]
except:
pass
s = socks.socksocket()
s.settimeout(10)
s.connect(("127.0.0.1", 5658))
#s.connect(("94.113.207.67", 5658))
def diffget(socket):
#check difficulty
connections.send(s, "diffget", 10)
diff = connections.receive(s, 10)
print ("Current difficulty: {}".format(diff))
#check difficulty
def balanceget(socket, arg1):
#get balance
connections.send(s, "balanceget", 10)
connections.send(s, arg1, 10)
#balance_ledger = connections.receive(s, 10)
balance_ledger = connections.receive(s, 10)
print ("Address balance: {}".format(balance_ledger[0]))
print ("Address credit: {}".format(balance_ledger[1]))
print ("Address debit: {}".format(balance_ledger[2]))
print ("Address fees: {}".format(balance_ledger[3]))
print ("Address rewards: {}".format(balance_ledger[4]))
#get balance
#insert to mempool
#DIRECT INSERT, NO REMOTE TX CONSTRUCTION
#connections.send(s, "mpinsert", 10)
#transaction = "('1494941203.13', '4edadac9093d9326ee4b17f869b14f1a2534f96f9c5d7b48dc9acaed', '4edadac9093d9326ee4b17f869b14f1a2534f96f9c5d7b48dc9acaed', '1.00000000', 'AnCAkXrBhqgKItLrbrho3+KNro5GuQNB7zcYlhxMELbiTIOcHZpv/oUazqwDvybp6xKxLWMYt2rmmGPmZ49Q3WG4ikIPkFgYY6XV9Uq+ZsnwjJNTKTwXfj++M/kGle7omUVCsi7PDeijz0HlORRySOM/G0rBnObUahMSvlGnCyo=', 'LS0tLS1CRUdJTiBQVUJMSUMgS0VZLS0tLS0KTUlHZk1BMEdDU3FHU0liM0RRRUJBUVVBQTRHTkFEQ0JpUUtCZ1FES3ZMVGJEeDg1YTF1Z2IvNnhNTWhWT3E2VQoyR2VZVDgrSXEyejlGd0lNUjQwbDJ0dEdxTks3dmFyTmNjRkxJdThLbjRvZ0RRczNXU1dRQ3hOa2haaC9GcXpGCllZYTMvSXRQUGZ6clhxZ2Fqd0Q4cTRadDRZbWp0OCsyQmtJbVBqakZOa3VUUUl6Mkl1M3lGcU9JeExkak13N24KVVZ1OXRGUGlVa0QwVm5EUExRSURBUUFCCi0tLS0tRU5EIFBVQkxJQyBLRVktLS0tLQ==', '0', '')"
#connections.send(s, transaction, 10)
#confirmation = connections.receive(s, 10)
#print (confirmation)
#insert to mempool
def mpget(socket):
#ask for mempool
connections.send(s, "mpget", 10)
mempool = connections.receive(s, 10)
print ("Current mempool: {}".format(mempool))
#ask for mempool
def difflast(socket):
#ask for last difficulty
connections.send(s, "difflast", 10)
response = connections.receive(s, 10)
blocklast = response[0]
difflast = response[1]
print("Last block: {}".format(blocklast))
print ("Last difficulty: {}".format(difflast))
#ask for last difficulty
def blocklast(socket):
#get last block
connections.send(s, "blocklast", 10)
hash_last = connections.receive(s, 10)
print ("Last block number: {}".format(hash_last[0]))
print ("Last block hash: {}".format(hash_last[1]))
#get last hash
def keygen(socket):
#generate address
#RECEIVES PRIVATE KEY FROM NODE
connections.send(s, "keygen", 10)
keys_generated = connections.receive(s, 10)
print ("Private key: {}".format(keys_generated[0]))
print ("Public key: {}".format(keys_generated[1]))
print ("Address: {}".format(keys_generated[2]))
#generate address
def blockget(socket, arg1):
#get block
connections.send(s, "blockget", 10)
connections.send(s, arg1, 10)
block_get = connections.receive(s, 10)
print ("Requested block: {}".format(block_get))
print ("Requested block number of transactions: {}".format(len(block_get)))
print ("Requested block height: {}".format(block_get[0][0]))
#get block
def addlist(socket, arg1):
#get all txs for an address
connections.send(s, "addlist", 10)
connections.send(s, arg1, 10)
address_tx_list = connections.receive(s, 10)
print("All transactions for requested address:")
for row in address_tx_list:
print (row)
#get all txs for an address
def addlistlim(socket, arg1, arg2):
#get all txs for an address
connections.send(s, "addlistlim", 10)
connections.send(s, arg1, 10)
connections.send(s, arg2, 10)
address_tx_list = connections.receive(s, 10)
print("Transactions for requested address:")
for row in address_tx_list:
print (row)
#get all txs for an address
def listlim(socket, arg1):
#get all txs for an address
connections.send(s, "listlim", 10)
connections.send(s, arg1, 10)
tx_list = connections.receive(s, 10)
print("All transactions for requested range:")
for row in tx_list:
print (row)
def txsend(socket, arg1, arg2, arg3, arg4, arg5):
#generate transaction
#SENDS PRIVATE KEY TO NODE
connections.send(s, "txsend", 10)
remote_tx_timestamp = '%.2f' % time.time()
remote_tx_privkey = arg1 #node will dump pubkey+address from this
remote_tx_recipient = arg2
remote_tx_amount = arg3
remote_tx_keep = arg4
remote_tx_openfield = arg5
#connections.send(s, (remote_tx_timestamp, remote_tx_privkey, remote_tx_recipient, remote_tx_amount, remote_tx_keep, remote_tx_openfield), 10)
connections.send(s, (str(remote_tx_timestamp), str(remote_tx_privkey), str(remote_tx_recipient), str(remote_tx_amount), str(remote_tx_keep), str(remote_tx_openfield)), 10)
#generate transaction
signature = connections.receive(s, 10)
print (signature)
def aliasget(socket, arg1):
connections.send(s, "aliasget", 10)
connections.send(s, arg1, 10)
alias_results = connections.receive(s, 10)
print (alias_results)
def peersget(socket):
connections.send(s, "peersget", 10)
peers_received = connections.receive(s, 10)
print (peers_received)
def statusget(socket):
connections.send(s, "statusget", 10)
response = connections.receive(s, 10)
node_address = response[0]
nodes_count = response[1]
nodes_list = response[2]
threads_count = response[3]
uptime = response[4]
consensus = response[5]
consensus_percentage = response[6]
version = response[7]
print("Node address:", node_address)
print("Number of nodes:", nodes_count)
print("List of nodes:", nodes_list)
print("Number of threads:", threads_count)
print("Uptime:", uptime)
print("Consensus:", consensus)
print("Consensus percentage:", consensus_percentage)
print("Version:", version)
def addvalidate(socket, arg1):
connections.send(s, "addvalidate", 10)
connections.send(s, arg1, 10)
validate_result = connections.receive(s, 10)
print (validate_result)
def aliasesget(socket, arg1):
arg_split = arg1.split(",")
print (arg_split)
connections.send(s, "aliasesget", 10)
connections.send(s, arg_split, 10)
alias_results = connections.receive(s, 10)
print (alias_results)
if command == "aliasget":
aliasget(s, arg1)
if command == "addvalidate":
addvalidate(s, arg1)
if command == "aliasesget":
aliasesget(s, arg1)
elif command == "diffget":
diffget(s)
elif command == "difflast":
difflast(s)
elif command == "balanceget":
balanceget(s, arg1)
elif command == "mpget":
mpget(s)
elif command == "statusget":
statusget(s)
elif command == "peersget":
peersget(s)
elif command == "blocklast":
blocklast(s)
elif command == "keygen":
keygen(s)
elif command == "blockget":
blockget(s, arg1)
elif command == "addlist":
addlist(s, arg1)
elif command == "addlistlim":
addlistlim(s, arg1, arg2)
elif command == "listlim":
listlim(s, arg1)
elif command == "txsend":
try:
arg4
except:
arg4="0"
try:
arg5
except:
arg5=""
txsend(s, arg1, arg2, arg3, arg4, arg5)
s.close()