Browse Source

proto.btc.rpc: add `tracking_wallet_exists` property

The MMGen Project 1 year ago
parent
commit
77d313e2e7
3 changed files with 9 additions and 3 deletions
  1. 0 1
      mmgen/proto/btc/daemon.py
  2. 8 1
      mmgen/proto/btc/rpc.py
  3. 1 1
      mmgen/proto/btc/tw/json.py

+ 0 - 1
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

+ 8 - 1
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'

+ 1 - 1
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)