From 005e4df53858c4a549c2f1747d06bf0c51ad0592 Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Tue, 18 Apr 2023 18:35:58 +0000 Subject: [PATCH] mmgen-xmrwallet: support `current` param to --restore-height --- mmgen/main_xmrwallet.py | 4 +++- mmgen/xmrwallet.py | 39 +++++++++++++++++++++++++++------------ 2 files changed, 30 insertions(+), 13 deletions(-) diff --git a/mmgen/main_xmrwallet.py b/mmgen/main_xmrwallet.py index e6cbd223..29c314f0 100755 --- a/mmgen/main_xmrwallet.py +++ b/mmgen/main_xmrwallet.py @@ -60,7 +60,9 @@ opts_data = { -k, --use-internal-keccak-module Force use of the internal keccak module -p, --hash-preset=P Use scrypt hash preset 'P' for password hashing (default: '{gc.dfl_hash_preset}') --r, --restore-height=H Scan from height 'H' when creating wallets +-r, --restore-height=H Scan from height 'H' when creating wallets. + Use special value ‘current’ to create empty + wallet at current blockchain height. -R, --no-relay Save transaction to file instead of relaying -s, --no-start-wallet-daemon Don’t start the wallet daemon at startup -S, --no-stop-wallet-daemon Don’t stop the wallet daemon at exit diff --git a/mmgen/xmrwallet.py b/mmgen/xmrwallet.py index b95b1bc1..819658a7 100755 --- a/mmgen/xmrwallet.py +++ b/mmgen/xmrwallet.py @@ -468,6 +468,9 @@ class MoneroWalletOps: daemon_addr = self.cfg.daemon or None, ) + if self.name == 'create' and self.cfg.restore_height is None: + self.wd.usr_daemon_args = ['--offline'] + self.c = MoneroWalletRPCClient( cfg = self.cfg, daemon = self.wd, @@ -477,6 +480,20 @@ class MoneroWalletOps: if not self.cfg.no_start_wallet_daemon: async_run(self.c.restart_daemon()) + def get_coin_daemon_rpc(self): + + host,port = self.cfg.daemon.split(':') if self.cfg.daemon else ('localhost',self.wd.daemon_port) + + from .daemon import CoinDaemon + return MoneroRPCClient( + cfg = self.cfg, + proto = self.proto, + daemon = CoinDaemon( self.cfg, 'xmr' ), + host = host, + port = int(port), + user = None, + passwd = None ) + def create_addr_data(self): if uarg.wallets: idxs = AddrIdxList(uarg.wallets) @@ -713,19 +730,25 @@ class MoneroWalletOps: opts = ('restore_height',) def check_uopts(self): - if int(self.cfg.restore_height or 0) < 0: - die(1,f'{self.cfg.restore_height}: invalid value for --restore-height (less than zero)') + if self.cfg.restore_height != 'current': + if int(self.cfg.restore_height or 0) < 0: + die(1,f'{self.cfg.restore_height}: invalid value for --restore-height (less than zero)') async def process_wallet(self,d,fn,last): msg_r('') # for pexpect + if self.cfg.restore_height == 'current': + restore_height = self.get_coin_daemon_rpc().call_raw('get_height')['height'] + else: + restore_height = self.cfg.restore_height + from .xmrseed import xmrseed ret = self.c.call( 'restore_deterministic_wallet', filename = os.path.basename(fn), password = d.wallet_passwd, seed = xmrseed().fromhex(d.sec.wif,tostr=True), - restore_height = self.cfg.restore_height, + restore_height = restore_height, language = 'English' ) pp_msg(ret) if self.cfg.debug else msg(' Address: {}'.format( ret['address'] )) @@ -740,15 +763,7 @@ class MoneroWalletOps: host,port = self.cfg.daemon.split(':') if self.cfg.daemon else ('localhost',self.wd.daemon_port) - from .daemon import CoinDaemon - self.dc = MoneroRPCClient( - cfg = self.cfg, - proto = self.proto, - daemon = CoinDaemon( self.cfg, 'xmr' ), - host = host, - port = int(port), - user = None, - passwd = None ) + self.dc = self.get_coin_daemon_rpc() self.accts_data = {}