Add tx normalizer docstring

This commit is contained in:
nolash 2021-08-28 03:16:12 +02:00
parent 7e3d9630ce
commit 3b990a9a87
Signed by: lash
GPG Key ID: 21D2E7BB88C2A746
2 changed files with 12 additions and 13 deletions

View File

@ -8,30 +8,30 @@ from hexathon import (
uniform as hex_uniform,
)
logg = logging.getLogger(__name__)
logg = logging.getLogger()
class TxHexNormalize:
class TxHexNormalizer:
def tx_hash(self, tx_hash):
return self.__hex_normalize(tx_hash)
return self.__hex_normalize(tx_hash, 'tx hash')
def tx_wire(self, tx_wire):
return self.__hex_normalize(tx_wire)
return self.__hex_normalize(tx_wire, 'tx wire')
def wallet_address(self, address):
return self.__hex_normalize(address)
return self.__hex_normalize(address, 'wallet address')
def executable_address(self, address):
return self.__hex_normalize(address)
return self.__hex_normalize(address, 'executable address')
def __hex_normalize(self, data):
def __hex_normalize(self, data, context):
r = add_0x(hex_uniform(strip_0x(data)))
logg.debug('tx hex normalize {} -> {}'.format(data, r))
logg.debug('normalize {} {} -> {}'.format(context, data, r))
return r

View File

@ -29,7 +29,7 @@ from chainqueue.sql.state import (
set_rejected,
)
from chainqueue.sql.tx import cache_tx_dict
from chainqueue.encode import TxHexNormalize
from chainqueue.encode import TxHexNormalizer
logg = logging.getLogger(__name__)
@ -39,6 +39,8 @@ class SQLBackend:
:param conn_spec: Backend-dependent connection specification string. See chainqueue.db.models.base.SessionBase.connect
:type conn_spec: str
:param tx_normalizer: Transaction data normalizer
:type tx_normalizer: Object implementing chainqueue.encode.TxHexNormalizer interface
:param error_parser: Error parser to use for RPC calls within the backend component
:type error_parser: Object implementing chainlib.error.DefaultErrorParser
:param pool_size: Connection pool size for pool-capable sql engines. See chainqueue.db.models.base.SessionBase.connect
@ -47,16 +49,13 @@ class SQLBackend:
:type debug: bool
:todo: define a backend abstract interface class
"""
#def __init__(self, conn_spec, error_parser=None, *args, **kwargs):
def __init__(self, conn_spec, tx_normalizer=None, error_parser=None, pool_size=0, debug=False, *args, **kwargs):
#SessionBase.connect(conn_spec, pool_size=kwargs.get('poolsize', 0), debug=kwargs.get('debug', False))
SessionBase.connect(conn_spec, pool_size=pool_size, debug=debug)
if error_parser == None:
error_parser = DefaultErrorParser()
self.error_parser = error_parser
if tx_normalizer == None:
tx_normalizer = TxHexNormalize()
tx_normalizer = TxHexNormalizer()
self.tx_normalizer = tx_normalizer