chainqueue

Blockchain transaction queue control
Log | Files | Refs | LICENSE

commit 5302b1f4f5176e4b85eae1764bad8781c6baa380
parent a3e9a3ee00589c3f52049e0b7c27e7aca6f4420b
Author: nolash <dev@holbrook.no>
Date:   Wed,  8 Sep 2021 17:19:30 +0200

Add output column selector

Diffstat:
Mchainqueue/adapters/base.py | 13+++++++++++++
Mchainqueue/cli.py | 49+++++++++++++++++++++++++++++++++++++++++++++++--
Mchainqueue/encode.py | 49+------------------------------------------------
Mrequirements.txt | 2+-
Mrun_tests.sh | 2+-
Msetup.cfg | 2+-
6 files changed, 64 insertions(+), 53 deletions(-)

diff --git a/chainqueue/adapters/base.py b/chainqueue/adapters/base.py @@ -54,6 +54,19 @@ class Adapter: raise NotImplementedError() + def get(self, tx_hash, chain_spec, session=None): + """Retrieve serialized transaction represented by the given transaction hash. + + :param chain_spec: Chain spec to use for transaction decode + :type chain_spec: chainlib.chain.ChainSpec + :param tx_hash: Transaction hash, in hex + :type tx_hash: str + :param session: Backend state integrity session + :type session: varies + """ + raise NotImplementedError() + + def dispatch(self, chain_spec, rpc, tx_hash, signed_tx, session=None): """Send a queued transaction to the network. diff --git a/chainqueue/cli.py b/chainqueue/cli.py @@ -1,5 +1,6 @@ # standard imports import logging +import enum # external imports from hexathon import add_0x @@ -16,6 +17,13 @@ from chainqueue.enum import ( logg = logging.getLogger(__name__) +class OutputCol(enum.Enum): + chainspec = 0 + hash = 1 + statustext = 2 + statuscode = 3 + + class Outputter: """Output helper for chainqueue cli listings tools. @@ -31,7 +39,14 @@ class Outputter: :type decode_status: bool """ - def __init__(self, chain_spec, writer, getter, session_method=None, decode_status=True): + all_cols = [ + OutputCol.chainspec, + OutputCol.hash, + OutputCol.statustext, + OutputCol.statuscode, + ] + + def __init__(self, chain_spec, writer, getter, session_method=None, decode_status=True, cols=None): self.decode_status = decode_status self.writer = writer self.getter = getter @@ -47,6 +62,19 @@ class Outputter: 'final': 0, } + debug_col_name = [] + if cols == None: + self.cols = Outputter.all_cols + else: + self.cols = [] + for col in cols: + v = getattr(OutputCol, col) + self.cols.append(v) + + for col in self.cols: + debug_col_name.append(col.name) + logg.debug('outputter initialized with cols: {}'.format(','.join(debug_col_name))) + def __del__(self): if self.session != None: @@ -97,4 +125,21 @@ 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'])) + #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']), + ] + + i = 0 + l = len(self.cols) + for col in self.cols: + self.writer.write(vals[col.value]) + i += 1 + if i == l: + self.writer.write('\n') + else: + self.writer.write('\t') + #self.writer.write('{}\t{}\t{}\t{}\n'.format() diff --git a/chainqueue/encode.py b/chainqueue/encode.py @@ -1,49 +1,2 @@ -# standard imports -import logging - # external imports -from hexathon import ( - add_0x, - strip_0x, - uniform as hex_uniform, - ) - -logg = logging.getLogger() - - -class TxHexNormalizer: - - def tx_hash(self, tx_hash): - return self.__hex_normalize(tx_hash, 'tx hash') - - - def tx_wire(self, tx_wire): - return self.__hex_normalize(tx_wire, 'tx wire') - - - def wallet_address(self, address): - return self.__hex_normalize(address, 'wallet address') - - - def executable_address(self, address): - return self.__hex_normalize(address, 'executable address') - - - def __hex_normalize(self, data, context): - #r = add_0x(hex_uniform(strip_0x(data))) - r = hex_uniform(strip_0x(data)) - logg.debug('normalize {} {} -> {}'.format(context, data, r)) - return r - - -class NoopNormalize: - - def __init__(self): - self.tx_hash = self.__noop - self.tx_wire = self.__noop - self.wallet_address = self.__noop - self.executable_address = self.__noop - - - def __noop(self, data): - return data +from chainlib.encode import TxHexNormalizer diff --git a/requirements.txt b/requirements.txt @@ -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.9a3 +chainlib~=0.0.9a5 diff --git a/run_tests.sh b/run_tests.sh @@ -2,7 +2,7 @@ set +e set +x -export PYTHONPATH=. +export PYTHONPATH={$PYTHONPATH:-.} for f in `ls tests/*.py`; do python $f if [ $? -gt 0 ]; then diff --git a/setup.cfg b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = chainqueue -version = 0.0.5a1 +version = 0.0.5a3 description = Generic blockchain transaction queue control author = Louis Holbrook author_email = dev@holbrook.no