Better handle bad input to query RPC call
Based on #559. Also: - remove unused import - restore timeout to 15s - handle invalid input by catching at a higher level and converting to RPCError
This commit is contained in:
parent
74e6fe416f
commit
a3afab83d6
@ -6,8 +6,6 @@
|
|||||||
# and warranty status of this software.
|
# and warranty status of this software.
|
||||||
|
|
||||||
|
|
||||||
import asyncio
|
|
||||||
|
|
||||||
from aiorpcx import run_in_thread
|
from aiorpcx import run_in_thread
|
||||||
|
|
||||||
from electrumx.lib.hash import hash_to_hex_str
|
from electrumx.lib.hash import hash_to_hex_str
|
||||||
@ -95,13 +93,9 @@ class ChainState(object):
|
|||||||
except ValueError:
|
except ValueError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
try:
|
hashX = coin.address_to_hashX(arg)
|
||||||
hashX = coin.address_to_hashX(arg)
|
lines.append(f'Address: {arg}')
|
||||||
lines.append(f'Address: {arg}')
|
return hashX
|
||||||
return hashX
|
|
||||||
except Base58Error:
|
|
||||||
print(f'Ingoring unknown arg: {arg}')
|
|
||||||
return None
|
|
||||||
|
|
||||||
for arg in args:
|
for arg in args:
|
||||||
hashX = arg_to_hashX(arg)
|
hashX = arg_to_hashX(arg)
|
||||||
|
|||||||
@ -28,7 +28,7 @@ import electrumx
|
|||||||
import electrumx.lib.text as text
|
import electrumx.lib.text as text
|
||||||
import electrumx.lib.util as util
|
import electrumx.lib.util as util
|
||||||
from electrumx.lib.hash import (sha256, hash_to_hex_str, hex_str_to_hash,
|
from electrumx.lib.hash import (sha256, hash_to_hex_str, hex_str_to_hash,
|
||||||
HASHX_LEN)
|
HASHX_LEN, Base58Error)
|
||||||
from electrumx.lib.peer import Peer
|
from electrumx.lib.peer import Peer
|
||||||
from electrumx.server.daemon import DaemonError
|
from electrumx.server.daemon import DaemonError
|
||||||
from electrumx.server.peers import PeerManager
|
from electrumx.server.peers import PeerManager
|
||||||
@ -384,7 +384,10 @@ class SessionManager(object):
|
|||||||
|
|
||||||
async def rpc_query(self, items, limit):
|
async def rpc_query(self, items, limit):
|
||||||
'''Return a list of data about server peers.'''
|
'''Return a list of data about server peers.'''
|
||||||
return await self.chain_state.query(items, limit)
|
try:
|
||||||
|
return await self.chain_state.query(items, limit)
|
||||||
|
except Base58Error as e:
|
||||||
|
raise RPCError(BAD_REQUEST, e.args[0]) from None
|
||||||
|
|
||||||
async def rpc_sessions(self):
|
async def rpc_sessions(self):
|
||||||
'''Return statistics about connected sessions.'''
|
'''Return statistics about connected sessions.'''
|
||||||
|
|||||||
@ -113,7 +113,7 @@ def main():
|
|||||||
# aiorpcX makes this so easy...
|
# aiorpcX makes this so easy...
|
||||||
async def send_request():
|
async def send_request():
|
||||||
try:
|
try:
|
||||||
async with timeout_after(1):
|
async with timeout_after(15):
|
||||||
async with ClientSession('localhost', port) as session:
|
async with ClientSession('localhost', port) as session:
|
||||||
result = await session.send_request(method, args)
|
result = await session.send_request(method, args)
|
||||||
if method in ('query', ):
|
if method in ('query', ):
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user