Add output column selector
This commit is contained in:
parent
a3e9a3ee00
commit
5302b1f4f5
@ -54,6 +54,19 @@ class Adapter:
|
|||||||
raise NotImplementedError()
|
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):
|
def dispatch(self, chain_spec, rpc, tx_hash, signed_tx, session=None):
|
||||||
"""Send a queued transaction to the network.
|
"""Send a queued transaction to the network.
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
# standard imports
|
# standard imports
|
||||||
import logging
|
import logging
|
||||||
|
import enum
|
||||||
|
|
||||||
# external imports
|
# external imports
|
||||||
from hexathon import add_0x
|
from hexathon import add_0x
|
||||||
@ -16,6 +17,13 @@ from chainqueue.enum import (
|
|||||||
logg = logging.getLogger(__name__)
|
logg = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
class OutputCol(enum.Enum):
|
||||||
|
chainspec = 0
|
||||||
|
hash = 1
|
||||||
|
statustext = 2
|
||||||
|
statuscode = 3
|
||||||
|
|
||||||
|
|
||||||
class Outputter:
|
class Outputter:
|
||||||
"""Output helper for chainqueue cli listings tools.
|
"""Output helper for chainqueue cli listings tools.
|
||||||
|
|
||||||
@ -31,7 +39,14 @@ class Outputter:
|
|||||||
:type decode_status: bool
|
: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.decode_status = decode_status
|
||||||
self.writer = writer
|
self.writer = writer
|
||||||
self.getter = getter
|
self.getter = getter
|
||||||
@ -47,6 +62,19 @@ class Outputter:
|
|||||||
'final': 0,
|
'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):
|
def __del__(self):
|
||||||
if self.session != None:
|
if self.session != None:
|
||||||
@ -97,4 +125,21 @@ class Outputter:
|
|||||||
status = tx['status']
|
status = tx['status']
|
||||||
if self.decode_status:
|
if self.decode_status:
|
||||||
status = status_str(tx['status_code'], bits_only=True)
|
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()
|
||||||
|
@ -1,49 +1,2 @@
|
|||||||
# standard imports
|
|
||||||
import logging
|
|
||||||
|
|
||||||
# external imports
|
# external imports
|
||||||
from hexathon import (
|
from chainlib.encode import TxHexNormalizer
|
||||||
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
|
|
||||||
|
@ -5,4 +5,4 @@ alembic==1.4.2
|
|||||||
SQLAlchemy==1.3.20
|
SQLAlchemy==1.3.20
|
||||||
confini>=0.4.1a1,<0.5.0
|
confini>=0.4.1a1,<0.5.0
|
||||||
pyxdg~=0.27
|
pyxdg~=0.27
|
||||||
chainlib~=0.0.9a3
|
chainlib~=0.0.9a5
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
set +e
|
set +e
|
||||||
set +x
|
set +x
|
||||||
export PYTHONPATH=.
|
export PYTHONPATH={$PYTHONPATH:-.}
|
||||||
for f in `ls tests/*.py`; do
|
for f in `ls tests/*.py`; do
|
||||||
python $f
|
python $f
|
||||||
if [ $? -gt 0 ]; then
|
if [ $? -gt 0 ]; then
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
[metadata]
|
[metadata]
|
||||||
name = chainqueue
|
name = chainqueue
|
||||||
version = 0.0.5a1
|
version = 0.0.5a3
|
||||||
description = Generic blockchain transaction queue control
|
description = Generic blockchain transaction queue control
|
||||||
author = Louis Holbrook
|
author = Louis Holbrook
|
||||||
author_email = dev@holbrook.no
|
author_email = dev@holbrook.no
|
||||||
|
Loading…
Reference in New Issue
Block a user