-
Notifications
You must be signed in to change notification settings - Fork 29
/
dpowassets.py
executable file
·80 lines (70 loc) · 2.05 KB
/
dpowassets.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
#!/usr/bin/env python3
import requests
import json
import pprint
import sys
import os
import configparser
import csv
# read configuration file
ENVIRON = 'PROD'
config = configparser.ConfigParser()
config.read('config.ini')
# Read the assetchians.json file
script_dir = os.getcwd()
with open(script_dir + '/assetchains.json') as file:
assetchains = json.load(file)
# configure pretty printer
pp = pprint.PrettyPrinter(width=41, compact=True)
# get connection options
conn = {}
connection_options = [
'iguana_ip',
'iguana_port']
for i in connection_options:
conn[i] = config[ENVIRON][i]
if len(sys.argv) > 1:
specific_iguana = sys.argv[1]
else:
specific_iguana = False
# define function that posts json data to iguana
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)
# set btcpubkey
btcpubkey = config[ENVIRON]['btcpubkey']
# dpow
def dpow(symbol, freq, iguana_rpc, iguana):
payload = {
"agent": "iguana",
"method": "dpow",
"symbol": symbol,
"freq": freq,
"pubkey": btcpubkey
}
# define url's
iguana_url = 'http://' + conn['iguana_ip'] + ':' + iguana_rpc
try:
response_dpow = post_rpc(iguana_url, payload)
print('== response_dpow ' + iguana + ' : ' + symbol + ' ==')
pp.pprint(response_dpow)
except Exception as e:
print('== response_dpow ' + iguana + ' : ' + str(e) + ' ==')
# dpow assetchains
for chain in assetchains:
ac_chain = chain['ac_name']
iguana_rpc = conn['iguana_port']
iguana = "blackjok3r"
if 'iguana_rpc' in chain:
iguana_rpc = chain['iguana_rpc']
if 'iguana' in chain:
iguana = chain['iguana']
if specific_iguana and iguana != specific_iguana:
continue
for param, value in chain.items():
if param == 'freq':
ac_freq = chain['freq']
dpow(ac_chain,ac_freq,iguana_rpc,iguana)