diff --git a/electrum/bitcoin.py b/electrum/bitcoin.py index b2959f021..43afc6bbb 100644 --- a/electrum/bitcoin.py +++ b/electrum/bitcoin.py @@ -23,19 +23,17 @@ # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. import binascii -import hashlib from typing import List, Tuple, TYPE_CHECKING, Optional, Union, NamedTuple from eth_abi import encode_abi, decode_abi from eth_utils import function_abi_to_4byte_selector import enum from enum import IntEnum, Enum -from .util import bfh, bh2u, BitcoinException, assert_bytes, to_bytes, inv_dict -from . import version +from .util import bfh, BitcoinException, assert_bytes, to_bytes, inv_dict from . import segwit_addr from . import constants from . import ecc -from .crypto import sha256d, sha256, hash_160, hmac_oneshot +from .crypto import sha256d, sha256, hash_160 if TYPE_CHECKING: from .network import Network @@ -459,7 +457,7 @@ def address_to_script(addr: str, *, net=None) -> str: script = pubkeyhash_to_p2pkh_script(hash_160_.hex()) elif addrtype == net.ADDRTYPE_P2SH: script = opcodes.OP_HASH160.hex() - script += push_script(bh2u(hash_160_)) + script += push_script(hash_160_.hex()) script += opcodes.OP_EQUAL.hex() else: raise BitcoinException(f'unknown address type: {addrtype}') @@ -506,7 +504,7 @@ def address_to_scripthash(addr: str) -> str: def script_to_scripthash(script: str) -> str: h = sha256(bfh(script))[0:32] - return bh2u(bytes(reversed(h))) + return bytes(reversed(h)).hex() def public_key_to_p2pk_script(pubkey: str) -> str: @@ -612,7 +610,7 @@ def DecodeBase58Check(psz: Union[bytes, str]) -> bytes: csum_found = vchRet[-4:] csum_calculated = sha256d(payload)[0:4] if csum_calculated != csum_found: - raise InvalidChecksum(f'calculated {bh2u(csum_calculated)}, found {bh2u(csum_found)}') + raise InvalidChecksum(f'calculated {csum_calculated.hex()}, found {csum_found.hex()}') else: return payload diff --git a/electrum/blockchain.py b/electrum/blockchain.py index d277aaf81..248172a1f 100644 --- a/electrum/blockchain.py +++ b/electrum/blockchain.py @@ -31,7 +31,7 @@ from .bitcoin import hash_encode, int_to_hex, rev_hex, var_int from .crypto import sha256d from . import constants -from .util import bfh, bh2u, unpack_uint16_from, unpack_int32_from, unpack_uint32_from, unpack_int64_from, unpack_uint64_from +from .util import bfh, unpack_uint16_from, unpack_int32_from, unpack_uint32_from, unpack_int64_from, unpack_uint64_from from .simple_config import SimpleConfig from .logging import get_logger, Logger diff --git a/electrum/constants.py b/electrum/constants.py index 845c0a97a..8a06e8af0 100644 --- a/electrum/constants.py +++ b/electrum/constants.py @@ -142,7 +142,7 @@ class QtumTestnet(AbstractNet): QIP5_FORK_HEIGHT = 446320 QIP9_FORK_HEIGHT = 446320 OFFLINE_STAKE_HEIGHT = 625000 - USE_OPSENDER = False + USE_OPSENDER = True LN_REALM_BYTE = 0 LN_DNS_SEEDS = [] diff --git a/electrum/gui/qt/main_window.py b/electrum/gui/qt/main_window.py index 25d874fc4..e1ed45169 100644 --- a/electrum/gui/qt/main_window.py +++ b/electrum/gui/qt/main_window.py @@ -3359,12 +3359,10 @@ def call_add_delegation(self, addr, staker, fee, gas_limit, gas_price, dialog): """ :param staker: hash160 str """ + password = None if self.wallet.has_keystore_encryption(): password = self.password_dialog(_("Enter your password to proceed")) - if not password: - return - else: - password = None + if not password: return pod = self.wallet.sign_message(addr, staker, password) args = [staker.lower(), fee, pod] @@ -3372,12 +3370,11 @@ def call_add_delegation(self, addr, staker, fee, gas_limit, gas_price, dialog): gas_limit, gas_price, 0, addr, dialog, False, password, tx_desc="update delegation") def call_remove_delegation(self, addr, gas_limit, gas_price, dialog): + password = None if self.wallet.has_keystore_encryption(): password = self.password_dialog(_("Enter your password to proceed")) - if not password: - return - else: - password = None + if not password: return + self.sendto_smart_contract(DELEGATION_CONTRACT, DELEGATE_ABI[0], [], gas_limit, gas_price, 0, addr, dialog, False, password, tx_desc="remove delegation") diff --git a/electrum/mnemonic.py b/electrum/mnemonic.py index 6e0f0e687..fd7e20642 100644 --- a/electrum/mnemonic.py +++ b/electrum/mnemonic.py @@ -30,7 +30,7 @@ from typing import Sequence, Dict from types import MappingProxyType -from .util import resource_path, bfh, bh2u, randrange +from .util import resource_path, bfh, randrange from .crypto import hmac_oneshot from . import version from .logging import Logger @@ -217,7 +217,7 @@ def make_seed(self, seed_type=None, *, num_bits=132) -> str: def is_new_seed(x: str, prefix=version.SEED_PREFIX) -> bool: x = normalize_text(x) - s = bh2u(hmac_oneshot(b"Seed version", x.encode('utf8'), hashlib.sha512)) + s = hmac_oneshot(b"Seed version", x.encode('utf8'), hashlib.sha512).hex() return s.startswith(prefix) diff --git a/electrum/network.py b/electrum/network.py index 582deed12..c861f640d 100644 --- a/electrum/network.py +++ b/electrum/network.py @@ -43,14 +43,13 @@ from . import util from .util import (log_exceptions, ignore_exceptions, - bfh, SilentTaskGroup, make_aiohttp_session, send_exception_to_crash_reporter, - is_hash256_str, is_non_negative_integer, bh2u, MyEncoder, NetworkRetryManager) + SilentTaskGroup, make_aiohttp_session, send_exception_to_crash_reporter, + MyEncoder, NetworkRetryManager) from .bitcoin import COIN, b58_address_to_hash160, TOKEN_TRANSFER_TOPIC, DELEGATION_CONTRACT, DELEGATE_ABI, eth_output_decode from . import constants from . import blockchain from . import bitcoin -from .blockchain import Blockchain from . import dns_hacks from .transaction import Transaction from .blockchain import Blockchain @@ -1337,18 +1336,18 @@ async def call_contract(self, address, data, sender): async def request_token_balance(self, bind_addr, contract_addr): __, hash160 = b58_address_to_hash160(bind_addr) - hash160 = bh2u(hash160) + hash160 = hash160.hex() datahex = '70a08231{}'.format(hash160.zfill(64)) return await self.interface.session.send_request('blockchain.contract.call', [contract_addr, datahex, '', 'int']) async def request_token_history(self, bind_addr, contract_addr): __, hash160 = b58_address_to_hash160(bind_addr) - hash160 = bh2u(hash160) + hash160 = hash160.hex() return await self.interface.session.send_request('blockchain.contract.event.get_history', [hash160, contract_addr, TOKEN_TRANSFER_TOPIC]) async def request_delegation_info(self, addr): __, hash160 = b58_address_to_hash160(addr) - hash160 = bh2u(hash160) + hash160 = hash160.hex() datahex = 'bffe3486{}'.format(hash160.zfill(64)) result = await self.call_contract(DELEGATION_CONTRACT, datahex, '') return eth_output_decode(DELEGATE_ABI[2], result) diff --git a/electrum/util.py b/electrum/util.py index 45297c652..1bc9fe8cc 100644 --- a/electrum/util.py +++ b/electrum/util.py @@ -917,7 +917,7 @@ def parse_URI(uri: str, on_pr: Callable = None, *, loop=None) -> dict: raise InvalidBitcoinURI(f"failed to parse 'exp' field: {repr(e)}") from e if 'sig' in out: try: - out['sig'] = bh2u(bitcoin.base_decode(out['sig'], base=58)) + out['sig'] = bitcoin.base_decode(out['sig'], base=58).hex() except Exception as e: raise InvalidBitcoinURI(f"failed to parse 'sig' field: {repr(e)}") from e