Browse Source

tw.ctl: add `use_cached_balances` attr

The MMGen Project 6 months ago
parent
commit
ea7cb6f6f3
2 changed files with 6 additions and 2 deletions
  1. 1 1
      mmgen/proto/eth/tw/view.py
  2. 5 1
      mmgen/tw/ctl.py

+ 1 - 1
mmgen/proto/eth/tw/view.py

@@ -33,6 +33,6 @@ class EthereumTwView(TwView):
 	def gen_subheader(self, cw, color):
 		if self.disp_prec == 8:
 			yield 'Balances truncated to 8 decimal points'
-		if self.cfg.cached_balances:
+		if self.twctl.use_cached_balances:
 			from ....color import nocolor, yellow
 			yield (nocolor, yellow)[color]('WARNING: Using cached balances. These may be out of date!')

+ 5 - 1
mmgen/tw/ctl.py

@@ -54,6 +54,7 @@ class TwCtl(MMGenObject, metaclass=AsyncInit):
 	aggressive_sync = False
 	importing = False
 	tw_fn = 'tracking-wallet.json'
+	use_cached_balances = False
 
 	def __new__(cls, cfg, proto, *args, **kwargs):
 		return MMGenObject.__new__(
@@ -81,6 +82,9 @@ class TwCtl(MMGenObject, metaclass=AsyncInit):
 		self.desc = self.base_desc = f'{self.proto.name} tracking wallet'
 		self.cur_balances = {} # cache balances to prevent repeated lookups per program invocation
 
+		if cfg.cached_balances:
+			self.use_cached_balances = True
+
 		if not no_rpc:
 			self.rpc = await rpc_init(cfg, proto, ignore_wallet=rpc_ignore_wallet)
 
@@ -182,7 +186,7 @@ class TwCtl(MMGenObject, metaclass=AsyncInit):
 	def get_cached_balance(self, addr, session_cache, data_root):
 		if addr in session_cache:
 			return self.proto.coin_amt(session_cache[addr])
-		if not self.cfg.cached_balances:
+		if not self.use_cached_balances:
 			return None
 		if addr in data_root and 'balance' in data_root[addr]:
 			return self.proto.coin_amt(data_root[addr]['balance'])