-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathcall_apis.py
280 lines (267 loc) · 13.3 KB
/
call_apis.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
from Crypto.PublicKey import RSA
from mixin_api import MIXIN_API
import mixin_config
import json
import csv
import time
PIN = "945689";
PIN2 = "845689";
MASTER_ID = "37222956";
MASTER_UUID = "0b4f49dc-8fb4-4539-9a89-fb3afc613747";
BTC_ASSET_ID = "c6d0c728-2624-429b-8e0d-d9d19b6592fa";
EOS_ASSET_ID = "6cfe566e-4aad-470b-8c9a-2fd35b49c68d";
BTC_WALLET_ADDR = "14T129GTbXXPGXXvZzVaNLRFPeHXD1C25C";
AMOUNT = "0.001";
# // Mixin Network support cryptocurrencies (2019-02-19)
# // |EOS|6cfe566e-4aad-470b-8c9a-2fd35b49c68d
# // |CNB|965e5c6e-434c-3fa9-b780-c50f43cd955c
# // |BTC|c6d0c728-2624-429b-8e0d-d9d19b6592fa
# // |ETC|2204c1ee-0ea2-4add-bb9a-b3719cfff93a
# // |XRP|23dfb5a5-5d7b-48b6-905f-3970e3176e27
# // |XEM|27921032-f73e-434e-955f-43d55672ee31
# // |ETH|43d61dcd-e413-450d-80b8-101d5e903357
# // |DASH|6472e7e3-75fd-48b6-b1dc-28d294ee1476
# // |DOGE|6770a1e5-6086-44d5-b60f-545f9d9e8ffd
# // |LTC|76c802a2-7c88-447f-a93e-c29c9e5dd9c8
# // |SC|990c4c29-57e9-48f6-9819-7d986ea44985
# // |ZEN|a2c5d22b-62a2-4c13-b3f0-013290dbac60
# // |ZEC|c996abc9-d94e-4494-b1cf-2a3fd3ac5714
# // |BCH|fd11b6e3-0b87-41f1-a41f-f0e9b49e5bf0
def pubkeyContent(inputContent):
contentWithoutHeader= inputContent[len("-----BEGIN PUBLIC KEY-----") + 1:]
contentWithoutTail = contentWithoutHeader[:-1 * (len("-----END PUBLIC KEY-----") + 1)]
contentWithoutReturn = contentWithoutTail[:64] + contentWithoutTail[65:129] + contentWithoutTail[130:194] + contentWithoutTail[195:]
return contentWithoutReturn
def generateMixinAPI(private_key,pin_token,session_id,user_id,pin,client_secret):
mixin_config.private_key = private_key
mixin_config.pin_token = pin_token
mixin_config.pay_session_id = session_id
mixin_config.client_id = user_id
mixin_config.client_secret = client_secret
mixin_config.pay_pin = pin
return MIXIN_API(mixin_config)
def readAssetBalance(asset_id):
with open('new_users.csv', newline='') as csvfile:
reader = csv.reader(csvfile)
for row in reader:
pin = row.pop()
userid = row.pop()
session_id = row.pop()
pin_token = row.pop()
private_key = row.pop()
mixinApiNewUserInstance = generateMixinAPI(private_key,
pin_token,
session_id,
userid,
pin,"")
btcInfo = mixinApiNewUserInstance.getAsset(asset_id)
print("Account %s \'s balance is %s " %(userid,btcInfo.get("data").get("balance")))
def readAssetAddress(asset_id,isBTC = True):
with open('new_users.csv', newline='') as csvfile:
reader = csv.reader(csvfile)
for row in reader:
pin = row.pop()
userid = row.pop()
session_id = row.pop()
pin_token = row.pop()
private_key = row.pop()
mixinApiNewUserInstance = generateMixinAPI(private_key,
pin_token,
session_id,
userid,
pin,"")
btcInfo = mixinApiNewUserInstance.getAsset(asset_id)
print(btcInfo)
if isBTC:
print("Account %s \'s Bitcoin wallet address is %s " %(userid,btcInfo.get("data").get("public_key")))
else:
print("Account %s \'s EOS account name is %s, wallet address is %s " %(userid,
btcInfo.get("data").get("account_name"),
btcInfo.get("data").get("account_tag")))
# print(btcInfo.get("data").get("public_key"))
mixinApiBotInstance = MIXIN_API(mixin_config)
PromptMsg = "1: Create user and update PIN\n2: Read Bitcoin balance \n3: Read Bitcoin Address\n4: Read EOS balance\n"
PromptMsg += "5: Read EOS address\n6: Transfer Bitcoin from bot to new account\n7: Transfer Bitcoin from new account to Master\n"
PromptMsg += "8: Withdraw bot's Bitcoin\n9: Withdraw bot's EOS\na: Verify Pin\nd: Create Address and Delete it\nr: Create Address and read it\n"
PromptMsg += "gensnap: Generate snapshot for one of my snapshot\n"
PromptMsg += "q: Exit \nMake your choose:"
while ( 1 > 0 ):
cmd = input(PromptMsg)
if (cmd == 'q' ):
exit()
print("Run...")
if ( cmd == 'gensnap'):
snapshot_id = input("snapshot id:")
snapshot = mixinApiBotInstance.account_snapshot_prove(snapshot_id)
print("snapshot information start:")
print(snapshot[0])
print("snapshot information end :---")
print("\ncurl command to verify it ------")
print(snapshot[1])
print("\nend ------")
counter_user_id = snapshot[0]["data"]["opponent_id"]
result = mixinApiBotInstance.getUserInfo_prove(counter_user_id)
userInfo = result[0]
print("counter user id in network:" +userInfo["data"]["user_id"])
print("counter user id in messenger:" + userInfo["data"]["identity_number"])
print("counter user name in messenger:" + userInfo["data"]["full_name"])
print("\ncurl command to veify it: ------")
print(result[1])
print("\n end ----")
if ( cmd == '1' ):
key = RSA.generate(1024)
pubkey = key.publickey()
print(key.exportKey())
print(pubkey.exportKey())
private_key = key.exportKey()
session_key = pubkeyContent(pubkey.exportKey())
# print(session_key)
print(session_key.decode())
userInfo = mixinApiBotInstance.createUser(session_key.decode(),"Tom Bot")
print(userInfo.get("data").get("user_id"))
with open('new_users.csv', 'a', newline='') as csvfile:
csvwriter = csv.writer(csvfile)
csvwriter.writerow([private_key.decode(),
userInfo.get("data").get("pin_token"),
userInfo.get("data").get("session_id"),
userInfo.get("data").get("user_id"),
PIN])
mixinApiNewUserInstance = generateMixinAPI(private_key.decode(),
userInfo.get("data").get("pin_token"),
userInfo.get("data").get("session_id"),
userInfo.get("data").get("user_id"),
PIN,"")
pinInfo = mixinApiNewUserInstance.updatePin(PIN,"")
print(pinInfo)
time.sleep(3)
# mixinApiNewUserInstance.pay_pin = PIN
pinInfo2 = mixinApiNewUserInstance.verifyPin()
print(pinInfo2)
if ( cmd == '2' ):
print("Read Bitcoin(uuid:%s) balance" %(BTC_ASSET_ID))
readAssetBalance(BTC_ASSET_ID)
if ( cmd == '3' ):
print("Read Bitcoin(uuid:%s) address" %(BTC_ASSET_ID))
readAssetAddress(BTC_ASSET_ID)
if ( cmd == '4' ):
print("Read EOS(uuid:%s) balance" %(EOS_ASSET_ID))
readAssetBalance(EOS_ASSET_ID)
if ( cmd == '5' ):
print("Read Bitcoin(uuid:%s) address" %(EOS_ASSET_ID))
readAssetAddress(EOS_ASSET_ID,False)
if ( cmd == '6' ):
with open('new_users.csv', newline='') as csvfile:
reader = csv.reader(csvfile)
for row in reader:
row.pop()
userid = row.pop()
mixinApiBotInstance.transferTo(userid, BTC_ASSET_ID, AMOUNT, "")
if ( cmd == '7' ):
with open('new_users.csv', newline='') as csvfile:
reader = csv.reader(csvfile)
for row in reader:
pin = row.pop()
userid = row.pop()
session_id = row.pop()
pin_token = row.pop()
private_key = row.pop()
mixinApiNewUserInstance = generateMixinAPI(private_key,
pin_token,
session_id,
userid,
pin,"")
btcInfo = mixinApiBotInstance.transferTo(MASTER_UUID, BTC_ASSET_ID, AMOUNT, "")
print(btcInfo)
if ( cmd == '8' ):
with open('new_users.csv', newline='') as csvfile:
reader = csv.reader(csvfile)
for row in reader:
pin = row.pop()
userid = row.pop()
session_id = row.pop()
pin_token = row.pop()
private_key = row.pop()
print(pin)
mixinApiNewUserInstance = generateMixinAPI(private_key,
pin_token,
session_id,
userid,
pin,"")
btcInfo = mixinApiBotInstance.createAddress(BTC_ASSET_ID, BTC_WALLET_ADDR,"BTC")
# mixinApiBotInstance.withdrawals(btcInfo.get("data").get("address_id"),AMOUNT,"")
print(btcInfo)
if ( cmd == '9' ):
with open('new_users.csv', newline='') as csvfile:
reader = csv.reader(csvfile)
for row in reader:
pin = row.pop()
userid = row.pop()
session_id = row.pop()
pin_token = row.pop()
private_key = row.pop()
print(pin)
mixinApiNewUserInstance = generateMixinAPI(private_key,
pin_token,
session_id,
userid,
pin,"")
eosInfo = mixinApiBotInstance.createAddressEOS(EOS_ASSET_ID,"eoswithmixin","d80363afcc466fbaf2daa7328ae2adfa")
# mixinApiBotInstance.withdrawals(btcInfo.get("data").get("address_id"),AMOUNT,"")
print(eosInfo)
if ( cmd == 'a' ):
with open('new_users.csv', newline='') as csvfile:
reader = csv.reader(csvfile)
for row in reader:
pin = row.pop()
userid = row.pop()
session_id = row.pop()
pin_token = row.pop()
private_key = row.pop()
print(pin)
mixinApiNewUserInstance = generateMixinAPI(private_key,
pin_token,
session_id,
userid,
pin,"")
btcInfo = mixinApiNewUserInstance.verifyPin()
print(btcInfo)
if ( cmd == 'd' ):
with open('new_users.csv', newline='') as csvfile:
reader = csv.reader(csvfile)
for row in reader:
pin = row.pop()
userid = row.pop()
session_id = row.pop()
pin_token = row.pop()
private_key = row.pop()
print(pin)
mixinApiNewUserInstance = generateMixinAPI(private_key,
pin_token,
session_id,
userid,
pin,"")
btcInfo = mixinApiBotInstance.createAddress(BTC_ASSET_ID, BTC_WALLET_ADDR,"BTC","","")
addr_id = btcInfo.get("data").get("address_id")
print(addr_id)
delInfo = mixinApiBotInstance.delAddress(addr_id)
print(delInfo)
if ( cmd == 'r' ):
with open('new_users.csv', newline='') as csvfile:
reader = csv.reader(csvfile)
for row in reader:
pin = row.pop()
userid = row.pop()
session_id = row.pop()
pin_token = row.pop()
private_key = row.pop()
print(pin)
mixinApiNewUserInstance = generateMixinAPI(private_key,
pin_token,
session_id,
userid,
pin,"")
btcInfo = mixinApiBotInstance.createAddress(BTC_ASSET_ID, BTC_WALLET_ADDR,"BTC","","")
addr_id = btcInfo.get("data").get("address_id")
print(addr_id)
addrInfo = mixinApiBotInstance.getAddress(addr_id)
print(addrInfo)