xmrwallet.ops.OpBase: new get_coin_daemon_rpc() method

This commit is contained in:
The MMGen Project 2026-11-15 10:56:44 +00:00
commit e17eada7b8
Signed by: mmgen
GPG key ID: 3F8B1861E32B7DA2
5 changed files with 30 additions and 43 deletions

View file

@ -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 ''))

View file

@ -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

View file

@ -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):

View file

@ -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 = {}

View file

@ -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