Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor #74

Merged
merged 3 commits into from
Feb 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ screenshots*/
profile.html

docs/org

tests/output


# build results
Expand All @@ -220,4 +220,6 @@ bitcoin_safe
*.so.1
version
tools/libusb/
*.dll
*.dll


2 changes: 1 addition & 1 deletion bitcoin_safe/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# this is the source of the version information
__version__ = "1.0.4"
__version__ = "1.0.5"
12 changes: 7 additions & 5 deletions bitcoin_safe/__main__.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import argparse
import sys

# all import must be absolute, because this is the entry script for pyinstaller
from bitcoin_safe.dynamic_lib_load import ensure_pyzbar_works
from bitcoin_safe.logging_setup import setup_logging

setup_logging()
from bitcoin_safe.dynamic_lib_load import setup_libsecp256k1

# setup the logging
from bitcoin_safe.logging_setup import setup_logging # type: ignore
setup_libsecp256k1()
from bitcoin_safe.dynamic_lib_load import ensure_pyzbar_works

ensure_pyzbar_works()

import argparse
import sys

from PyQt6.QtWidgets import QApplication

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,36 +26,18 @@
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

import enum
from dataclasses import dataclass

import logging
from typing import Callable, List, Tuple

from PyQt6.QtCore import QObject, pyqtBoundSignal
class SubtextType(enum.Enum):
hide = enum.auto()
click_new_address = enum.auto()
balance = enum.auto()

from bitcoin_safe.typestubs import TypedPyQtSignal, TypedPyQtSignalNo

from ...signals import SignalFunction

logger = logging.getLogger(__name__)


class SignalCarryingObject(QObject):
def __init__(self, parent=None, **kwargs) -> None:
super().__init__(parent, **kwargs)
self._connected_signals: List[
Tuple[SignalFunction | pyqtBoundSignal | TypedPyQtSignalNo | TypedPyQtSignal, Callable]
] = []

def connect_signal(
self,
signal: SignalFunction | pyqtBoundSignal | TypedPyQtSignalNo | TypedPyQtSignal,
f: Callable,
**kwargs
) -> None:
signal.connect(f, **kwargs)
self._connected_signals.append((signal, f))

def disconnect_signals(self) -> None:
while self._connected_signals:
signal, f = self._connected_signals.pop()
signal.disconnect(f)
@dataclass
class CategoryInfo:
category: str
text_click_new_address: str = ""
text_balance: str = ""
15 changes: 6 additions & 9 deletions bitcoin_safe/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,26 +28,23 @@


import logging
import os
from pathlib import Path
from typing import Any, Dict, List, Optional

import appdirs
import bdkpython as bdk
from packaging import version

from bitcoin_safe.gui.qt.unique_deque import UniqueDeque

from .execute_config import DEFAULT_MAINNET

logger = logging.getLogger(__name__)

import os
from typing import Any, Dict, List, Optional

import appdirs
import bdkpython as bdk

from .network_config import NetworkConfig, NetworkConfigs
from .storage import BaseSaveableClass
from .util import current_project_dir, path_to_rel_home_path, rel_home_path_to_abs_path

logger = logging.getLogger(__name__)

MIN_RELAY_FEE = 1
FEE_RATIO_HIGH_WARNING = 0.05 # warn user if fee/amount for on-chain tx is higher than this
NO_FEE_WARNING_BELOW = 10 # sat/vB
Expand Down
13 changes: 6 additions & 7 deletions bitcoin_safe/descriptor_export_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,21 @@


import logging

from bitcoin_safe.gui.qt.util import save_file_dialog
from bitcoin_safe.hardware_signers import DescriptorExportType, DescriptorExportTypes
from bitcoin_safe.wallet import filename_clean

logger = logging.getLogger(__name__)

from typing import Optional

import bdkpython as bdk
from bitcoin_qr_tools.data import ConverterMultisigWalletExport
from bitcoin_qr_tools.signer_info import SignerInfo
from bitcoin_usb.address_types import DescriptorInfo

from bitcoin_safe.gui.qt.util import save_file_dialog
from bitcoin_safe.hardware_signers import DescriptorExportType, DescriptorExportTypes
from bitcoin_safe.wallet import filename_clean

