Move all encoding steps to cliencoder

This commit is contained in:
nolash
2021-10-06 07:52:19 +02:00
parent 0e0dbf180e
commit b983938d80
2 changed files with 25 additions and 17 deletions

View File

@@ -3,12 +3,15 @@ import re
import logging
# external imports
from chainlib.eth.contract import ABIContractType
from chainlib.eth.contract import (
ABIContractType,
ABIContractEncoder,
)
logg = logging.getLogger(__name__)
class CLIEncoder:
class CLIEncoder(ABIContractEncoder):
__re_uint = r'^([uU])[int]*([0-9]+)?$'
__re_bytes = r'^([bB])[ytes]*([0-9]+)?$'
@@ -19,6 +22,12 @@ class CLIEncoder:
'to_string',
]
def __init__(self, signature=None):
super(CLIEncoder, self).__init__()
self.signature = signature
if signature != None:
self.method(signature)
def to_uint(self, typ):
s = None
a = None
@@ -68,3 +77,13 @@ class CLIEncoder:
raise ValueError('no translation for type {}'.format(typ))
logg.debug('type {} translated to {}'.format(typ, r[0]))
return r[1]
def add_from(self, arg):
logg.debug('arg {}'.format(arg))
(typ, val) = arg.split(':', maxsplit=1)
real_typ = self.translate_type(typ)
if self.signature != None:
self.typ(real_typ)
fn = getattr(self, real_typ.value)
fn(val)