commit 7cc939b8ab2565e976d9983ca4108cc3e3157b11
parent a1acc2e21c0f494a0d68f86233852abb54103edb
Author: chris-belcher <chris-belcher@users.noreply.github.com>
Date: Tue, 14 Jan 2020 11:19:50 +0000
Add missing imports and move function
Some imports and functions were missed out in the move towards
separating the protocol into another file. Fixes #176
Diffstat:
2 files changed, 21 insertions(+), 19 deletions(-)
diff --git a/electrumpersonalserver/server/common.py b/electrumpersonalserver/server/common.py
@@ -15,7 +15,6 @@ from electrumpersonalserver.server.jsonrpc import JsonRpc, JsonRpcError
import electrumpersonalserver.server.hashes as hashes
import electrumpersonalserver.server.deterministicwallet as deterministicwallet
import electrumpersonalserver.server.transactionmonitor as transactionmonitor
-import electrumpersonalserver.server.peertopeer as peertopeer
from electrumpersonalserver.server.electrumprotocol import (
SERVER_VERSION_NUMBER,
ElectrumProtocol,
@@ -28,24 +27,6 @@ from electrumpersonalserver.server.electrumprotocol import (
## global variables are actually mutable lists
bestblockhash = [None]
-def get_tor_hostport():
- # Probable ports for Tor to listen at
- host = "127.0.0.1"
- ports = [9050, 9150]
- for port in ports:
- try:
- s = (socket._socketobject if hasattr(socket, "_socketobject")
- else socket.socket)(socket.AF_INET, socket.SOCK_STREAM)
- s.settimeout(0.1)
- s.connect((host, port))
- # Tor responds uniquely to HTTP-like requests
- s.send(b"GET\n")
- if b"Tor is not an HTTP Proxy" in s.recv(1024):
- return (host, port)
- except socket.error:
- pass
- return None
-
def on_heartbeat_listening(txmonitor):
logger = logging.getLogger('ELECTRUMPERSONALSERVER')
logger.debug("on heartbeat listening")
diff --git a/electrumpersonalserver/server/electrumprotocol.py b/electrumpersonalserver/server/electrumprotocol.py
@@ -5,6 +5,7 @@ import binascii
import os
import struct
import tempfile
+import socket
from collections import defaultdict
from electrumpersonalserver.server.hashes import (
@@ -13,6 +14,7 @@ from electrumpersonalserver.server.hashes import (
bytes_fmt
)
from .jsonrpc import JsonRpc, JsonRpcError
+import electrumpersonalserver.server.peertopeer as peertopeer
from electrumpersonalserver.server.merkleproof import (
convert_core_to_electrum_merkle_proof
)
@@ -48,6 +50,25 @@ Donate to help make Electrum Personal Server even better:
"""
+def get_tor_hostport():
+ # Probable ports for Tor to listen at
+ host = "127.0.0.1"
+ ports = [9050, 9150]
+ for port in ports:
+ try:
+ s = (socket._socketobject if hasattr(socket, "_socketobject")
+ else socket.socket)(socket.AF_INET, socket.SOCK_STREAM)
+ s.settimeout(0.1)
+ s.connect((host, port))
+ # Tor responds uniquely to HTTP-like requests
+ s.send(b"GET\n")
+ if b"Tor is not an HTTP Proxy" in s.recv(1024):
+ return (host, port)
+ except socket.error:
+ pass
+ return None
+
+
def get_block_header(rpc, blockhash, raw=False):
rpc_head = rpc.call("getblockheader", [blockhash])
if "previousblockhash" in rpc_head: