2022-05-09 20:46:10 +02:00
|
|
|
# standard imports
|
|
|
|
import logging
|
2022-05-12 10:20:06 +02:00
|
|
|
import json
|
2022-05-09 20:46:10 +02:00
|
|
|
|
2022-05-09 12:00:29 +02:00
|
|
|
# external imports
|
|
|
|
from potaahto.symbols import snake_and_camel
|
|
|
|
from hexathon import (
|
|
|
|
uniform,
|
|
|
|
strip_0x,
|
|
|
|
)
|
|
|
|
|
|
|
|
# local imports
|
|
|
|
from chainlib.src import (
|
|
|
|
Src as BaseSrc,
|
|
|
|
SrcItem,
|
|
|
|
)
|
|
|
|
|
2022-05-09 20:46:10 +02:00
|
|
|
logg = logging.getLogger(__name__)
|
|
|
|
|
2022-05-09 12:00:29 +02:00
|
|
|
|
|
|
|
class Src(BaseSrc):
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def src_normalize(self, v):
|
|
|
|
src = snake_and_camel(v)
|
2022-05-09 20:46:10 +02:00
|
|
|
logg.debug('normalize has {}'.format(src))
|
2022-05-09 12:00:29 +02:00
|
|
|
if isinstance(src.get('v'), str):
|
|
|
|
try:
|
|
|
|
src['v'] = int(src['v'])
|
|
|
|
except ValueError:
|
|
|
|
src['v'] = int(src['v'], 16)
|
|
|
|
return src
|
|
|
|
|
|
|
|
|
|
|
|
def normal(self, v, typ=SrcItem.AUTO):
|
|
|
|
if typ == SrcItem.SRC:
|
|
|
|
return self.src_normalize(v)
|
|
|
|
|
|
|
|
if typ == SrcItem.HASH:
|
|
|
|
v = strip_0x(v, pad=False)
|
|
|
|
v = uniform(v, compact_value=True)
|
|
|
|
elif typ == SrcItem.ADDRESS:
|
|
|
|
v = strip_0x(v, pad=False)
|
|
|
|
v = uniform(v, compact_value=True)
|
|
|
|
elif typ == SrcItem.PAYLOAD:
|
|
|
|
v = strip_0x(v, pad=False, allow_empty=True)
|
|
|
|
v = uniform(v, compact_value=False, allow_empty=True)
|
|
|
|
|
|
|
|
return v
|
2022-05-12 10:20:06 +02:00
|
|
|
|
|
|
|
|
|
|
|
def __repr__(self):
|
|
|
|
return json.dumps(self.src)
|