1
0
Fork 0
mirror of https://github.com/romanz/electrs.git synced 2025-02-23 22:56:55 +01:00
electrs/contrib/client.py

19 lines
460 B
Python
Raw Normal View History

2018-04-30 14:37:23 +03:00
import json
import socket
2018-04-25 22:44:36 +03:00
2018-05-02 13:42:13 +03:00
class Connection:
def __init__(self, addr):
self.s = socket.create_connection(addr)
self.f = self.s.makefile('r')
self.id = 0
def call(self, method, *args):
req = {
'id': self.id,
'method': method,
'params': list(args),
}
msg = json.dumps(req) + '\n'
self.s.sendall(msg.encode('ascii'))
return json.loads(self.f.readline())