electrum

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

commit 791e0e1a67fee73c8d1da7ca4c733a21ce1ea628
parent 99d18a48f2e22604b8fdfbc236ce5d58e17db0c2
Author: SomberNight <somber.night@protonmail.com>
Date:   Thu, 25 Oct 2018 23:08:59 +0200

move relayfee and dust_threshold to bitcoin.py

Diffstat:
Melectrum/bitcoin.py | 17++++++++++++++++-
Melectrum/network.py | 2+-
Melectrum/wallet.py | 14+-------------
3 files changed, 18 insertions(+), 15 deletions(-)

diff --git a/electrum/bitcoin.py b/electrum/bitcoin.py @@ -24,7 +24,7 @@ # SOFTWARE. import hashlib -from typing import List, Tuple +from typing import List, Tuple, TYPE_CHECKING from .util import bfh, bh2u, BitcoinException, assert_bytes, to_bytes, inv_dict from . import version @@ -33,6 +33,9 @@ from . import constants from . import ecc from .crypto import sha256d, sha256, hash_160, hmac_oneshot +if TYPE_CHECKING: + from .network import Network + ################################## transactions @@ -147,6 +150,18 @@ def add_number_to_script(i: int) -> bytes: return bfh(push_script(script_num_to_hex(i))) +def relayfee(network: 'Network'=None) -> int: + 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'=None) -> int: + # Change <= dust threshold is added to the tx fee + return 182 * 3 * relayfee(network) // 1000 + + hash_encode = lambda x: bh2u(x[::-1]) hash_decode = lambda x: bfh(x)[::-1] hmac_sha_512 = lambda x, y: hmac_oneshot(x, y, hashlib.sha512) diff --git a/electrum/network.py b/electrum/network.py @@ -201,7 +201,7 @@ class Network(PrintError): self.banner = '' self.donation_address = '' - self.relay_fee = None + self.relay_fee = None # type: Optional[int] # callbacks set by the GUI self.callbacks = defaultdict(list) # note: needs self.callback_lock diff --git a/electrum/wallet.py b/electrum/wallet.py @@ -47,7 +47,7 @@ from .util import (NotEnoughFunds, PrintError, UserCancelled, profiler, InvalidPassword, format_time, timestamp_to_datetime, Satoshis, Fiat, bfh, bh2u) from .bitcoin import (COIN, TYPE_ADDRESS, is_address, address_to_script, - is_minikey) + is_minikey, relayfee, dust_threshold) from .version import * from .crypto import sha256d from .keystore import load_keystore, Hardware_KeyStore @@ -74,18 +74,6 @@ TX_STATUS = [ ] - -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'): - # 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): if txin_type != 'p2pk': address = bitcoin.pubkey_to_address(txin_type, pubkey)