ttypes: make some import conditional - electrum - Electrum Bitcoin wallet HTML git clone https://git.parazyd.org/electrum DIR Log DIR Files DIR Refs DIR Submodules --- DIR commit 99d18a48f2e22604b8fdfbc236ce5d58e17db0c2 DIR parent 082a83dd85ae8aa8a3faf10ef12d360a7e22ac42 HTML Author: SomberNight <somber.night@protonmail.com> Date: Thu, 25 Oct 2018 23:01:53 +0200 ttypes: make some import conditional Diffstat: M electrum/address_synchronizer.py | 9 ++++++--- M electrum/commands.py | 8 +++++--- M electrum/wallet.py | 17 ++++++++++------- 3 files changed, 21 insertions(+), 13 deletions(-) --- DIR diff --git a/electrum/address_synchronizer.py b/electrum/address_synchronizer.py t@@ -25,6 +25,7 @@ import threading import asyncio import itertools from collections import defaultdict +from typing import TYPE_CHECKING from . import bitcoin from .bitcoin import COINBASE_MATURITY, TYPE_ADDRESS, TYPE_PUBKEY t@@ -34,8 +35,10 @@ from .synchronizer import Synchronizer from .verifier import SPV from .blockchain import hash_header from .i18n import _ -from .storage import WalletStorage -from .network import Network + +if TYPE_CHECKING: + from .storage import WalletStorage + from .network import Network TX_HEIGHT_LOCAL = -2 t@@ -56,7 +59,7 @@ class AddressSynchronizer(PrintError): inherited by wallet """ - def __init__(self, storage: WalletStorage): + def __init__(self, storage: 'WalletStorage'): self.storage = storage self.network = None # type: Network # verifier (SPV) and synchronizer are started in start_network DIR diff --git a/electrum/commands.py b/electrum/commands.py t@@ -32,7 +32,7 @@ import ast import base64 from functools import wraps from decimal import Decimal -from typing import Optional +from typing import Optional, TYPE_CHECKING from .import util, ecc from .util import bfh, bh2u, format_satoshis, json_decode, print_error, json_encode t@@ -46,8 +46,10 @@ from .storage import WalletStorage from . import keystore from .wallet import Wallet, Imported_Wallet, Abstract_Wallet from .mnemonic import Mnemonic -from .network import Network -from .simple_config import SimpleConfig + +if TYPE_CHECKING: + from .network import Network + from .simple_config import SimpleConfig known_commands = {} DIR diff --git a/electrum/wallet.py b/electrum/wallet.py t@@ -38,6 +38,7 @@ import traceback from functools import partial from numbers import Number from decimal import Decimal +from typing import TYPE_CHECKING from .i18n import _ from .util import (NotEnoughFunds, PrintError, UserCancelled, profiler, t@@ -59,8 +60,10 @@ from .address_synchronizer import (AddressSynchronizer, TX_HEIGHT_LOCAL, from .paymentrequest import (PR_PAID, PR_UNPAID, PR_UNKNOWN, PR_EXPIRED, InvoiceStore) from .contacts import Contacts -from .network import Network -from .simple_config import SimpleConfig + +if TYPE_CHECKING: + from .network import Network + from .simple_config import SimpleConfig TX_STATUS = [ t@@ -72,18 +75,18 @@ TX_STATUS = [ -def relayfee(network: Network): +def relayfee(network: 'Network'): from .simple_config import FEERATE_DEFAULT_RELAY MAX_RELAY_FEE = 50000 f = network.relay_fee if network and network.relay_fee else FEERATE_DEFAULT_RELAY return min(f, MAX_RELAY_FEE) -def dust_threshold(network: Network): +def dust_threshold(network: 'Network'): # Change <= dust threshold is added to the tx fee return 182 * 3 * relayfee(network) / 1000 -def append_utxos_to_inputs(inputs, network: Network, pubkey, txin_type, imax): +def append_utxos_to_inputs(inputs, network: 'Network', pubkey, txin_type, imax): if txin_type != 'p2pk': address = bitcoin.pubkey_to_address(txin_type, pubkey) scripthash = bitcoin.address_to_scripthash(address) t@@ -106,7 +109,7 @@ def append_utxos_to_inputs(inputs, network: Network, pubkey, txin_type, imax): item['num_sig'] = 1 inputs.append(item) -def sweep_preparations(privkeys, network: Network, imax=100): +def sweep_preparations(privkeys, network: 'Network', imax=100): def find_utxos_for_privkey(txin_type, privkey, compressed): pubkey = ecc.ECPrivkey(privkey).get_public_key_hex(compressed=compressed) t@@ -132,7 +135,7 @@ def sweep_preparations(privkeys, network: Network, imax=100): return inputs, keypairs -def sweep(privkeys, network: Network, config: SimpleConfig, recipient, fee=None, imax=100): +def sweep(privkeys, network: 'Network', config: 'SimpleConfig', recipient, fee=None, imax=100): inputs, keypairs = sweep_preparations(privkeys, network, imax) total = sum(i.get('value') for i in inputs) if fee is None: