contract-registry

Ethereum Smart Contract key-value registry
Log | Files | Refs

commit 19532df107c82bbdecb94d35af975ec68c616d4a
parent e135112436055f8d30e50f23d7eab9c516b6359e
Author: lash <dev@holbrook.no>
Date:   Sun, 12 Feb 2023 13:52:32 +0000

Enforce max length on identifiers

Diffstat:
Mpython/eth_contract_registry/runnable/list.py | 23++---------------------
Mpython/eth_contract_registry/runnable/publish.py | 3+++
Mpython/eth_contract_registry/runnable/set.py | 13++++++++-----
3 files changed, 13 insertions(+), 26 deletions(-)

diff --git a/python/eth_contract_registry/runnable/list.py b/python/eth_contract_registry/runnable/list.py @@ -15,6 +15,7 @@ import chainlib.eth.cli from chainlib.chain import ChainSpec from chainlib.eth.tx import receipt from chainlib.eth.constant import ZERO_CONTENT +from chainlib.eth.constant import ZERO_ADDRESS from chainlib.error import JSONRPCException from chainlib.eth.address import to_checksum_address from hexathon import ( @@ -68,26 +69,6 @@ settings = process_settings(settings, config) logg.debug('settings loaded:\n{}'.format(settings)) - -#arg_flags = chainlib.eth.cli.argflag_std_read | chainlib.eth.cli.Flag.EXEC -#argparser = chainlib.eth.cli.ArgumentParser(arg_flags) -#argparser.add_argument('identifier', type=str, nargs='?', help='Token symbol to return address for') -#args = argparser.parse_args() -# -#extra_args = { -# 'identifier': None, -# } -#config = chainlib.eth.cli.Config.from_args(args, arg_flags, extra_args=extra_args, default_fee_limit=ContractRegistry.gas()) -# -#wallet = chainlib.eth.cli.Wallet() -#wallet.from_config(config) -# -#rpc = chainlib.eth.cli.Rpc(wallet=wallet) -#conn = rpc.connect_by_config(config) -# -#chain_spec = ChainSpec.from_chain_str(config.get('CHAIN_SPEC')) - - def out_element(e, w=sys.stdout): if config.get('_RAW'): w.write(e[1] + '\n') @@ -96,7 +77,7 @@ def out_element(e, w=sys.stdout): def element(ifc, conn, registry_address, identifier, w=sys.stdout): - o = ifc.address_of(registry_address, identifier) + o = ifc.address_of(registry_address, identifier, sender_address=ZERO_ADDRESS) r = conn.do(o) address = ifc.parse_address_of(r) out_element((identifier, address), w) diff --git a/python/eth_contract_registry/runnable/publish.py b/python/eth_contract_registry/runnable/publish.py @@ -40,6 +40,9 @@ def process_config_local(config, arg, args, flags): identifiers = args.identifier if len(identifiers) == 0: raise ValueError('at least one identifier must be defined') + for idntfr in identifiers: + if len(idntfr) > 32: + raise ValueError('identifier must be max 32 characters') config.add(identifiers, '_IDENTIFIER') return config diff --git a/python/eth_contract_registry/runnable/set.py b/python/eth_contract_registry/runnable/set.py @@ -9,6 +9,7 @@ import sys import os import logging +import hashlib # external imports import chainlib.eth.cli @@ -42,10 +43,12 @@ logg = logging.getLogger() def process_config_local(config, arg, args, flags): - hsh = strip_0x(args.chain_hash) - if len(hsh) != 64: - raise ValueError('chain hash must be 32 bytes') - config.add(hsh, '_CHAIN_HASH') + #hsh = strip_0x(args.chain_hash) + #if len(hsh) != 64: + # raise ValueError('chain hash must be 32 bytes') + #config.add(hsh, '_CHAIN_HASH') + if len(config.get('_POSARG')) > 32: + raise ValueError('identifier must be max 32 characters') config.add(config.get('_POSARG'), '_IDENTIFIER') return config @@ -56,7 +59,7 @@ flags = arg_flags.STD_WRITE | arg_flags.EXEC | arg_flags.WALLET argparser = chainlib.eth.cli.ArgumentParser() argparser = process_args(argparser, arg, flags) -argparser.add_argument('--chain-hash', type=str, default=ZERO_CONTENT, help='Chain config hash to use for entry') +#argparser.add_argument('--chain-hash', type=str, default=ZERO_CONTENT, help='Chain config hash to use for entry') argparser.add_argument('identifier', type=str, help='Contract identifier to set') args = argparser.parse_args()