| tDisconnect client on unknown scripthash - 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 003e14213e3aa18e3db8b44b22495a22fdbfd9b6 |
| parent 97e99149356dae5a8a3a42f45259b82f6ec4db2c |
| Author: chris-belcher |
| Date: Mon, 18 May 2020 22:56:58 +0100
Disconnect client on unknown scripthash
Previously the server would just print a warning to stdout and return
an empty wallet when the client requested an unknown scripthash. Users
dont always read stdout. It is better to actually disconnect the client
instead when this happens. This will make the user figure out what's
wrong and read the debug log or stdout.
Diffstat:
M electrumpersonalserver/server/__in… | 1 +
M electrumpersonalserver/server/comm… | 14 +++++++++-----
M electrumpersonalserver/server/elec… | 9 ++++++---
3 files changed, 16 insertions(+), 8 deletions(-)
--- |
| diff --git a/electrumpersonalserver/server/__init__.py b/electrumpersonalserver/server/__init__.py |
| t@@ -39,6 +39,7 @@ from electrumpersonalserver.server.peertopeer import (
)
from electrumpersonalserver.server.electrumprotocol import (
SERVER_VERSION_NUMBER,
+ UnknownScripthashError,
ElectrumProtocol,
get_block_header,
get_current_header, |
| diff --git a/electrumpersonalserver/server/common.py b/electrumpersonalserver/server/common.py |
| t@@ -19,6 +19,7 @@ import electrumpersonalserver.server.deterministicwallet as deterministicwallet
import electrumpersonalserver.server.transactionmonitor as transactionmonitor
from electrumpersonalserver.server.electrumprotocol import (
SERVER_VERSION_NUMBER,
+ UnknownScripthashError,
ElectrumProtocol,
get_block_header,
get_current_header,
t@@ -160,16 +161,19 @@ def run_electrum_server(rpc, txmonitor, config):
logger.debug("Error with node connection, e = " + repr(e)
+ "\ntraceback = " + str(traceback.format_exc()))
accepting_clients = False
+ except UnknownScripthashError as e:
+ logger.debug("Disconnecting client due to misconfiguration. User"
+ + " must correctly configure master public key(s)")
except (IOError, EOFError) as e:
if isinstance(e, (EOFError, ConnectionRefusedError)):
logger.debug("Electrum wallet disconnected")
else:
logger.debug("IOError: " + repr(e))
- try:
- if sock != None:
- sock.close()
- except IOError:
- pass
+ try:
+ if sock != None:
+ sock.close()
+ except IOError:
+ pass
protocol.on_disconnect()
time.sleep(0.2)
|
| diff --git a/electrumpersonalserver/server/electrumprotocol.py b/electrumpersonalserver/server/electrumprotocol.py |
| t@@ -50,6 +50,9 @@ Donate to help make Electrum Personal Server even better:
"""
+class UnknownScripthashError(Exception):
+ pass
+
def get_tor_hostport():
# Probable ports for Tor to listen at
host = "127.0.0.1"
t@@ -236,15 +239,15 @@ class ElectrumProtocol(object):
+ "check that they really are addresses you expect. In "
+ "Electrum go to Wallet -> Information to get the right "
+ "master public key.")
- history_hash = get_status_electrum([])
+ raise UnknownScripthashError(scrhash)
self._send_response(query, history_hash)
elif method == "blockchain.scripthash.get_history":
scrhash = query["params"][0]
history = self.txmonitor.get_electrum_history(scrhash)
if history == None:
- history = []
self.logger.warning("Address history not known to server, "
+ "hash(address) = " + scrhash)
+ raise UnknownScripthashError(scrhash)
self._send_response(query, history)
elif method == "blockchain.scripthash.get_balance":
scrhash = query["params"][0]
t@@ -252,7 +255,7 @@ class ElectrumProtocol(object):
if balance == None:
self.logger.warning("Address history not known to server, "
+ "hash(address) = " + scrhash)
- balance = {"confirmed": 0, "unconfirmed": 0}
+ raise UnknownScripthashError(scrhash)
self._send_response(query, balance)
elif method == "server.ping":
self._send_response(query, None) |