From 7f3551e435a3d03057ad1ce77f30eb9a1c8c6939 Mon Sep 17 00:00:00 2001 From: Neil Booth Date: Fri, 18 Nov 2016 20:55:28 +0900 Subject: [PATCH] tx_merkle: catch bad hashes and report properly Fixes #27 --- server/protocol.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/server/protocol.py b/server/protocol.py index 1a23704..c5e1822 100644 --- a/server/protocol.py +++ b/server/protocol.py @@ -395,8 +395,11 @@ class ElectrumX(Session): hex_hashes = await self.daemon.block_hex_hashes(height, 1) block = await self.daemon.deserialised_block(hex_hashes[0]) tx_hashes = block['tx'] - # This will throw if the tx_hash is bad - pos = tx_hashes.index(tx_hash) + try: + pos = tx_hashes.index(tx_hash) + except ValueError: + raise self.RPCError('tx hash {} not in block {} at height {:,d}' + .format(tx_hash, hex_hashes[0], height)) idx = pos hashes = [hex_str_to_hash(txh) for txh in tx_hashes]