Skip to content

Commit

Permalink
Bug fix when calling set_data_from_mempoolspace from timer (#72)
Browse files Browse the repository at this point in the history
  • Loading branch information
andreasgriffin authored Jan 25, 2025
1 parent ae86997 commit 51d0b3f
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 22 deletions.
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.2"
__version__ = "1.0.3"
31 changes: 25 additions & 6 deletions bitcoin_safe/gui/qt/block_buttons.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

import enum
import logging
from typing import Callable, List
from typing import Callable, Dict, List
from urllib.parse import urlparse

import bdkpython as bdk
Expand All @@ -44,6 +44,7 @@
)

from bitcoin_safe.config import MIN_RELAY_FEE, UserConfig
from bitcoin_safe.network_config import ProxyInfo
from bitcoin_safe.util import block_explorer_URL_of_projected_block, unit_fee_str

from ...html_utils import html_f
Expand Down Expand Up @@ -300,18 +301,22 @@ def set_active(self, index: int, exclusive=True):


class ObjectRequiringMempool(QObject):
def __init__(self, mempool_data: MempoolData, parent=None) -> None:
def __init__(self, proxies: Dict | None, mempool_data: MempoolData, parent=None) -> None:
super().__init__(parent=parent)
self.proxies = proxies

self.mempool_data = mempool_data

self.timer = QTimer()
self.timer.timeout.connect(self.mempool_data.set_data_from_mempoolspace)
self.timer.timeout.connect(self.set_data_from_mempoolspace)
self.timer.start(10 * 60 * 1000) # 10 minutes in milliseconds

def set_mempool_block_unknown_fee_rate(self, i, confirmation_time: bdk.BlockTime | None = None) -> None:
logger.error("This should not be called")

def set_data_from_mempoolspace(self):
self.mempool_data.set_data_from_mempoolspace(proxies=self.proxies)


class BaseBlock(QObject):
signal_click: TypedPyQtSignal[float] = pyqtSignal(float) # type: ignore
Expand Down Expand Up @@ -346,15 +351,20 @@ class MempoolButtons(BaseBlock, ObjectRequiringMempool):
"Showing multiple buttons of the next, the 2. and the 3. block templates according to the mempool"

def __init__(
self, mempool_data: MempoolData, fee_rate: float = 1, max_button_count=3, parent=None
self,
mempool_data: MempoolData,
proxies: Dict | None,
fee_rate: float = 1,
max_button_count=3,
parent=None,
) -> None:
button_group = VerticalButtonGroup(
network=mempool_data.network_config.network, button_count=max_button_count, parent=parent
)
BaseBlock.__init__(
self, mempool_data=mempool_data, button_group=button_group, confirmation_time=None, parent=parent
)
ObjectRequiringMempool.__init__(self, mempool_data=mempool_data, parent=parent)
ObjectRequiringMempool.__init__(self, proxies=proxies, mempool_data=mempool_data, parent=parent)
self.fee_rate = fee_rate

