mirror of
https://github.com/romanz/electrs.git
synced 2024-11-19 18:10:51 +01:00
20 lines
486 B
Python
20 lines
486 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, method, *args):
|
|
req = {
|
|
'id': self.id,
|
|
'method': method,
|
|
'params': list(args),
|
|
'jsonrpc': '2.0',
|
|
}
|
|
msg = json.dumps(req) + '\n'
|
|
self.s.sendall(msg.encode('ascii'))
|
|
return json.loads(self.f.readline())
|