From ea7cb6f6f3d7d36549d87c18dc2ef90f820e7ab9 Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Fri, 23 May 2025 15:35:22 +0000 Subject: [PATCH] tw.ctl: add `use_cached_balances` attr --- mmgen/proto/eth/tw/view.py | 2 +- mmgen/tw/ctl.py | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/mmgen/proto/eth/tw/view.py b/mmgen/proto/eth/tw/view.py index 1ffec02e..093e0694 100755 --- a/mmgen/proto/eth/tw/view.py +++ b/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!') diff --git a/mmgen/tw/ctl.py b/mmgen/tw/ctl.py index d9330785..2e9ad39a 100755 --- a/mmgen/tw/ctl.py +++ b/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'])