diff --git a/electrum/network.py b/electrum/network.py index 612090d14..c82b57e9b 100644 --- a/electrum/network.py +++ b/electrum/network.py @@ -234,7 +234,7 @@ class Network(Logger): LOGGING_SHORTCUT = 'n' - def __init__(self, config: SimpleConfig=None): + def __init__(self, config: SimpleConfig): global INSTANCE INSTANCE = self @@ -244,9 +244,8 @@ class Network(Logger): assert self.asyncio_loop.is_running(), "event loop not running" self._loop_thread = None # type: threading.Thread # set by caller; only used for sanity checks - if config is None: - config = {} # Do not use mutables as default values! - self.config = SimpleConfig(config) if isinstance(config, dict) else config # type: SimpleConfig + assert isinstance(config, SimpleConfig), f"config should be a SimpleConfig instead of {type(config)}" + self.config = config blockchain.read_blockchains(self.config) self.logger.info(f"blockchains {list(map(lambda b: b.forkpoint, blockchain.blockchains.values()))}") self._blockchain_preferred_block = self.config.get('blockchain_preferred_block', None) # type: Optional[Dict] diff --git a/electrum/scripts/block_headers.py b/electrum/scripts/block_headers.py index abf6a2595..aac821032 100755 --- a/electrum/scripts/block_headers.py +++ b/electrum/scripts/block_headers.py @@ -7,10 +7,13 @@ import asyncio from electrum.network import Network from electrum.util import print_msg, json_encode, create_and_start_event_loop, log_exceptions +from electrum.simple_config import SimpleConfig + +config = SimpleConfig() # start network loop, stopping_fut, loop_thread = create_and_start_event_loop() -network = Network() +network = Network(config) network.start() # wait until connected diff --git a/electrum/scripts/estimate_fee.py b/electrum/scripts/estimate_fee.py index 76bcc55b5..a281a65bc 100755 --- a/electrum/scripts/estimate_fee.py +++ b/electrum/scripts/estimate_fee.py @@ -6,10 +6,13 @@ from numbers import Number from electrum.network import filter_protocol, Network from electrum.util import create_and_start_event_loop, log_exceptions +from electrum.simple_config import SimpleConfig +config = SimpleConfig() + loop, stopping_fut, loop_thread = create_and_start_event_loop() -network = Network() +network = Network(config) network.start() @log_exceptions diff --git a/electrum/scripts/get_history.py b/electrum/scripts/get_history.py index a97698288..cff747802 100755 --- a/electrum/scripts/get_history.py +++ b/electrum/scripts/get_history.py @@ -6,6 +6,7 @@ import asyncio from electrum import bitcoin from electrum.network import Network from electrum.util import json_encode, print_msg, create_and_start_event_loop, log_exceptions +from electrum.simple_config import SimpleConfig try: @@ -14,8 +15,10 @@ except Exception: print("usage: get_history ") sys.exit(1) +config = SimpleConfig() + loop, stopping_fut, loop_thread = create_and_start_event_loop() -network = Network() +network = Network(config) network.start() @log_exceptions diff --git a/electrum/scripts/peers.py b/electrum/scripts/peers.py index e55e716fe..a26572b30 100755 --- a/electrum/scripts/peers.py +++ b/electrum/scripts/peers.py @@ -4,9 +4,13 @@ import asyncio from electrum.network import filter_protocol, Network from electrum.util import create_and_start_event_loop, log_exceptions from electrum.blockchain import hash_raw_header +from electrum.simple_config import SimpleConfig + + +config = SimpleConfig() loop, stopping_fut, loop_thread = create_and_start_event_loop() -network = Network() +network = Network(config) network.start() @log_exceptions diff --git a/electrum/scripts/txradar.py b/electrum/scripts/txradar.py index 7fb8f7be3..2166a87ba 100755 --- a/electrum/scripts/txradar.py +++ b/electrum/scripts/txradar.py @@ -4,6 +4,7 @@ import asyncio from electrum.network import filter_protocol, Network from electrum.util import create_and_start_event_loop, log_exceptions +from electrum.simple_config import SimpleConfig try: @@ -12,9 +13,10 @@ except: print("usage: txradar txid") sys.exit(1) +config = SimpleConfig() loop, stopping_fut, loop_thread = create_and_start_event_loop() -network = Network() +network = Network(config) network.start() @log_exceptions diff --git a/electrum/scripts/watch_address.py b/electrum/scripts/watch_address.py index 851160de5..297ec2ea2 100755 --- a/electrum/scripts/watch_address.py +++ b/electrum/scripts/watch_address.py @@ -6,6 +6,7 @@ import asyncio from electrum.network import Network from electrum.util import print_msg, create_and_start_event_loop from electrum.synchronizer import SynchronizerBase +from electrum.simple_config import SimpleConfig try: @@ -14,9 +15,11 @@ except Exception: print("usage: watch_address ") sys.exit(1) +config = SimpleConfig() + # start network loop = create_and_start_event_loop()[0] -network = Network() +network = Network(config) network.start()