electrum-personal-server

Maximally lightweight electrum server for a single user
git clone https://git.parazyd.org/electrum-personal-server
Log | Files | Refs | README

commit 839c222880efce312363a89068c6cd724c3b267b
parent 9388442a35fe2e185af698b6eb4a2ec2c8ebe2e4
Author: chris-belcher <chris-belcher@users.noreply.github.com>
Date:   Sun, 19 Aug 2018 17:04:46 +0100

Handle client requesting header out of range

Solves issue #49. If a client requests blockchain.blocks.headers
with start_height beyond the chain length then the server would
have crashed.

Diffstat:
Mserver.py | 7+++++--
1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/server.py b/server.py @@ -294,7 +294,10 @@ def check_for_new_blockchain_tip(rpc, raw): def get_block_headers_hex(rpc, start_height, count): #read count number of headers starting from start_height result = bytearray() - the_hash = rpc.call("getblockhash", [start_height]) + try: + the_hash = rpc.call("getblockhash", [start_height]) + except JsonRpcError as e: + return "", 0 for i in range(count): header = rpc.call("getblockheader", [the_hash]) #add header hex to result @@ -310,7 +313,7 @@ def get_block_headers_hex(rpc, start_height, count): if "nextblockhash" not in header: break the_hash = header["nextblockhash"] - return binascii.hexlify(result).decode("utf-8"), len(result)/80 + return binascii.hexlify(result).decode("utf-8"), int(len(result)/80) def create_server_socket(hostport): server_sock = socket.socket()