Enforce max length on identifiers

This commit is contained in:
lash 2023-02-12 13:52:32 +00:00
parent e135112436
commit 19532df107
Signed by: lash
GPG Key ID: 21D2E7BB88C2A746
3 changed files with 13 additions and 26 deletions

View File

@ -15,6 +15,7 @@ import chainlib.eth.cli
from chainlib.chain import ChainSpec from chainlib.chain import ChainSpec
from chainlib.eth.tx import receipt from chainlib.eth.tx import receipt
from chainlib.eth.constant import ZERO_CONTENT from chainlib.eth.constant import ZERO_CONTENT
from chainlib.eth.constant import ZERO_ADDRESS
from chainlib.error import JSONRPCException from chainlib.error import JSONRPCException
from chainlib.eth.address import to_checksum_address from chainlib.eth.address import to_checksum_address
from hexathon import ( from hexathon import (
@ -68,26 +69,6 @@ settings = process_settings(settings, config)
logg.debug('settings loaded:\n{}'.format(settings)) 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): def out_element(e, w=sys.stdout):
if config.get('_RAW'): if config.get('_RAW'):
w.write(e[1] + '\n') 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): 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) r = conn.do(o)
address = ifc.parse_address_of(r) address = ifc.parse_address_of(r)
out_element((identifier, address), w) out_element((identifier, address), w)

View File

@ -40,6 +40,9 @@ def process_config_local(config, arg, args, flags):
identifiers = args.identifier identifiers = args.identifier
if len(identifiers) == 0: if len(identifiers) == 0:
raise ValueError('at least one identifier must be defined') 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') config.add(identifiers, '_IDENTIFIER')
return config return config

View File

@ -9,6 +9,7 @@
import sys import sys
import os import os
import logging import logging
import hashlib
# external imports # external imports
import chainlib.eth.cli import chainlib.eth.cli
@ -42,10 +43,12 @@ logg = logging.getLogger()
def process_config_local(config, arg, args, flags): def process_config_local(config, arg, args, flags):
hsh = strip_0x(args.chain_hash) #hsh = strip_0x(args.chain_hash)
if len(hsh) != 64: #if len(hsh) != 64:
raise ValueError('chain hash must be 32 bytes') # raise ValueError('chain hash must be 32 bytes')
config.add(hsh, '_CHAIN_HASH') #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') config.add(config.get('_POSARG'), '_IDENTIFIER')
return config return config
@ -56,7 +59,7 @@ flags = arg_flags.STD_WRITE | arg_flags.EXEC | arg_flags.WALLET
argparser = chainlib.eth.cli.ArgumentParser() argparser = chainlib.eth.cli.ArgumentParser()
argparser = process_args(argparser, arg, flags) 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') argparser.add_argument('identifier', type=str, help='Contract identifier to set')
args = argparser.parse_args() args = argparser.parse_args()