This repository was archived by the owner on Jun 7, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathsolid.py
More file actions
70 lines (56 loc) · 1.73 KB
/
solid.py
File metadata and controls
70 lines (56 loc) · 1.73 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
import json
import urllib2
import sys
from sets import Set
import time
url = "http://localhost:" + sys.argv[1]
folder = './'
#Utils:
all_nines = '9' * 81
TIMEOUT = 7
def API(request,url=url):
stringified = json.dumps(request)
headers = {'content-type': 'application/json', 'X-IOTA-API-Version': '1'}
try:
request = urllib2.Request(url=url, data=stringified, headers=headers)
returnData = urllib2.urlopen(request,timeout=TIMEOUT).read()
response = json.loads(returnData)
except:
print url, "Timeout!"
print '\n ' + repr(sys.exc_info())
return ""
if not response:
response = ""
return response
def getNodeInfo():
cmd = {
"command": "getNodeInfo"
}
return API(cmd)
def getTrytes(hash):
cmd = {
"command": "getTrytes",
"hashes" : [hash]
}
return API(cmd)
# check that node is solid:
# and get latest milestone hash
solid_milestone = False
counter = 0
while not solid_milestone:
node_info = getNodeInfo()
if node_info != "":
if node_info['latestSolidSubtangleMilestone'] != all_nines:
if node_info['latestSolidSubtangleMilestoneIndex'] == node_info['latestMilestoneIndex']:
solid_milestone = node_info['latestSolidSubtangleMilestone']
print "Success! node solid - solid_milestone: " + solid_milestone
exit(0)
print "waiting for node to get solid:" + str(node_info['latestSolidSubtangleMilestoneIndex']) + "/" + str(node_info['latestMilestoneIndex'])
time.sleep(2)
counter += 1
if counter > 30:
print "Error! not becoming solid!"
exit(-1)
else:
print "waiting for API"
time.sleep(10)