Add columns selector to list cli

This commit is contained in:
nolash 2021-09-09 08:38:14 +02:00
parent 5302b1f4f5
commit 273a10b169
Signed by: lash
GPG Key ID: 21D2E7BB88C2A746
3 changed files with 17 additions and 5 deletions

View File

@ -22,6 +22,7 @@ class OutputCol(enum.Enum):
hash = 1
statustext = 2
statuscode = 3
signedtx = 4
class Outputter:
@ -40,6 +41,13 @@ class Outputter:
"""
all_cols = [
OutputCol.chainspec,
OutputCol.hash,
OutputCol.signedtx,
OutputCol.statustext,
OutputCol.statuscode,
]
default_cols = [
OutputCol.chainspec,
OutputCol.hash,
OutputCol.statustext,
@ -64,7 +72,7 @@ class Outputter:
debug_col_name = []
if cols == None:
self.cols = Outputter.all_cols
self.cols = Outputter.default_cols
else:
self.cols = []
for col in cols:
@ -125,12 +133,13 @@ class Outputter:
status = tx['status']
if self.decode_status:
status = status_str(tx['status_code'], bits_only=True)
#self.writer.write('{}\t{}\t{}\t{}\n'.format(self.chain_spec_str, add_0x(tx_hash), status, tx['status_code']))
vals = [
self.chain_spec_str,
add_0x(tx_hash),
status,
str(tx['status_code']),
add_0x(tx['signed_tx']),
]
i = 0
@ -142,4 +151,3 @@ class Outputter:
self.writer.write('\n')
else:
self.writer.write('\t')
#self.writer.write('{}\t{}\t{}\t{}\n'.format()

View File

@ -30,6 +30,7 @@ argparser.add_argument('--error', action='store_true', help='Only show transacti
argparser.add_argument('--pending', action='store_true', help='Omit finalized transactions')
argparser.add_argument('--status-mask', type=int, dest='status_mask', help='Manually specify status bitmask value to match (overrides --error and --pending)')
argparser.add_argument('--summary', action='store_true', help='output summary for each status category')
argparser.add_argument('-o', '--column', dest='column', action='append', type=str, help='add a column to display')
argparser.add_positional('address', type=str, help='Ethereum address of recipient')
args = argparser.parse_args()
extra_args = {
@ -40,6 +41,7 @@ extra_args = {
'error': None,
'pending': None,
'status_mask': None,
'column': None,
'summary': None,
}
config = chainlib.cli.Config.from_args(args, arg_flags, extra_args=extra_args, base_config_dir=config_dir)
@ -67,6 +69,8 @@ if config.get('_BACKEND') == 'sql':
else:
raise NotImplementedError('backend {} not implemented'.format(config.get('_BACKEND')))
output_cols = config.get('_COLUMN')
def main():
since = config.get('_START', None)
@ -76,7 +80,7 @@ def main():
if until != None:
until = add_0x(until)
txs = tx_lister(chain_spec, config.get('_ADDRESS'), since=since, until=until, status=status_mask, not_status=not_status_mask)
outputter = Outputter(chain_spec, sys.stdout, tx_getter, session_method=session_method, decode_status=config.true('_RAW'))
outputter = Outputter(chain_spec, sys.stdout, tx_getter, session_method=session_method, decode_status=config.true('_RAW'), cols=output_cols)
if config.get('_SUMMARY'):
for k in txs.keys():
outputter.add(k)

View File

@ -5,4 +5,4 @@ alembic==1.4.2
SQLAlchemy==1.3.20
confini>=0.4.1a1,<0.5.0
pyxdg~=0.27
chainlib~=0.0.9a5
chainlib~=0.0.9a7