btcproxy: Unpack batched JSON-RPC calls and issue them separately

This commit is contained in:
Christian Decker 2018-08-30 19:50:42 +02:00
parent 88186020e0
commit 74f228deb8

View file

@ -31,8 +31,7 @@ class ProxiedBitcoinD(BitcoinD):
self.proxyport = proxyport
self.mocks = {}
def proxy(self):
r = json.loads(request.data.decode('ASCII'))
def _handle_request(self, r):
conf_file = os.path.join(self.bitcoin_dir, 'bitcoin.conf')
brpc = BitcoinProxy(btc_conf_file=conf_file)
method = r['method']
@ -55,6 +54,16 @@ class ProxiedBitcoinD(BitcoinD):
"error": e.error,
"id": r['id']
}
return reply
def proxy(self):
r = json.loads(request.data.decode('ASCII'))
if isinstance(r, list):
reply = [self._handle_request(subreq) for subreq in r]
else:
reply = self._handle_request(subreq)
return json.dumps(reply, cls=DecimalEncoder)
def start(self):