This repository has been 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
/
Copy pathapi.py
73 lines (60 loc) · 1.61 KB
/
api.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
import json
import urllib2
import sys
url = "http://localhost:14266"
folder = './'
#Utils:
all_nines = '9' * 81
TIMEOUT = 60
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(url):
cmd = {
"command": "getNodeInfo"
}
return API(cmd, url)
def getTrytes(url, hash):
cmd = {
"command": "getTrytes",
"hashes" : [hash]
}
return API(cmd, url)
def attachToTangle(url, trunk_tx, branch_tx, mwm, unattached_trytes):
cmd = {
"command": "attachToTangle",
"trunkTransaction": trunk_tx,
"branchTransaction": branch_tx,
"minWeightMagnitude": mwm,
"trytes": [unattached_trytes]
}
return API(cmd, url)
def storeTransactions(url, attached_trytes):
cmd = {
"command": "storeTransactions",
"trytes": [attached_trytes]
}
return API(cmd, url)
def broadcastTransactions(url, attached_trytes):
cmd = {
"command": "broadcastTransactions",
"trytes": [attached_trytes]
}
return API(cmd, url)
def findTransactions(url, tags):
cmd = {
"command": "findTransactions",
"tags": [tags]
}
return API(cmd, url)