self.refresh()
Expand Down Expand Up @@ -411,7 +421,16 @@ def __init__(
BaseBlock.__init__(
self, mempool_data=mempool_data, button_group=button_group, confirmation_time=None, parent=parent
)
ObjectRequiringMempool.__init__(self, mempool_data=mempool_data, parent=parent)
ObjectRequiringMempool.__init__(
self,
proxies=(
ProxyInfo.parse(config.network_config.proxy_url).get_requests_proxy_dict()
if config.network_config.proxy_url
else None
),
mempool_data=mempool_data,
parent=parent,
)

self.config = config
self.fee_rate = fee_rate
Expand Down
12 changes: 10 additions & 2 deletions bitcoin_safe/gui/qt/fee_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
from bitcoin_safe.gui.qt.notification_bar import NotificationBar
from bitcoin_safe.gui.qt.util import icon_path
from bitcoin_safe.html_utils import html_f, link
from bitcoin_safe.network_config import ProxyInfo
from bitcoin_safe.psbt_util import FeeInfo
from bitcoin_safe.typestubs import TypedPyQtSignal

Expand Down Expand Up @@ -137,10 +138,17 @@ def __init__(
fee_rate=fee_rate,
)
self._mempool_projected_block = MempoolProjectedBlock(
mempool_data, config=self.config, fee_rate=fee_rate
mempool_data=mempool_data, config=self.config, fee_rate=fee_rate
)
self._mempool_buttons = MempoolButtons(
fee_rate=fee_rate, mempool_data=mempool_data, max_button_count=5
fee_rate=fee_rate,
mempool_data=mempool_data,
max_button_count=5,
proxies=(
ProxyInfo.parse(config.network_config.proxy_url).get_requests_proxy_dict()
if config.network_config.proxy_url
else None
),
)

self._all_mempool_buttons: List[BaseBlock] = [
Expand Down
6 changes: 3 additions & 3 deletions bitcoin_safe/gui/qt/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def __init__(
self.fx = FX(
threading_parent=self.threading_manager,
proxies=(
ProxyInfo.parse(self.config.network_config.proxy_url).get_requests_proxy_dist()
ProxyInfo.parse(self.config.network_config.proxy_url).get_requests_proxy_dict()
if self.config.network_config.proxy_url
else None
),
Expand All @@ -158,7 +158,7 @@ def __init__(
)
self.mempool_data.set_data_from_mempoolspace(
proxies=(
ProxyInfo.parse(self.config.network_config.proxy_url).get_requests_proxy_dist()
ProxyInfo.parse(self.config.network_config.proxy_url).get_requests_proxy_dict()
if self.config.network_config.proxy_url
else None
)
Expand Down Expand Up @@ -304,7 +304,7 @@ def setupUi(self) -> None:
signals_min=self.signals,
threading_parent=self.threading_manager,
proxies=(
ProxyInfo.parse(self.config.network_config.proxy_url).get_requests_proxy_dist()
ProxyInfo.parse(self.config.network_config.proxy_url).get_requests_proxy_dict()
if self.config.network_config.proxy_url
else None
),
Expand Down
4 changes: 2 additions & 2 deletions bitcoin_safe/gui/qt/network_settings/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def test_connection(network_config: NetworkConfig) -> Optional[str]:
f"{network_config.esplora_url}/blocks/tip/height",
timeout=2,
proxies=(
ProxyInfo.parse(network_config.proxy_url).get_requests_proxy_dist()
ProxyInfo.parse(network_config.proxy_url).get_requests_proxy_dict()
if network_config.proxy_url
else None
),
Expand Down Expand Up @@ -473,7 +473,7 @@ def _test_connection(self, network_config: NetworkConfig) -> Tuple[str | None, b
mempool_server = test_mempool_space_server(
url=network_config.mempool_url,
proxies=(
ProxyInfo.parse(network_config.proxy_url).get_requests_proxy_dist()
ProxyInfo.parse(network_config.proxy_url).get_requests_proxy_dict()
if network_config.proxy_url
else None
),
Expand Down
20 changes: 15 additions & 5 deletions bitcoin_safe/gui/qt/ui_tx.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
from bitcoin_safe.html_utils import html_f
from bitcoin_safe.keystore import KeyStore
from bitcoin_safe.labels import LabelType
from bitcoin_safe.network_config import ProxyInfo
from bitcoin_safe.threading_manager import TaskThread, ThreadingManager
from bitcoin_safe.typestubs import TypedPyQtSignal

Expand Down Expand Up @@ -1002,6 +1003,15 @@ def set_tab_focus(self, focus_ui_element: UiElements):

self.focus_ui_element = UiElements.none

def _get_height_from_mempool(self):
return self.mempool_data.fetch_block_tip_height(
proxies=(
ProxyInfo.parse(self.config.network_config.proxy_url).get_requests_proxy_dict()
if self.config.network_config.proxy_url
else None
)
)

def set_visibility(self, confirmation_time: bdk.BlockTime | None) -> None:
is_psbt = self.data.data_type == DataType.PSBT
self.export_widget_container.setVisible(not is_psbt)
Expand All @@ -1011,10 +1021,10 @@ def set_visibility(self, confirmation_time: bdk.BlockTime | None) -> None:
if not tx:
return
tx_status = TxStatus(
tx,
confirmation_time,
self.mempool_data.fetch_block_tip_height,
self.is_in_mempool(tx.txid()),
tx=tx,
confirmation_time=confirmation_time,
get_height=self._get_height_from_mempool,
is_in_mempool=self.is_in_mempool(tx.txid()),
)

show_send = bool(tx_status.can_do_initial_broadcast() and self.data.data_type == DataType.Tx)
Expand Down Expand Up @@ -1169,7 +1179,7 @@ def __init__(
self.recipients.signal_clicked_send_max_button.connect(self.on_signal_amount_changed)
self.recipients.add_recipient()

self.fee_group = FeeGroup(mempool_data, fx, self.config)
self.fee_group = FeeGroup(mempool_data=mempool_data, fx=fx, config=self.config)
self.widget_right_top_layout.addWidget(
self.fee_group.groupBox_Fee, alignment=Qt.AlignmentFlag.AlignHCenter
)
Expand Down
2 changes: 1 addition & 1 deletion bitcoin_safe/network_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def get_socks_scheme(self) -> Literal[1] | Literal[2]:
def get_url(self):
return f"{self.scheme}://{self.host}:{self.port}"

def get_requests_proxy_dist(self):
def get_requests_proxy_dict(self):
return {"http": self.get_url(), "https": self.get_url()}

@classmethod
Expand Down
2 changes: 1 addition & 1 deletion bitcoin_safe/wallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def __init__(
self,
tx: bdk.Transaction | None,
confirmation_time: bdk.BlockTime | None,
get_height: Callable,
get_height: Callable[[], int],
is_in_mempool: bool,
confirmation_status: Optional[TxConfirmationStatus] = None,
) -> None:
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ line-length = 110
name = "bitcoin-safe"
# the version here and in all other places in this toml are updated automatically
# from the source: bitcoin_safe/__init__.py
version = "1.0.2"
version = "1.0.3"
description = "A bitcoin savings wallet for the entire family."
authors = [ "andreasgriffin <[email protected]>",]
license = "GPL-3.0"
Expand Down

0 comments on commit 51d0b3f

Please sign in to comment.