-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
executable file
·37 lines (33 loc) · 1.23 KB
/
main.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
#!/usr/bin/env python3
from ssh_tunnel import SSHTunnel
import requests, time, json, sys
from pygments import highlight, lexers, formatters
def main(config):
with open(config) as file:
config_data = json.load(file)
tunnel = SSHTunnel(
config_data["local_port"],
config_data["remote_port"],
config_data["remote_user"],
config_data["remote_host"]
)
tunnel.start()
time.sleep(1)
headers = {'content-type': 'text/plain;'}
data = '{"jsonrpc":"1.0","id":"curltext","method":"listunspent","params":[]}'
response = requests.post(
"http://127.0.0.1:{}/".format(config_data["local_port"]),
headers=headers, data=data, auth=(config_data["rpc_user"], config_data["rpc_password"])
)
response_dict = response.json()
my_vals = [{
'txid': x['txid'],
'amount': x['amount'],
'address': x['address'],
'vout': x['vout']} for x in response_dict['result']]
print(highlight(json.dumps(my_vals, indent=2), lexers.JsonLexer(), formatters.TerminalFormatter()))
if __name__ == '__main__':
if len(sys.argv) != 2:
print("Please pass a path to a config file.")
else:
main(sys.argv[1])