Compare commits
4 Commits
dev-0.1.16
...
dev-0.2.0
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b7a84acdb4
|
||
|
|
b7953cbd0f
|
||
|
|
c5bd4aad3a
|
||
|
|
c45e6e3310
|
@@ -1,3 +1,5 @@
|
|||||||
|
- 0.2.0
|
||||||
|
* Implement chainlib 0.3.0
|
||||||
- 0.1.16
|
- 0.1.16
|
||||||
* Queue list cli tool
|
* Queue list cli tool
|
||||||
* State parser cli tool
|
* State parser cli tool
|
||||||
|
|||||||
@@ -1,153 +0,0 @@
|
|||||||
# standard imports
|
|
||||||
import logging
|
|
||||||
import enum
|
|
||||||
|
|
||||||
# external imports
|
|
||||||
from hexathon import add_0x
|
|
||||||
|
|
||||||
# local imports
|
|
||||||
from chainqueue.enum import (
|
|
||||||
StatusBits,
|
|
||||||
all_errors,
|
|
||||||
is_alive,
|
|
||||||
is_error_status,
|
|
||||||
status_str,
|
|
||||||
)
|
|
||||||
|
|
||||||
logg = logging.getLogger(__name__)
|
|
||||||
|
|
||||||
|
|
||||||
class OutputCol(enum.Enum):
|
|
||||||
chainspec = 0
|
|
||||||
hash = 1
|
|
||||||
statustext = 2
|
|
||||||
statuscode = 3
|
|
||||||
signedtx = 4
|
|
||||||
|
|
||||||
|
|
||||||
class Outputter:
|
|
||||||
"""Output helper for chainqueue cli listings tools.
|
|
||||||
|
|
||||||
:param chain_spec: Chain spec to use as getter context
|
|
||||||
:type chain_spec: chainlib.chain.ChainSpec
|
|
||||||
:param writer: Writer to write output to. Will automatically flush.
|
|
||||||
:type writer: Writer
|
|
||||||
:param getter: Transaction getter
|
|
||||||
:type getter: See chainqueue.sql.backend.get_otx
|
|
||||||
:param session_method: Backend session generator method
|
|
||||||
:type session_method: varies
|
|
||||||
:param decode_status: Print status bit details
|
|
||||||
:type decode_status: bool
|
|
||||||
"""
|
|
||||||
|
|
||||||
all_cols = [
|
|
||||||
OutputCol.chainspec,
|
|
||||||
OutputCol.hash,
|
|
||||||
OutputCol.signedtx,
|
|
||||||
OutputCol.statustext,
|
|
||||||
OutputCol.statuscode,
|
|
||||||
]
|
|
||||||
default_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
|
|
||||||
self.chain_spec = chain_spec
|
|
||||||
self.chain_spec_str = str(chain_spec)
|
|
||||||
self.session = None
|
|
||||||
if session_method != None:
|
|
||||||
self.session = session_method()
|
|
||||||
self.results = {
|
|
||||||
'pending_error': 0,
|
|
||||||
'final_error': 0,
|
|
||||||
'pending': 0,
|
|
||||||
'final': 0,
|
|
||||||
}
|
|
||||||
|
|
||||||
debug_col_name = []
|
|
||||||
if cols == None:
|
|
||||||
self.cols = Outputter.default_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:
|
|
||||||
self.session.close()
|
|
||||||
|
|
||||||
|
|
||||||
def add(self, tx_hash):
|
|
||||||
"""Retrieve a transaction by hash and add it for summary output generation.
|
|
||||||
|
|
||||||
:param tx_hash: Transaction hash
|
|
||||||
:type tx_hash: str
|
|
||||||
"""
|
|
||||||
tx = self.getter(self.chain_spec, tx_hash, session=self.session)
|
|
||||||
self.__add(tx)
|
|
||||||
|
|
||||||
def __add(self, tx):
|
|
||||||
category = None
|
|
||||||
if is_alive(tx['status_code']):
|
|
||||||
category = 'pending'
|
|
||||||
else:
|
|
||||||
category = 'final'
|
|
||||||
self.results[category] += 1
|
|
||||||
if is_error_status(tx['status_code']):
|
|
||||||
logg.debug('registered {} as {} with error'.format(tx['tx_hash'], category))
|
|
||||||
self.results[category + '_error'] += 1
|
|
||||||
else:
|
|
||||||
logg.debug('registered {} as {}'.format(tx['tx_hash'], category))
|
|
||||||
|
|
||||||
|
|
||||||
def decode_summary(self):
|
|
||||||
"""Writes summary to the registered writer.
|
|
||||||
"""
|
|
||||||
self.writer.write('pending\t{}\t{}\n'.format(self.results['pending'], self.results['pending_error']))
|
|
||||||
self.writer.write('final\t{}\t{}\n'.format(self.results['final'], self.results['final_error']))
|
|
||||||
self.writer.write('total\t{}\t{}\n'.format(self.results['final'] + self.results['pending'], self.results['final_error'] + self.results['pending_error']))
|
|
||||||
|
|
||||||
|
|
||||||
def decode_single(self, tx_hash):
|
|
||||||
"""Retrieves the transaction with the given hash and writes the details to the underlying writer.
|
|
||||||
|
|
||||||
Registers the transaction with the summary generator.
|
|
||||||
|
|
||||||
:param tx_hash: Transaction hash
|
|
||||||
:type tx_hash: str
|
|
||||||
"""
|
|
||||||
tx = self.getter(self.chain_spec, tx_hash, session=self.session)
|
|
||||||
self.__add(tx)
|
|
||||||
status = tx['status']
|
|
||||||
if self.decode_status:
|
|
||||||
status = status_str(tx['status_code'], bits_only=True)
|
|
||||||
|
|
||||||
vals = [
|
|
||||||
self.chain_spec_str,
|
|
||||||
add_0x(tx_hash),
|
|
||||||
status,
|
|
||||||
str(tx['status_code']),
|
|
||||||
add_0x(tx['signed_tx']),
|
|
||||||
]
|
|
||||||
|
|
||||||
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')
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
# standard imports
|
|
||||||
import os
|
|
||||||
|
|
||||||
# local imports
|
|
||||||
from .arg import process_flags
|
|
||||||
from .config import process_config
|
|
||||||
|
|
||||||
|
|
||||||
__script_dir = os.path.dirname(os.path.realpath(__file__))
|
|
||||||
data_dir = os.path.join(os.path.dirname(__script_dir), 'data')
|
|
||||||
config_dir = os.path.join(data_dir, 'config')
|
|
||||||
@@ -1,2 +1,8 @@
|
|||||||
def process_flags(argparser, flags):
|
def apply_flag(flag):
|
||||||
argparser.add_argument('--backend', type=str, help='Backend to use for state store')
|
flag.add('queue')
|
||||||
|
return flag
|
||||||
|
|
||||||
|
|
||||||
|
def apply_arg(arg):
|
||||||
|
arg.add_long('tx-digest-size', 'queue', type=int, help='Size of transaction hash in bytes')
|
||||||
|
return arg
|
||||||
|
|||||||
@@ -28,19 +28,12 @@ config_dir = os.path.join(script_dir, '..', 'data', 'config')
|
|||||||
arg_flags = chainlib.cli.argflag_std_base | chainlib.cli.Flag.CHAIN_SPEC | chainlib.cli.Flag.UNSAFE
|
arg_flags = chainlib.cli.argflag_std_base | chainlib.cli.Flag.CHAIN_SPEC | chainlib.cli.Flag.UNSAFE
|
||||||
argparser = chainlib.cli.ArgumentParser(arg_flags)
|
argparser = chainlib.cli.ArgumentParser(arg_flags)
|
||||||
argparser.add_argument('--backend', type=str, default='sql', help='Backend to use')
|
argparser.add_argument('--backend', type=str, default='sql', help='Backend to use')
|
||||||
argparser.add_argument('--state-dir', type=str, dest='state_dir', help='Backend to use')
|
|
||||||
argparser.add_argument('--tx-digest-size', type=int, dest='tx_digest_size', default=32, help='Size of tx digest in bytes')
|
|
||||||
#argparser.add_argument('--session-id', type=str, dest='session_id', help='Session id to list')
|
|
||||||
#argparser.add_argument('--start', type=str, help='Oldest transaction to include in results')
|
|
||||||
#argparser.add_argument('--end', type=str, help='Newest transaction to include in results')
|
|
||||||
argparser.add_argument('--error', action='store_true', help='Only show transactions which have error state')
|
argparser.add_argument('--error', action='store_true', help='Only show transactions which have error state')
|
||||||
argparser.add_argument('--no-final', action='store_true', dest='no_final', help='Omit finalized transactions')
|
argparser.add_argument('--no-final', action='store_true', dest='no_final', help='Omit finalized transactions')
|
||||||
argparser.add_argument('--status-mask', type=str, dest='status_mask', action='append', default=[], help='Manually specify status bitmask value to match (overrides --error and --pending)')
|
argparser.add_argument('--status-mask', type=str, dest='status_mask', action='append', default=[], help='Manually specify status bitmask value to match (overrides --error and --pending)')
|
||||||
argparser.add_argument('--exact', action='store_true', help='Match status exact')
|
argparser.add_argument('--exact', action='store_true', help='Match status exact')
|
||||||
argparser.add_argument('--include-pending', action='store_true', dest='include_pending', help='Include transactions in unprocessed state (pending)')
|
argparser.add_argument('--include-pending', action='store_true', dest='include_pending', help='Include transactions in unprocessed state (pending)')
|
||||||
argparser.add_argument('--renderer', type=str, default=[], action='append', help='Transaction renderer for output')
|
argparser.add_argument('--renderer', type=str, default=[], action='append', help='Transaction renderer for output')
|
||||||
#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', required=False, type=str, help='Ethereum address of recipient')
|
argparser.add_positional('address', required=False, type=str, help='Ethereum address of recipient')
|
||||||
args = argparser.parse_args()
|
args = argparser.parse_args()
|
||||||
extra_args = {
|
extra_args = {
|
||||||
@@ -48,16 +41,11 @@ extra_args = {
|
|||||||
'backend': None,
|
'backend': None,
|
||||||
'state_dir': None,
|
'state_dir': None,
|
||||||
'exact': None,
|
'exact': None,
|
||||||
# 'tx_digest_size': None,
|
|
||||||
# 'start': None,
|
|
||||||
# 'end': None,
|
|
||||||
'error': None,
|
'error': None,
|
||||||
'include_pending': '_PENDING',
|
'include_pending': '_PENDING',
|
||||||
'status_mask': None,
|
'status_mask': None,
|
||||||
'no_final': None,
|
'no_final': None,
|
||||||
'renderer': None,
|
'renderer': None,
|
||||||
# 'column': None,
|
|
||||||
# 'summary': None,
|
|
||||||
}
|
}
|
||||||
config = chainlib.cli.Config.from_args(args, arg_flags, extra_args=extra_args, base_config_dir=config_dir)
|
config = chainlib.cli.Config.from_args(args, arg_flags, extra_args=extra_args, base_config_dir=config_dir)
|
||||||
config = chainqueue.cli.config.process_config(config, args, 0)
|
config = chainqueue.cli.config.process_config(config, args, 0)
|
||||||
|
|||||||
@@ -10,77 +10,90 @@ from chainqueue.store import Store
|
|||||||
logg = logging.getLogger(__name__)
|
logg = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class ChainqueueSettings(ChainSettings):
|
def process_queue_tx(settings, config):
|
||||||
|
settings.set('TX_DIGEST_SIZE', config.get('TX_DIGEST_SIZE'))
|
||||||
def process_queue_tx(self, config):
|
return settings
|
||||||
self.o['TX_DIGEST_SIZE'] = config.get('TX_DIGEST_SIZE')
|
|
||||||
|
|
||||||
|
|
||||||
def process_queue_backend(self, config):
|
def process_queue_store(settings, config):
|
||||||
self.o['QUEUE_BACKEND'] = config.get('QUEUE_BACKEND')
|
status = Status(settings.get('QUEUE_STORE_FACTORY'), allow_invalid=True)
|
||||||
self.o['QUEUE_STATE_STORE'] = Status(self.o['QUEUE_STORE_FACTORY'], allow_invalid=True)
|
settings.set('QUEUE_STATE_STORE', status)
|
||||||
self.o['QUEUE_STORE'] = Store(
|
store = Store(
|
||||||
self.o['CHAIN_SPEC'],
|
settings.get('CHAIN_SPEC'),
|
||||||
self.o['QUEUE_STATE_STORE'],
|
settings.get('QUEUE_STATE_STORE'),
|
||||||
self.o['QUEUE_INDEX_STORE'],
|
settings.get('QUEUE_INDEX_STORE'),
|
||||||
self.o['QUEUE_COUNTER_STORE'],
|
settings.get('QUEUE_COUNTER_STORE'),
|
||||||
sync=True,
|
sync=True,
|
||||||
)
|
)
|
||||||
|
settings.set('QUEUE_STORE', store)
|
||||||
|
return settings
|
||||||
|
|
||||||
|
|
||||||
def process_queue_paths(self, config):
|
def process_queue_paths(settings, config):
|
||||||
index_dir = config.get('QUEUE_INDEX_PATH')
|
index_dir = config.get('QUEUE_INDEX_PATH')
|
||||||
if index_dir == None:
|
if index_dir == None:
|
||||||
index_dir = os.path.join(config.get('QUEUE_STATE_PATH'), 'tx')
|
index_dir = os.path.join(config.get('STATE_PATH'), 'tx')
|
||||||
|
|
||||||
counter_dir = config.get('QUEUE_COUNTER_PATH')
|
counter_dir = config.get('QUEUE_COUNTER_PATH')
|
||||||
if counter_dir == None:
|
if counter_dir == None:
|
||||||
counter_dir = os.path.join(config.get('QUEUE_STATE_PATH'))
|
counter_dir = os.path.join(config.get('STATE_PATH'))
|
||||||
|
|
||||||
self.o['QUEUE_STATE_PATH'] = config.get('QUEUE_STATE_PATH')
|
settings.set('QUEUE_STATE_PATH', config.get('STATE_PATH'))
|
||||||
self.o['QUEUE_INDEX_PATH'] = index_dir
|
settings.set('QUEUE_INDEX_PATH', index_dir)
|
||||||
self.o['QUEUE_COUNTER_PATH'] = counter_dir
|
settings.set('QUEUE_COUNTER_PATH', counter_dir)
|
||||||
|
return settings
|
||||||
|
|
||||||
|
|
||||||
def process_queue_backend_fs(self, config):
|
def process_queue_backend_fs(settings, config):
|
||||||
from chainqueue.store.fs import IndexStore
|
from chainqueue.store.fs import IndexStore
|
||||||
from chainqueue.store.fs import CounterStore
|
from chainqueue.store.fs import CounterStore
|
||||||
from shep.store.file import SimpleFileStoreFactory
|
from shep.store.file import SimpleFileStoreFactory
|
||||||
index_store = IndexStore(self.o['QUEUE_INDEX_PATH'], digest_bytes=self.o['TX_DIGEST_SIZE'])
|
index_store = IndexStore(settings.o['QUEUE_INDEX_PATH'], digest_bytes=int(settings.o['TX_DIGEST_SIZE']))
|
||||||
counter_store = CounterStore(self.o['QUEUE_COUNTER_PATH'])
|
counter_store = CounterStore(settings.o['QUEUE_COUNTER_PATH'])
|
||||||
factory = SimpleFileStoreFactory(self.o['QUEUE_STATE_PATH'], use_lock=True).add
|
factory = SimpleFileStoreFactory(settings.o['QUEUE_STATE_PATH'], use_lock=True).add
|
||||||
|
|
||||||
self.o['QUEUE_INDEX_STORE'] = index_store
|
settings.set('QUEUE_INDEX_STORE', index_store)
|
||||||
self.o['QUEUE_COUNTER_STORE'] = counter_store
|
settings.set('QUEUE_COUNTER_STORE', counter_store)
|
||||||
self.o['QUEUE_STORE_FACTORY'] = factory
|
settings.set('QUEUE_STORE_FACTORY', factory)
|
||||||
|
|
||||||
|
return settings
|
||||||
|
|
||||||
|
|
||||||
def process_queue_status_filter(self, config):
|
def process_queue_status_filter(settings, config):
|
||||||
states = 0
|
states = 0
|
||||||
if len(config.get('_STATUS_MASK')) == 0:
|
store = settings.get('QUEUE_STATE_STORE')
|
||||||
for v in self.o['QUEUE_STATE_STORE'].all(numeric=True):
|
if len(config.get('_STATUS_MASK')) == 0:
|
||||||
states |= v
|
for v in store.all(numeric=True):
|
||||||
logg.debug('state store {}'.format(states))
|
states |= v
|
||||||
else:
|
logg.debug('state store {}'.format(states))
|
||||||
for v in config.get('_STATUS_MASK'):
|
else:
|
||||||
try:
|
for v in config.get('_STATUS_MASK'):
|
||||||
states |= int(v)
|
try:
|
||||||
continue
|
states |= int(v)
|
||||||
except ValueError:
|
continue
|
||||||
pass
|
except ValueError:
|
||||||
|
pass
|
||||||
state = self.o['QUEUE_STATE_STORE'].from_name(v)
|
|
||||||
logg.debug('resolved state argument {} to numeric state {}'.format(v, state))
|
state = store.from_name(v)
|
||||||
states |= state
|
logg.debug('resolved state argument {} to numeric state {}'.format(v, state))
|
||||||
|
states |= state
|
||||||
|
|
||||||
self.o['QUEUE_STATUS_FILTER'] = states
|
settings.set('QUEUE_STATUS_FILTER', states)
|
||||||
|
return settings
|
||||||
|
|
||||||
|
|
||||||
def process(self, config):
|
def process_queue(settings, config):
|
||||||
super(ChainqueueSettings, self).process(config)
|
settings = process_queue_tx(settings, config)
|
||||||
self.process_queue_tx(config)
|
settings = process_queue_paths(settings, config)
|
||||||
self.process_queue_paths(config)
|
if config.get('QUEUE_BACKEND') == 'fs':
|
||||||
if config.get('_BACKEND') == 'fs':
|
settings = process_queue_backend_fs(settings, config)
|
||||||
self.process_queue_backend_fs(config)
|
settings = process_queue_backend(settings, config)
|
||||||
self.process_queue_backend(config)
|
settings = process_queue_store(settings, config)
|
||||||
self.process_queue_status_filter(config)
|
settings = process_queue_status_filter(settings, config)
|
||||||
|
return settings
|
||||||
|
|
||||||
|
|
||||||
|
def process_settings(settings, config):
|
||||||
|
super(ChainqueueSettings, settings).process(config)
|
||||||
|
settings = settings.process_queue(settings, config)
|
||||||
|
return settings
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
hexathon~=0.1.7
|
hexathon~=0.1.7
|
||||||
leveldir~=0.3.0
|
leveldir~=0.3.0
|
||||||
confini~=0.6.0
|
confini~=0.6.1
|
||||||
chainlib~=0.2.0
|
chainlib~=0.3.0
|
||||||
shep~=0.2.9
|
shep~=0.2.9
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[metadata]
|
[metadata]
|
||||||
name = chainqueue
|
name = chainqueue
|
||||||
version = 0.1.16
|
version = 0.2.0
|
||||||
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
|
||||||
@@ -34,6 +34,7 @@ packages =
|
|||||||
chainqueue.store
|
chainqueue.store
|
||||||
chainqueue.runnable
|
chainqueue.runnable
|
||||||
chainqueue.cli
|
chainqueue.cli
|
||||||
|
chainqueue.data
|
||||||
|
|
||||||
[options.entry_points]
|
[options.entry_points]
|
||||||
console_scripts =
|
console_scripts =
|
||||||
|
|||||||
Reference in New Issue
Block a user