From e17eada7b874ebf683b06fa8567d717ef21add20 Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Sun, 15 Nov 2026 10:56:44 +0000 Subject: [PATCH] xmrwallet.ops.OpBase: new `get_coin_daemon_rpc()` method --- mmgen/xmrwallet/ops/__init__.py | 26 ++++++++++++++++++++++++++ mmgen/xmrwallet/ops/create.py | 2 +- mmgen/xmrwallet/ops/daemon.py | 25 +------------------------ mmgen/xmrwallet/ops/sync.py | 2 +- mmgen/xmrwallet/ops/wallet.py | 18 +----------------- 5 files changed, 30 insertions(+), 43 deletions(-) diff --git a/mmgen/xmrwallet/ops/__init__.py b/mmgen/xmrwallet/ops/__init__.py index d3e4b9c8..ac61419e 100644 --- a/mmgen/xmrwallet/ops/__init__.py +++ b/mmgen/xmrwallet/ops/__init__.py @@ -105,6 +105,32 @@ class OpBase: self.cfg.tx_relay_daemon, re.ASCII) + def get_coin_daemon_rpc(self, test_connection=None): + + from ...daemon import CoinDaemon + from ...proto.xmr.rpc import MoneroRPCClient + + if self.cfg.tx_relay_daemon: + m = self.parse_tx_relay_opt() + host, port = m[1].split(':') + proxy = m[2] + else: + host, port = self.cfg.daemon.split(':') if self.cfg.daemon else (None, None) + proxy = None + + md = CoinDaemon(self.cfg, proto=self.proto, test_user=self.cfg.test_user) + return MoneroRPCClient( + cfg = self.cfg, + proto = self.proto, + host = host or 'localhost', + port = port or md.rpc_port, + user = None, + passwd = None, + # avoid extra connections if relay is a public node: + test_connection = (host=='localhost') if test_connection is None else test_connection, + daemon = md, + proxy = proxy) + def get_tx_cls(self, clsname): from ..file.tx import MoneroMMGenTX return getattr(MoneroMMGenTX, clsname + ('Compat' if self.compat_call else '')) diff --git a/mmgen/xmrwallet/ops/create.py b/mmgen/xmrwallet/ops/create.py index 76749098..edde0d2a 100644 --- a/mmgen/xmrwallet/ops/create.py +++ b/mmgen/xmrwallet/ops/create.py @@ -29,7 +29,7 @@ class OpCreate(OpWallet): msg_r('') # for pexpect if self.cfg.restore_height == 'current': - restore_height = self.get_coin_daemon_rpc().call_raw('get_height')['height'] + restore_height = self.get_coin_daemon_rpc(test_connection=True).call_raw('get_height')['height'] else: restore_height = self.cfg.restore_height diff --git a/mmgen/xmrwallet/ops/daemon.py b/mmgen/xmrwallet/ops/daemon.py index ff072e97..162e3fe3 100644 --- a/mmgen/xmrwallet/ops/daemon.py +++ b/mmgen/xmrwallet/ops/daemon.py @@ -15,7 +15,6 @@ from pathlib import Path from ...util import msg, msg_r, gmsg, ymsg, die from ...ui import keypress_confirm -from ...proto.xmr.rpc import MoneroRPCClient from ..file.tx import MoneroMMGenTX @@ -30,29 +29,7 @@ class OpDaemon(OpBase): self.mount_removable_device() - if self.cfg.tx_relay_daemon: - m = self.parse_tx_relay_opt() - host, port = m[1].split(':') - proxy = m[2] - md = None - else: - from ...daemon import CoinDaemon - md = CoinDaemon(self.cfg, proto=self.cfg._proto) - host, port = ( - self.cfg.daemon.split(':') if self.cfg.daemon else - ('localhost', md.rpc_port)) - proxy = None - - self.dc = MoneroRPCClient( - cfg = self.cfg, - proto = self.proto, - daemon = md, - host = host, - port = int(port), - user = None, - passwd = None, - test_connection = host == 'localhost', # avoid extra connections if relay is a public node - proxy = proxy) + self.dc = self.get_coin_daemon_rpc() class OpRelay(OpDaemon): diff --git a/mmgen/xmrwallet/ops/sync.py b/mmgen/xmrwallet/ops/sync.py index 66b2d0f0..a73b7dd5 100644 --- a/mmgen/xmrwallet/ops/sync.py +++ b/mmgen/xmrwallet/ops/sync.py @@ -31,7 +31,7 @@ class OpSync(OpWallet): super().__init__(cfg, uarg_tuple) if not self.wallet_offline: - self.dc = self.get_coin_daemon_rpc() + self.dc = self.get_coin_daemon_rpc(test_connection=True) self.wallets_data = {} diff --git a/mmgen/xmrwallet/ops/wallet.py b/mmgen/xmrwallet/ops/wallet.py index cfc5d255..c8cc81aa 100644 --- a/mmgen/xmrwallet/ops/wallet.py +++ b/mmgen/xmrwallet/ops/wallet.py @@ -16,7 +16,7 @@ from ...color import orange, cyan from ...util import msg, gmsg, ymsg, die, suf from ...addr import MMGenID from ...addrlist import KeyAddrList, ViewKeyAddrList, AddrIdxList -from ...proto.xmr.rpc import MoneroRPCClient, MoneroWalletRPCClient +from ...proto.xmr.rpc import MoneroWalletRPCClient from ...proto.xmr.daemon import MoneroWalletDaemon from . import OpBase @@ -135,22 +135,6 @@ class OpWallet(OpBase): if self.cfg.skip_empty_addresses: msg(orange('Skipping display of empty used addresses where applicable')) - def get_coin_daemon_rpc(self): - - host, port = ( - self.cfg.daemon.split(':') if self.cfg.daemon else - ('localhost', self.wd.monerod_port)) - - from ...daemon import CoinDaemon - return MoneroRPCClient( - cfg = self.cfg, - proto = self.proto, - daemon = CoinDaemon(self.cfg, network_id='xmr'), - host = host, - port = int(port), - user = None, - passwd = None) - @property def autosign_viewkey_addr_file(self): from ...addrfile import ViewKeyAddrFile