async def send_request(self, request_self, method, params, rid): async with ClientSession('localhost', RPC_PORT) as session: try: response = await session.send_request(method, params, timeout=60) except Exception as e: response = e return create_rpc(response, rid)
async def send_request(): # aiorpcX makes this so easy... async with ClientSession('localhost', port) as session: result = await session.send_request(method, params, timeout=15) if method in ('groups', 'peers', 'sessions'): lines_func = getattr(Controller, f'{method}_text_lines') for line in lines_func(result): print(line) else: print(json.dumps(result, indent=4, sort_keys=True))
async def get_tx_history(address): async with ClientSession(electrumx_host, electrumx_port) as session: if address.find("bc1") == 0: scripthash = bech32_to_scripthash(address) await session.send_request("server.version", ["demo", "1.1"], timeout=60) response = await session.send_request( "blockchain.scripthash.get_history", [scripthash], timeout=60) return response else: return await session.send_request("blockchain.address.get_history", [address], timeout=60)
async def send_request(self, request_self, method, params, rid): client_port = port if method in ["getinfo"]: client_port = rpc_port async with ClientSession('localhost', client_port) as session: try: response = await session.send_request(method, params, timeout=60) except Exception as e: response = e request_self._set_response() request_self.wfile.write( json.dumps(create_rpc(response, rid)).encode('utf-8'))
def create_electrumx_session(app): connection = JSONRPCConnection(JSONRPCv2) electrum_config = app.config.electrum return ClientSession(host=electrum_config.host, port=electrum_config.port, connection=connection)