Add option to generate abi encoding without method

This commit is contained in:
nolash 2021-10-06 07:30:07 +02:00
parent 75c72b7828
commit e4d6b8d845
Signed by: lash
GPG Key ID: 21D2E7BB88C2A746
2 changed files with 17 additions and 4 deletions

View File

@ -62,7 +62,11 @@ argparser = chainlib.eth.cli.ArgumentParser(arg_flags)
argparser.add_argument('--signature', type=str, help='Method signature to encode') argparser.add_argument('--signature', type=str, help='Method signature to encode')
argparser.add_argument('contract_args', type=str, nargs='*', help='arguments to encode') argparser.add_argument('contract_args', type=str, nargs='*', help='arguments to encode')
args = argparser.parse_args() args = argparser.parse_args()
config = chainlib.eth.cli.Config.from_args(args, arg_flags, default_config_dir=config_dir) extra_args = {
'signature': None,
'contract_args': None,
}
config = chainlib.eth.cli.Config.from_args(args, arg_flags, extra_args=extra_args, default_config_dir=config_dir)
if not config.get('_EXEC_ADDRESS'): if not config.get('_EXEC_ADDRESS'):
argparser.error('exec address (-e) must be defined') argparser.error('exec address (-e) must be defined')
@ -161,19 +165,24 @@ def main():
cli_encoder = CLIEncoder() cli_encoder = CLIEncoder()
contract_encoder = ABIContractEncoder() contract_encoder = ABIContractEncoder()
if args.signature: if config.get('_SIGNATURE'):
contract_encoder.method(args.signature) contract_encoder.method(args.signature)
for arg in args.contract_args: for arg in config.get('_CONTRACT_ARGS'):
logg.debug('arg {}'.format(arg)) logg.debug('arg {}'.format(arg))
(typ, val) = arg.split(':', maxsplit=1) (typ, val) = arg.split(':', maxsplit=1)
real_typ = cli_encoder.translate_type(typ) real_typ = cli_encoder.translate_type(typ)
contract_encoder.typ(real_typ) if config.get('_SIGNATURE'):
contract_encoder.typ(real_typ)
fn = getattr(contract_encoder, real_typ.value) fn = getattr(contract_encoder, real_typ.value)
fn(val) fn(val)
code += contract_encoder.get() code += contract_encoder.get()
if not config.get('_SIGNATURE'):
print(strip_0x(code))
return
if signer == None: if signer == None:
c = TxFactory(chain_spec) c = TxFactory(chain_spec)
j = JSONRPCRequest(id_generator=rpc.id_generator) j = JSONRPCRequest(id_generator=rpc.id_generator)
@ -212,6 +221,8 @@ def main():
r = conn.do(r) r = conn.do(r)
print(r) print(r)
else: else:
if config.get('_RAW'):
o = strip_0x(o)
print(o) print(o)
if __name__ == '__main__': if __name__ == '__main__':

View File

@ -125,6 +125,8 @@ def main():
r = conn.do(o) r = conn.do(o)
print(r) print(r)
else: else:
if config.get('_RAW'):
o = strip_0x(o)
print(o) print(o)
else: else: