Move all encoding steps to cliencoder
This commit is contained in:
parent
0e0dbf180e
commit
b983938d80
@ -3,12 +3,15 @@ import re
|
|||||||
import logging
|
import logging
|
||||||
|
|
||||||
# external imports
|
# external imports
|
||||||
from chainlib.eth.contract import ABIContractType
|
from chainlib.eth.contract import (
|
||||||
|
ABIContractType,
|
||||||
|
ABIContractEncoder,
|
||||||
|
)
|
||||||
|
|
||||||
logg = logging.getLogger(__name__)
|
logg = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class CLIEncoder:
|
class CLIEncoder(ABIContractEncoder):
|
||||||
|
|
||||||
__re_uint = r'^([uU])[int]*([0-9]+)?$'
|
__re_uint = r'^([uU])[int]*([0-9]+)?$'
|
||||||
__re_bytes = r'^([bB])[ytes]*([0-9]+)?$'
|
__re_bytes = r'^([bB])[ytes]*([0-9]+)?$'
|
||||||
@ -19,6 +22,12 @@ class CLIEncoder:
|
|||||||
'to_string',
|
'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):
|
def to_uint(self, typ):
|
||||||
s = None
|
s = None
|
||||||
a = None
|
a = None
|
||||||
@ -68,3 +77,13 @@ class CLIEncoder:
|
|||||||
raise ValueError('no translation for type {}'.format(typ))
|
raise ValueError('no translation for type {}'.format(typ))
|
||||||
logg.debug('type {} translated to {}'.format(typ, r[0]))
|
logg.debug('type {} translated to {}'.format(typ, r[0]))
|
||||||
return r[1]
|
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)
|
||||||
|
@ -45,7 +45,6 @@ from chainlib.error import SignerMissingException
|
|||||||
from chainlib.chain import ChainSpec
|
from chainlib.chain import ChainSpec
|
||||||
from chainlib.eth.runnable.util import decode_for_puny_humans
|
from chainlib.eth.runnable.util import decode_for_puny_humans
|
||||||
from chainlib.eth.jsonrpc import to_blockheight_param
|
from chainlib.eth.jsonrpc import to_blockheight_param
|
||||||
from chainlib.eth.contract import ABIContractEncoder
|
|
||||||
|
|
||||||
logging.basicConfig(level=logging.WARNING)
|
logging.basicConfig(level=logging.WARNING)
|
||||||
logg = logging.getLogger()
|
logg = logging.getLogger()
|
||||||
@ -96,22 +95,12 @@ def main():
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
code = '0x'
|
code = '0x'
|
||||||
cli_encoder = CLIEncoder()
|
cli_encoder = CLIEncoder(signature=config.get('_SIGNATURE'))
|
||||||
contract_encoder = ABIContractEncoder()
|
|
||||||
|
|
||||||
if config.get('_SIGNATURE'):
|
|
||||||
contract_encoder.method(args.signature)
|
|
||||||
|
|
||||||
for arg in config.get('_CONTRACT_ARGS'):
|
for arg in config.get('_CONTRACT_ARGS'):
|
||||||
logg.debug('arg {}'.format(arg))
|
cli_encoder.add_from(arg)
|
||||||
(typ, val) = arg.split(':', maxsplit=1)
|
|
||||||
real_typ = cli_encoder.translate_type(typ)
|
code += cli_encoder.get()
|
||||||
if config.get('_SIGNATURE'):
|
|
||||||
contract_encoder.typ(real_typ)
|
|
||||||
fn = getattr(contract_encoder, real_typ.value)
|
|
||||||
fn(val)
|
|
||||||
|
|
||||||
code += contract_encoder.get()
|
|
||||||
|
|
||||||
if not config.get('_SIGNATURE'):
|
if not config.get('_SIGNATURE'):
|
||||||
print(strip_0x(code))
|
print(strip_0x(code))
|
||||||
|
Loading…
Reference in New Issue
Block a user