Add tx getter, column selector in list

This commit is contained in:
nolash 2021-09-08 17:18:33 +02:00
parent b45f34488b
commit a675a2592f
Signed by: lash
GPG Key ID: 21D2E7BB88C2A746
3 changed files with 22 additions and 7 deletions

View File

@ -4,6 +4,7 @@
import os
import logging
import sys
import argparse
# external imports
from hexathon import add_0x
@ -15,6 +16,7 @@ from chainqueue.sql.backend import SQLBackend
from chaind.sql.session import SessionIndex
from chainqueue.adapters.sessionindex import SessionIndexAdapter
from chainqueue.cli import Outputter
from chainqueue.enum import StatusBits
logging.basicConfig(level=logging.WARNING)
@ -24,7 +26,12 @@ script_dir = os.path.dirname(os.path.realpath(__file__))
config_dir = os.path.join(script_dir, '..', 'data', 'config')
arg_flags = chainlib.cli.argflag_std_base | chainlib.cli.Flag.CHAIN_SPEC
argparser = chainlib.cli.ArgumentParser(arg_flags)
argparser = chainlib.cli.ArgumentParser(
arg_flags,
description="""Lists and queue items by session id, filterable by timestamp and state.
By default all columns will be displayed. Columns can be explicitly selected instead by passing one or more column names using the -o,--column flag. Valid column names are: chainspec, hash, statustext, statuscode.
""")
argparser.add_argument('--backend', type=str, default='sql', help='Backend to use (currently only "sql")')
argparser.add_argument('--start', type=str, help='Oldest transaction hash to include in results')
argparser.add_argument('--end', type=str, help='Newest transaction hash to include in results')
@ -33,6 +40,7 @@ argparser.add_argument('--pending', action='store_true', help='Omit finalized tr
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('--address', dest='address', type=str, help='filter by address')
argparser.add_argument('-o', '--column', dest='column', action='append', type=str, help='add a column to display')
argparser.add_positional('session_id', type=str, help='Ethereum address of recipient')
args = argparser.parse_args()
extra_args = {
@ -44,6 +52,7 @@ extra_args = {
'pending': None,
'status_mask': None,
'summary': None,
'column': None,
'session_id': 'SESSION_ID',
}
@ -82,10 +91,10 @@ dsn = dsn_from_config(config)
backend = SQLBackend(dsn, debug=config.true('DATABASE_DEBUG'))
session_index_backend = SessionIndex(config.get('SESSION_ID'))
adapter = SessionIndexAdapter(backend, session_index_backend=session_index_backend)
output_cols = config.get('_COLUMN')
def main():
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)
txs = session_index_backend.get(chain_spec, adapter)
if config.get('_SUMMARY'):
for k in txs.keys():

View File

@ -2,7 +2,10 @@
import datetime
# external imports
from hexathon import add_0x
from hexathon import (
add_0x,
strip_0x,
)
from chainqueue.adapters.base import Adapter
from chainqueue.enum import StatusBits
@ -14,7 +17,8 @@ class SessionIndexAdapter(Adapter):
self.session_index_backend = session_index_backend
def add(self, bytecode, chain_spec, session=None):
def add(self, tx_raw_signed_hex, chain_spec, session=None):
bytecode = bytes.fromhex(strip_0x(tx_raw_signed_hex))
tx = self.translate(bytecode, chain_spec)
r = self.backend.create(chain_spec, tx['nonce'], tx['from'], tx['hash'], add_0x(bytecode.hex()), session=session)
if r:
@ -38,4 +42,6 @@ class SessionIndexAdapter(Adapter):
return txs
def get(self, tx_hash, chain_spec, session=None):
tx_summary = self.backend.get_otx(chain_spec, tx_hash, session=session)
return tx_summary['signed_tx']

View File

@ -1,5 +1,5 @@
chainlib>=0.0.9a3,<=0.1.0
chainqueue>=0.0.5a1,<=0.0.5
chainqueue>=0.0.5a3,<=0.0.5
chainsyncer>=0.0.6a3,<=0.0.6
confini>=0.4.1a1,<0.5.0
crypto-dev-signer>=0.4.15a3,<0.5.0