1
0
mirror of https://github.com/romanz/electrs.git synced 2024-11-19 09:54:09 +01:00
electrs/contrib/client.py
Roman Zeyde 423e4c7922 Rewrite Python scripts
Also, improve balance/history display
2021-06-18 17:49:29 +03:00

25 lines
640 B
Python

import json
import socket
class Client:
def __init__(self, addr):
self.s = socket.create_connection(addr)
self.f = self.s.makefile('r')
self.id = 0
def call(self, requests):
requests = list(requests)
for request in requests:
request['id'] = self.id
request['jsonrpc'] = '2.0'
self.id += 1
msg = json.dumps(requests) + '\n'
self.s.sendall(msg.encode('ascii'))
response = json.loads(self.f.readline())
return [r['result'] for r in response]
def request(method, *args):
return {'method': method, 'params': list(args)}