from .descriptors import MultipathDescriptor

logger = logging.getLogger(__name__)


class DescriptorExportTools:

Expand Down
5 changes: 2 additions & 3 deletions bitcoin_safe/descriptors.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@


import logging

logger = logging.getLogger(__name__)

from typing import Sequence

import bdkpython as bdk
Expand All @@ -45,6 +42,8 @@
SimplePubKeyProvider,
)

logger = logging.getLogger(__name__)


def get_default_address_type(is_multisig) -> AddressType:
return AddressTypes.p2wsh if is_multisig else AddressTypes.p2wpkh
Expand Down
18 changes: 13 additions & 5 deletions bitcoin_safe/dynamic_lib_load.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def setup_libsecp256k1() -> None:
bitcoin_usb.set_custom_secp256k1_path(lib_path)
bitcointx.set_custom_secp256k1_path(lib_path)
elif get_libsecp256k1_os_path():
logger.info(f"libsecp256k1 was found in the OS")
logger.info(translate("setup_libsecp256k1", f"libsecp256k1 was found in the OS"))
else:
msg = translate(
"dynamic_lib_load", "libsecp256k1 could not be found. Please install libsecp256k1 in your OS."
Expand All @@ -135,14 +135,22 @@ def ensure_pyzbar_works() -> None:
# Get the platform-specific path to the binary library
logger.info(f"Platform: {platform.system()}")
if platform.system() == "Windows":
logger.info("Trying to import pyzbar to see if Visual C++ Redistributable is installed. ")
logger.info(
translate(
"ensure_pyzbar_works",
"Trying to import pyzbar to see if Visual C++ Redistributable is installed. ",
)
)
try:
from pyzbar import pyzbar

pyzbar.__name__
logger.info(f"pyzbar successfully loaded ")
except: # Do not restrict it to FileNotFoundError, because it can cause other exceptions
logger.info(f"pyzbar not loaded ")
logger.info(translate("ensure_pyzbar_works", f"pyzbar successfully loaded "))
except (
Exception
) as e: # Do not restrict it to FileNotFoundError, because it can cause other exceptions
logger.debug(str(e))
logger.info(translate("ensure_pyzbar_works", f"pyzbar not loaded "))
show_warning_before_failiure(
translate("lib_load", """You are missing the {link}\nPlease install it.""").format(
link=link(
Expand Down
7 changes: 6 additions & 1 deletion bitcoin_safe/execute_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,10 @@
# SOFTWARE.


DEFAULT_MAINNET = True
IS_PRODUCTION = True # change this for testing

DEFAULT_MAINNET = IS_PRODUCTION
ENABLE_THREADING = True
ENABLE_TIMERS = True
DEFAULT_LANG_CODE = "en_US"
MEMPOOL_SCHEDULE_TIMER = 10 * 60 * 1000 if IS_PRODUCTION else 1 * 60 * 1000
10 changes: 5 additions & 5 deletions bitcoin_safe/fx.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@
import logging
from typing import Dict

from bitcoin_safe.threading_manager import ThreadingManager

logger = logging.getLogger(__name__)

from PyQt6.QtCore import QLocale, QObject, pyqtSignal

from bitcoin_safe.threading_manager import ThreadingManager

from .mempool import threaded_fetch
from .signals import TypedPyQtSignalNo

logger = logging.getLogger(__name__)


class FX(QObject, ThreadingManager):
signal_data_updated: TypedPyQtSignalNo = pyqtSignal() # type: ignore
Expand All @@ -48,7 +48,7 @@ def __init__(self, proxies: Dict | None, threading_parent: ThreadingManager | No
self.proxies = proxies
self.rates: Dict[str, Dict] = {}
self.update()
logger.debug(f"initialized {self}")
logger.debug(f"initialized {self.__class__.__name__}")

def update_if_needed(self) -> None:
if self.rates:
Expand Down
Binary file modified bitcoin_safe/gui/icons/distribute-multisigsig-export.svgz
Binary file not shown.
Binary file modified bitcoin_safe/gui/locales/app_ar_AE.qm
Binary file not shown.
Loading
Loading