From 77d313e2e7a394add575b35a08161f545d0781a5 Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Mon, 3 Jul 2023 12:42:50 +0000 Subject: [PATCH] proto.btc.rpc: add `tracking_wallet_exists` property --- mmgen/proto/btc/daemon.py | 1 - mmgen/proto/btc/rpc.py | 9 ++++++++- mmgen/proto/btc/tw/json.py | 2 +- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/mmgen/proto/btc/daemon.py b/mmgen/proto/btc/daemon.py index abd21c94..6b31b4b8 100755 --- a/mmgen/proto/btc/daemon.py +++ b/mmgen/proto/btc/daemon.py @@ -24,7 +24,6 @@ class bitcoin_core_daemon(CoinDaemon): cli_fn = 'bitcoin-cli' testnet_dir = 'testnet3' cfg_file_hdr = '# Bitcoin Core config file\n' - tracking_wallet_name = 'mmgen-tracking-wallet' rpc_ports = _nw(8332, 18332, 18443) cfg_file = 'bitcoin.conf' nonstd_datadir = False diff --git a/mmgen/proto/btc/rpc.py b/mmgen/proto/btc/rpc.py index 4b234f34..749c1b31 100755 --- a/mmgen/proto/btc/rpc.py +++ b/mmgen/proto/btc/rpc.py @@ -101,6 +101,7 @@ class BitcoinRPCClient(RPCClient,metaclass=AsyncInit): auth_type = 'basic' has_auth_cookie = True wallet_path = '/' + twname = 'mmgen-tracking-wallet' async def __init__( self, @@ -216,6 +217,12 @@ class BitcoinRPCClient(RPCClient,metaclass=AsyncInit): def make_host_path(self,wallet): return f'/wallet/{wallet}' if wallet else self.wallet_path + @property + async def tracking_wallet_exists(self): + twname = self.cfg.regtest_user or self.twname + wnames = [i['name'] for i in (await self.call('listwalletdir'))['wallets']] + return twname in wnames + async def check_or_create_daemon_wallet(self,called=[],wallet_create=True): """ Returns True if the correct tracking wallet is currently loaded or if a new one @@ -225,7 +232,7 @@ class BitcoinRPCClient(RPCClient,metaclass=AsyncInit): if called or (self.chain == 'regtest' and self.cfg.regtest_user != 'carol'): return False - twname = self.daemon.tracking_wallet_name + twname = self.twname loaded_wnames = await self.call('listwallets') wnames = [i['name'] for i in (await self.call('listwalletdir'))['wallets']] m = f'Please fix your {self.daemon.desc} wallet installation or cmdline options' diff --git a/mmgen/proto/btc/tw/json.py b/mmgen/proto/btc/tw/json.py index 37b2f568..96a5c546 100755 --- a/mmgen/proto/btc/tw/json.py +++ b/mmgen/proto/btc/tw/json.py @@ -50,7 +50,7 @@ class BitcoinTwJSON(TwJSON): @property async def tracking_wallet_exists(self): - return await self.twctl.rpc.check_or_create_daemon_wallet(wallet_create=False) + return await self.twctl.rpc.tracking_wallet_exists async def create_tracking_wallet(self): return await self.twctl.rpc.check_or_create_daemon_wallet(wallet_create=True)