commit 3b990a9a87ba279986d853d4e3d452ad07dde41d
parent 7e3d9630ceaa980b165eb581b69687a956eb41c2
Author: nolash <dev@holbrook.no>
Date: Sat, 28 Aug 2021 03:16:12 +0200
Add tx normalizer docstring
Diffstat:
2 files changed, 12 insertions(+), 13 deletions(-)
diff --git a/chainqueue/encode.py b/chainqueue/encode.py
@@ -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
diff --git a/chainqueue/sql/backend.py b/chainqueue/sql/backend.py
@@ -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