-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathgetconf.py
executable file
·199 lines (181 loc) · 6.33 KB
/
getconf.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
#!/usr/bin/env python3
import re
import os
import requests
import json
import platform
# define function that fetchs rpc creds from .conf
def def_credentials(chain):
operating_system = platform.system()
if operating_system == 'Darwin':
ac_dir = os.environ['HOME'] + '/Library/Application Support/Komodo'
elif operating_system == 'Linux':
ac_dir = os.environ['HOME'] + '/.komodo'
elif operating_system == 'Win64':
ac_dir = '%s/komodo/PIRATE' % os.environ['APPDATA']
# define config file path
if chain == 'KMD':
coin_config_file = str(ac_dir + '/komodo.conf')
else:
coin_config_file = str(ac_dir + '/' + chain + '/' + chain + '.conf')
#define rpc creds
with open(coin_config_file, 'r') as f:
#print("Reading config file for credentials:", coin_config_file)
for line in f:
l = line.rstrip()
if re.search('rpcuser', l):
rpcuser = l.replace('rpcuser=', '')
elif re.search('rpcpassword', l):
rpcpassword = l.replace('rpcpassword=', '')
elif re.search('rpcport', l):
rpcport = l.replace('rpcport=', '')
return('http://' + rpcuser + ':' + rpcpassword + '@127.0.0.1:' + rpcport)
# define function that posts json data
def post_rpc(url, payload, auth=None):
try:
r = requests.post(url, data=json.dumps(payload), auth=auth)
return(json.loads(r.text))
except Exception as e:
raise Exception("Couldn't connect to " + url + ": ", e)
# Return current -pubkey=
def getpubkey_rpc(chain):
getinfo_payload = {
"jsonrpc": "1.0",
"id": "python",
"method": "getinfo",
"params": []}
getinfo_result = post_rpc(def_credentials(chain), getinfo_payload)
return(getinfo_result['result']['pubkey'])
# return latest batontxid from all publishers
def get_latest_batontxids(chain, oracletxid):
oraclesinfo_result = oraclesinfo_rpc(chain, oracletxid)
latest_batontxids = {}
# fill "latest_batontxids" dictionary with publisher:batontxid data
for i in oraclesinfo_result['registered']:
latest_batontxids[i['publisher']] = i['batontxid']
return(latest_batontxids)
#VANILLA RPC
def sendrawtx_rpc(chain, rawtx):
sendrawtx_payload = {
"jsonrpc": "1.0",
"id": "python",
"method": "sendrawtransaction",
"params": [rawtx]}
#rpcurl = def_credentials(chain)
return(post_rpc(def_credentials(chain), sendrawtx_payload))
def signmessage_rpc(chain, address, message):
signmessage_payload = {
"jsonrpc": "1.0",
"id": "python",
"method": "signmessage",
"params": [
address,
message
]
}
signmessage_result = post_rpc(def_credentials(chain), signmessage_payload)
return(signmessage_result['result'])
def verifymessage_rpc(chain, address, signature, message):
verifymessage_payload = {
"jsonrpc": "1.0",
"id": "python",
"method": "verifymessage",
"params": [
address,
signature,
message
]
}
verifymessage_result = post_rpc(def_credentials(chain), verifymessage_payload)
return(verifymessage_result['result'])
def kvsearch_rpc(chain, key):
kvsearch_payload = {
"jsonrpc": "1.0",
"id": "python",
"method": "kvsearch",
"params": [
key
]
}
kvsearch_result = post_rpc(def_credentials(chain), kvsearch_payload)
return(kvsearch_result['result'])
def kvupdate_rpc(chain, key, value, days, password):
# create dynamic oraclessamples payload
kvupdate_payload = {
"jsonrpc": "1.0",
"id": "python",
"method": "kvupdate",
"params": [
key,
value,
str(days),
password]}
# make kvupdate rpc call
kvupdate_result = post_rpc(def_credentials(chain), kvupdate_payload)
return(kvupdate_result)
def oraclesdata_rpc(chain, oracletxid, hexstr):
oraclesdata_payload = {
"jsonrpc": "1.0",
"id": "python",
"method": "oraclesdata",
"params": [
oracletxid,
hexstr]}
oraclesdata_result = post_rpc(def_credentials(chain), oraclesdata_payload)
return(oraclesdata_result['result'])
def oraclescreate_rpc(chain, name, description, oracle_type):
oraclescreate_payload = {
"jsonrpc": "1.0",
"id": "python",
"method": "oraclescreate",
"params": [
name,
description,
oracle_type]}
oraclescreate_result = post_rpc(def_credentials(chain), oraclescreate_payload)
return(oraclescreate_result['result'])
def oraclesinfo_rpc(chain, oracletxid):
oraclesinfo_payload = {
"jsonrpc": "1.0",
"id": "python",
"method": "oraclesinfo",
"params": [oracletxid]}
oraclesinfo_result = post_rpc(def_credentials(chain), oraclesinfo_payload)
return(oraclesinfo_result['result'])
def oracleslist_rpc(chain):
oracleslist_payload = {
"jsonrpc": "1.0",
"id": "python",
"method": "oracleslist",
"params": []}
oracleslist_result = post_rpc(def_credentials(chain), oracleslist_payload)
return(oracleslist_result['result'])
def oraclessubscribe_rpc(chain, oracletxid, publisher, amount):
oraclessubscribe_payload = {
"jsonrpc": "1.0",
"id": "python",
"method": "oraclessubscribe",
"params": [oracletxid, publisher, amount]}
oraclessubscribe_result = post_rpc(def_credentials(chain), oraclessubscribe_payload)
return(oraclessubscribe_result['result'])
def oraclesregister_rpc(chain, oracletxid, datafee):
oraclesregister_payload = {
"jsonrpc": "1.0",
"id": "python",
"method": "oraclesregister",
"params": [
oracletxid,
str(datafee)]}
oraclesregister_result = post_rpc(def_credentials(chain), oraclesregister_payload)
return(oraclesregister_result['result'])
def oraclessamples_rpc(chain, oracletxid, batonutxo, num):
oraclessamples_payload = {
"jsonrpc": "1.0",
"id": "python",
"method": "oraclessamples",
"params": [
oracletxid,
batonutxo,
str(num)]}
oraclessamples_result = post_rpc(def_credentials(chain), oraclessamples_payload)
return(oraclessamples_result['result'])