chainqueue/chainqueue/encode.py

50 lines
1.1 KiB
Python
Raw Normal View History

2021-08-28 03:10:21 +02:00
# standard imports
import logging
# external imports
from hexathon import (
add_0x,
strip_0x,
uniform as hex_uniform,
)
2021-08-28 03:16:12 +02:00
logg = logging.getLogger()
2021-08-28 03:10:21 +02:00
2021-08-28 03:16:12 +02:00
class TxHexNormalizer:
2021-08-28 03:10:21 +02:00
def tx_hash(self, tx_hash):
2021-08-28 03:16:12 +02:00
return self.__hex_normalize(tx_hash, 'tx hash')
2021-08-28 03:10:21 +02:00
def tx_wire(self, tx_wire):
2021-08-28 03:16:12 +02:00
return self.__hex_normalize(tx_wire, 'tx wire')
2021-08-28 03:10:21 +02:00
def wallet_address(self, address):
2021-08-28 03:16:12 +02:00
return self.__hex_normalize(address, 'wallet address')
2021-08-28 03:10:21 +02:00
def executable_address(self, address):
2021-08-28 03:16:12 +02:00
return self.__hex_normalize(address, 'executable address')
2021-08-28 03:10:21 +02:00
2021-08-28 03:16:12 +02:00
def __hex_normalize(self, data, context):
2021-08-28 06:28:38 +02:00
#r = add_0x(hex_uniform(strip_0x(data)))
r = hex_uniform(strip_0x(data))
2021-08-28 03:16:12 +02:00
logg.debug('normalize {} {} -> {}'.format(context, data, r))
2021-08-28 03:10:21 +02:00
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