xmrwallet.ops.wallet, mmgen-addrimport: cleanups

This commit is contained in:
The MMGen Project 2026-02-06 10:14:20 +00:00
commit cf5f7204c7
Signed by: mmgen
GPG key ID: 3F8B1861E32B7DA2
3 changed files with 18 additions and 17 deletions

View file

@ -33,7 +33,7 @@ opts_data = {
'options': """
-h, --help Print this help message
--, --longhelp Print help message for long (global) options
-a, --address=a Import the single coin address 'a'
-A, --address=ADDR Import the single coin address ADDR
-b, --batch Import all addresses in one RPC call
-l, --addrlist Address source is a flat list of non-MMGen coin addresses
-k, --keyaddr-file Address source is a key-address file
@ -42,7 +42,7 @@ opts_data = {
blockchain for unspent outputs that include the imported
address(es). Required if any of the imported addresses
are already in the blockchain and have a balance.
-t, --token-addr=A Import addresses for ERC20 token with address 'A'
-t, --token-addr=ADDR Import addresses for ERC20 token with address ADDR
""",
'notes': """
@ -131,8 +131,8 @@ def check_opts(twctl):
return batch, rescan
async def main():
from .tw.ctl import TwCtl
from .tw.ctl import TwCtl
twctl = await TwCtl(
cfg = cfg,
proto = proto,

View file

@ -21,7 +21,6 @@ from .wallet import OpWallet
class OpCreate(OpWallet):
stem = 'creat'
wallet_exists = False
opts = ('restore_height',)
def check_uopts(self):

View file

@ -34,32 +34,25 @@ class OpWallet(OpBase):
'autosign',
'watch_only')
wallet_offline = False
wallet_exists = True
start_daemon = True
skip_wallet_check = False # for debugging
def __init__(self, cfg, uarg_tuple):
def wallet_exists(fn):
try:
fn.stat()
except:
return False
else:
return True
def check_wallets():
for d in self.addr_data:
fn = self.get_wallet_fn(d)
match wallet_exists(fn):
case True if not self.wallet_exists:
match self.stat_wallet(fn):
case True if self.is_create:
die(1, f'Wallet ‘{fn}’ already exists!')
case False if self.wallet_exists:
case False:
die(1, f'Wallet ‘{fn}’ not found!')
super().__init__(cfg, uarg_tuple)
if self.cfg.offline or (self.name == 'create' and self.cfg.restore_height is None):
self.is_create = self.name in ('create', 'create_offline', 'restore')
if self.cfg.offline or (self.is_create and self.cfg.restore_height is None):
self.wallet_offline = True
self.wd = MoneroWalletDaemon(
@ -122,6 +115,15 @@ class OpWallet(OpBase):
if self.start_daemon and not self.cfg.no_start_wallet_daemon:
asyncio.run(self.restart_wallet_daemon())
@staticmethod
def stat_wallet(fn):
try:
fn.stat()
except:
return False
else:
return True
@classmethod
def get_idx_from_fn(cls, fn):
return int(re.match(r'[0-9a-fA-F]{8}-(\d+)-Monero(WatchOnly)?Wallet.*', fn.name)[1])