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 c8dbdd8bd4b0c37e210e174a42c0daa7b5883235
parent b8aab06cf37cf2e2c0831d42c929135ce5a1f346
Author: chris-belcher <chris-belcher@users.noreply.github.com>
Date:   Sun,  8 Apr 2018 18:08:18 +0100

added check for out of range block header request

Diffstat:
Mserver.py | 17++++++++++++++---
1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/server.py b/server.py @@ -70,6 +70,11 @@ def send_update(sock, update): sock.sendall(json.dumps(update).encode('utf-8') + b'\n') debug('<= ' + json.dumps(update)) +def send_error(sock, nid, error): + payload = {"error": error, "jsonrpc": "2.0", "id": nid} + sock.sendall(json.dumps(query).encode('utf-8') + b'\n') + debug('<= ' + json.dumps(query)) + def on_heartbeat_listening(txmonitor): debug("on heartbeat listening") txmonitor.check_for_updated_txes() @@ -149,9 +154,15 @@ def handle_query(sock, line, rpc, txmonitor): new_bestblockhash, header = get_current_header(rpc) send_response(sock, query, header) elif method == "blockchain.block.get_header": - blockhash = rpc.call("getblockhash", [query["params"][0]]) - header = get_block_header(rpc, blockhash) - send_response(sock, query, header) + height = query["params"][0] + try: + blockhash = rpc.call("getblockhash", [height]) + header = get_block_header(rpc, blockhash) + send_response(sock, query, header) + except JsonRpcError: + error = {"message": "height " + str(height) + " out of range", + "code": -1} + send_error(sock, query["id"], error) elif method == "blockchain.block.get_chunk": RETARGET_INTERVAL = 2016 index = query["params"][0]