electrum

Electrum Bitcoin wallet
git clone https://git.parazyd.org/electrum
Log | Files | Refs | Submodules

commit d1026b5afeae5873022427e3f344d000df5a1c4d
parent 16e293c289ddba7c055f6cccaddd7315f09fb3ba
Author: SomberNight <somber.night@protonmail.com>
Date:   Tue, 10 Sep 2019 16:38:10 +0200

follow-up: SimpleConfig is supposed to be singleton

see cefa4762ba904ef92d32b4c90005013dd7a7ac4a
and #5629

Diffstat:
Melectrum/network.py | 7+++----
Melectrum/scripts/block_headers.py | 5++++-
Melectrum/scripts/estimate_fee.py | 5++++-
Melectrum/scripts/get_history.py | 5++++-
Melectrum/scripts/peers.py | 6+++++-
Melectrum/scripts/txradar.py | 4+++-
Melectrum/scripts/watch_address.py | 5++++-
7 files changed, 27 insertions(+), 10 deletions(-)

diff --git 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 @@ -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 @@ -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 @@ -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 <bitcoin_address>") 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 @@ -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 @@ -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 @@ -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 <bitcoin_address>") sys.exit(1) +config = SimpleConfig() + # start network loop = create_and_start_event_loop()[0] -network = Network() +network = Network(config) network.start()