mirror of
https://github.com/LBRYFoundation/LBRY-Vault.git
synced 2025-08-31 17:31:36 +00:00
types: make some import conditional
This commit is contained in:
parent
082a83dd85
commit
99d18a48f2
3 changed files with 21 additions and 13 deletions
|
@ -25,6 +25,7 @@ import threading
|
||||||
import asyncio
|
import asyncio
|
||||||
import itertools
|
import itertools
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
from . import bitcoin
|
from . import bitcoin
|
||||||
from .bitcoin import COINBASE_MATURITY, TYPE_ADDRESS, TYPE_PUBKEY
|
from .bitcoin import COINBASE_MATURITY, TYPE_ADDRESS, TYPE_PUBKEY
|
||||||
|
@ -34,6 +35,8 @@ from .synchronizer import Synchronizer
|
||||||
from .verifier import SPV
|
from .verifier import SPV
|
||||||
from .blockchain import hash_header
|
from .blockchain import hash_header
|
||||||
from .i18n import _
|
from .i18n import _
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
from .storage import WalletStorage
|
from .storage import WalletStorage
|
||||||
from .network import Network
|
from .network import Network
|
||||||
|
|
||||||
|
@ -56,7 +59,7 @@ class AddressSynchronizer(PrintError):
|
||||||
inherited by wallet
|
inherited by wallet
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, storage: WalletStorage):
|
def __init__(self, storage: 'WalletStorage'):
|
||||||
self.storage = storage
|
self.storage = storage
|
||||||
self.network = None # type: Network
|
self.network = None # type: Network
|
||||||
# verifier (SPV) and synchronizer are started in start_network
|
# verifier (SPV) and synchronizer are started in start_network
|
||||||
|
|
|
@ -32,7 +32,7 @@ import ast
|
||||||
import base64
|
import base64
|
||||||
from functools import wraps
|
from functools import wraps
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
from typing import Optional
|
from typing import Optional, TYPE_CHECKING
|
||||||
|
|
||||||
from .import util, ecc
|
from .import util, ecc
|
||||||
from .util import bfh, bh2u, format_satoshis, json_decode, print_error, json_encode
|
from .util import bfh, bh2u, format_satoshis, json_decode, print_error, json_encode
|
||||||
|
@ -46,6 +46,8 @@ from .storage import WalletStorage
|
||||||
from . import keystore
|
from . import keystore
|
||||||
from .wallet import Wallet, Imported_Wallet, Abstract_Wallet
|
from .wallet import Wallet, Imported_Wallet, Abstract_Wallet
|
||||||
from .mnemonic import Mnemonic
|
from .mnemonic import Mnemonic
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
from .network import Network
|
from .network import Network
|
||||||
from .simple_config import SimpleConfig
|
from .simple_config import SimpleConfig
|
||||||
|
|
||||||
|
|
|
@ -38,6 +38,7 @@ import traceback
|
||||||
from functools import partial
|
from functools import partial
|
||||||
from numbers import Number
|
from numbers import Number
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
from .i18n import _
|
from .i18n import _
|
||||||
from .util import (NotEnoughFunds, PrintError, UserCancelled, profiler,
|
from .util import (NotEnoughFunds, PrintError, UserCancelled, profiler,
|
||||||
|
@ -59,6 +60,8 @@ from .address_synchronizer import (AddressSynchronizer, TX_HEIGHT_LOCAL,
|
||||||
from .paymentrequest import (PR_PAID, PR_UNPAID, PR_UNKNOWN, PR_EXPIRED,
|
from .paymentrequest import (PR_PAID, PR_UNPAID, PR_UNKNOWN, PR_EXPIRED,
|
||||||
InvoiceStore)
|
InvoiceStore)
|
||||||
from .contacts import Contacts
|
from .contacts import Contacts
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
from .network import Network
|
from .network import Network
|
||||||
from .simple_config import SimpleConfig
|
from .simple_config import SimpleConfig
|
||||||
|
|
||||||
|
@ -72,18 +75,18 @@ TX_STATUS = [
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def relayfee(network: Network):
|
def relayfee(network: 'Network'):
|
||||||
from .simple_config import FEERATE_DEFAULT_RELAY
|
from .simple_config import FEERATE_DEFAULT_RELAY
|
||||||
MAX_RELAY_FEE = 50000
|
MAX_RELAY_FEE = 50000
|
||||||
f = network.relay_fee if network and network.relay_fee else FEERATE_DEFAULT_RELAY
|
f = network.relay_fee if network and network.relay_fee else FEERATE_DEFAULT_RELAY
|
||||||
return min(f, MAX_RELAY_FEE)
|
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
|
# Change <= dust threshold is added to the tx fee
|
||||||
return 182 * 3 * relayfee(network) / 1000
|
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':
|
if txin_type != 'p2pk':
|
||||||
address = bitcoin.pubkey_to_address(txin_type, pubkey)
|
address = bitcoin.pubkey_to_address(txin_type, pubkey)
|
||||||
scripthash = bitcoin.address_to_scripthash(address)
|
scripthash = bitcoin.address_to_scripthash(address)
|
||||||
|
@ -106,7 +109,7 @@ def append_utxos_to_inputs(inputs, network: Network, pubkey, txin_type, imax):
|
||||||
item['num_sig'] = 1
|
item['num_sig'] = 1
|
||||||
inputs.append(item)
|
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):
|
def find_utxos_for_privkey(txin_type, privkey, compressed):
|
||||||
pubkey = ecc.ECPrivkey(privkey).get_public_key_hex(compressed=compressed)
|
pubkey = ecc.ECPrivkey(privkey).get_public_key_hex(compressed=compressed)
|
||||||
|
@ -132,7 +135,7 @@ def sweep_preparations(privkeys, network: Network, imax=100):
|
||||||
return inputs, keypairs
|
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)
|
inputs, keypairs = sweep_preparations(privkeys, network, imax)
|
||||||
total = sum(i.get('value') for i in inputs)
|
total = sum(i.get('value') for i in inputs)
|
||||||
if fee is None:
|
if fee is None:
|
||||||
|
|
Loading…
Add table
Reference in a new issue