From 3e859888787c60aaf0331e62cb630c688ba571b0 Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Mon, 26 May 2025 09:39:11 +0000 Subject: [PATCH] proto.*.tw.unspent: move methods and classes to parent class --- mmgen/proto/btc/tw/unspent.py | 24 +++++++++++------------ mmgen/proto/eth/tw/unspent.py | 29 --------------------------- mmgen/tw/unspent.py | 37 +++++++++++++++++++++++++++-------- 3 files changed, 40 insertions(+), 50 deletions(-) diff --git a/mmgen/proto/btc/tw/unspent.py b/mmgen/proto/btc/tw/unspent.py index 643e970c..5352b6c6 100755 --- a/mmgen/proto/btc/tw/unspent.py +++ b/mmgen/proto/btc/tw/unspent.py @@ -16,6 +16,14 @@ from ....tw.unspent import TwUnspentOutputs class BitcoinTwUnspentOutputs(TwUnspentOutputs): + class display_type(TwUnspentOutputs.display_type): + + class squeezed(TwUnspentOutputs.display_type.squeezed): + cols = ('num', 'txid', 'vout', 'addr', 'mmid', 'comment', 'amt', 'amt2', 'date') + + class detail(TwUnspentOutputs.display_type.detail): + cols = ('num', 'txid', 'vout', 'addr', 'mmid', 'amt', 'amt2', 'block', 'date_time', 'comment') + class MMGenTwUnspentOutput(TwUnspentOutputs.MMGenTwUnspentOutput): # required by gen_unspent(); setting valid_attrs explicitly is also more efficient valid_attrs = { @@ -47,21 +55,11 @@ class BitcoinTwUnspentOutputs(TwUnspentOutputs): prompt_fs_repl = { 'BCH': (1, 'Column options: toggle [D]ate/confs, cas[h]addr, gr[o]up, show [m]mgen addr') } - key_mappings = { - 't':'s_txid', - 'a':'s_amt', - 'd':'s_addr', - 'A':'s_age', - 'M':'s_twmmid', - 'r':'s_reverse', + extra_key_mappings = { 'D':'d_days', 'o':'d_group', - 'm':'d_mmid', - 'e':'d_redraw', - 'p':'a_print_detail', - 'v':'a_view', - 'w':'a_view_detail', - 'l':'i_comment_add'} + 't':'s_txid', + 'A':'s_age'} sort_funcs = { 'addr': lambda i: '{} {:010} {:024.12f}'.format(i.addr, 0xffffffff - abs(i.confs), i.amt), diff --git a/mmgen/proto/eth/tw/unspent.py b/mmgen/proto/eth/tw/unspent.py index 346772ad..97244abf 100755 --- a/mmgen/proto/eth/tw/unspent.py +++ b/mmgen/proto/eth/tw/unspent.py @@ -27,43 +27,14 @@ from .view import EthereumTwView # No unspent outputs with Ethereum, but naming must be consistent class EthereumTwUnspentOutputs(EthereumTwView, TwUnspentOutputs): - class display_type(TwUnspentOutputs.display_type): - - class squeezed(TwUnspentOutputs.display_type.squeezed): - cols = ('num', 'addr', 'mmid', 'comment', 'amt', 'amt2') - - class detail(TwUnspentOutputs.display_type.detail): - cols = ('num', 'addr', 'mmid', 'amt', 'amt2', 'comment') - class MMGenTwUnspentOutput(TwUnspentOutputs.MMGenTwUnspentOutput): valid_attrs = {'txid', 'vout', 'amt', 'amt2', 'comment', 'twmmid', 'addr', 'confs', 'skip'} invalid_attrs = {'proto'} - has_age = False - can_group = False hdr_lbl = 'tracked accounts' desc = 'account balances' item_desc = 'account' dump_fn_pfx = 'balances' - prompt_fs_in = [ - 'Sort options: [a]mount, a[d]dr, [M]mgen addr, [r]everse', - 'Display options: show [m]mgen addr, r[e]draw screen', - 'View/Print: pager [v]iew, [w]ide pager view, [p]rint to file{s}', - 'Actions: [q]uit menu, [D]elete addr, add [l]abel, [R]efresh balance:'] - key_mappings = { - 'a':'s_amt', - 'd':'s_addr', - 'r':'s_reverse', - 'M':'s_twmmid', - 'm':'d_mmid', - 'e':'d_redraw', - 'p':'a_print_detail', - 'v':'a_view', - 'w':'a_view_detail', - 'l':'i_comment_add', - 'D':'i_addr_delete', - 'R':'i_balance_refresh'} - no_data_errmsg = 'No accounts in tracking wallet!' def get_column_widths(self, data, *, wide, interactive): diff --git a/mmgen/tw/unspent.py b/mmgen/tw/unspent.py index cdca9236..2777b4e7 100755 --- a/mmgen/tw/unspent.py +++ b/mmgen/tw/unspent.py @@ -36,14 +36,8 @@ from .view import TwView class TwUnspentOutputs(TwView): - class display_type(TwView.display_type): - - class squeezed(TwView.display_type.squeezed): - cols = ('num', 'txid', 'vout', 'addr', 'mmid', 'comment', 'amt', 'amt2', 'date') - - class detail(TwView.display_type.detail): - cols = ('num', 'txid', 'vout', 'addr', 'mmid', 'amt', 'amt2', 'block', 'date_time', 'comment') - + has_age = False + can_group = False show_mmid = True no_rpcdata_errmsg = """ No spendable outputs found! Import addresses with balances into your @@ -52,6 +46,33 @@ class TwUnspentOutputs(TwView): update_widths_on_age_toggle = False print_output_types = ('detail',) mod_subpath = 'tw.unspent' + prompt_fs_in = [ + 'Sort options: [a]mount, a[d]dr, [M]mgen addr, [r]everse', + 'Display options: show [m]mgen addr, r[e]draw screen', + 'View/Print: pager [v]iew, [w]ide pager view, [p]rint to file{s}', + 'Actions: [q]uit menu, [D]elete addr, add [l]abel, [R]efresh balance:'] + key_mappings = { + 'a':'s_amt', + 'd':'s_addr', + 'r':'s_reverse', + 'M':'s_twmmid', + 'm':'d_mmid', + 'e':'d_redraw', + 'p':'a_print_detail', + 'v':'a_view', + 'w':'a_view_detail', + 'l':'i_comment_add'} + extra_key_mappings = { + 'D':'i_addr_delete', + 'R':'i_balance_refresh'} + + class display_type(TwView.display_type): + + class squeezed(TwView.display_type.squeezed): + cols = ('num', 'addr', 'mmid', 'comment', 'amt', 'amt2') + + class detail(TwView.display_type.detail): + cols = ('num', 'addr', 'mmid', 'amt', 'amt2', 'comment') class MMGenTwUnspentOutput(MMGenListItem): txid = ListItemAttr(CoinTxID)