2021-03-25 09:27:31 +01:00
|
|
|
"""Set identifier value on contract registry
|
|
|
|
|
|
|
|
.. moduleauthor:: Louis Holbrook <dev@holbrook.no>
|
|
|
|
.. pgp:: 0826EDA1702D1E87C6E2875121D2E7BB88C2A746
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
# standard imports
|
|
|
|
import sys
|
|
|
|
import os
|
|
|
|
import logging
|
|
|
|
|
2021-07-30 08:13:47 +02:00
|
|
|
# external imports
|
|
|
|
import chainlib.eth.cli
|
2021-03-25 09:27:31 +01:00
|
|
|
from chainlib.chain import ChainSpec
|
|
|
|
from chainlib.eth.tx import receipt
|
|
|
|
from chainlib.eth.constant import ZERO_CONTENT
|
2023-02-12 14:52:32 +01:00
|
|
|
from chainlib.eth.constant import ZERO_ADDRESS
|
2021-03-25 09:27:31 +01:00
|
|
|
from chainlib.error import JSONRPCException
|
2021-07-30 08:13:47 +02:00
|
|
|
from chainlib.eth.address import to_checksum_address
|
|
|
|
from hexathon import (
|
|
|
|
add_0x,
|
|
|
|
strip_0x,
|
|
|
|
)
|
2023-02-11 07:29:38 +01:00
|
|
|
from chainlib.eth.cli.arg import (
|
|
|
|
Arg,
|
|
|
|
ArgFlag,
|
|
|
|
process_args,
|
|
|
|
)
|
|
|
|
from chainlib.eth.cli.config import (
|
|
|
|
Config,
|
|
|
|
process_config,
|
|
|
|
)
|
|
|
|
from chainlib.eth.cli.log import process_log
|
|
|
|
from chainlib.eth.settings import process_settings
|
|
|
|
from chainlib.settings import ChainSettings
|
|
|
|
|
2021-03-25 09:27:31 +01:00
|
|
|
# local imports
|
2021-04-30 22:03:48 +02:00
|
|
|
from eth_contract_registry.registry import ContractRegistry
|
2021-03-25 09:27:31 +01:00
|
|
|
|
|
|
|
logging.basicConfig(level=logging.WARNING)
|
|
|
|
logg = logging.getLogger()
|
|
|
|
|
2023-02-11 07:29:38 +01:00
|
|
|
|
|
|
|
def process_config_local(config, arg, args, flags):
|
|
|
|
config.add(config.get('_POSARG'), '_IDENTIFIER')
|
|
|
|
return config
|
|
|
|
|
|
|
|
|
|
|
|
arg_flags = ArgFlag()
|
|
|
|
arg = Arg(arg_flags)
|
|
|
|
flags = arg_flags.STD_READ | arg_flags.EXEC
|
|
|
|
|
|
|
|
argparser = chainlib.eth.cli.ArgumentParser()
|
|
|
|
argparser = process_args(argparser, arg, flags)
|
|
|
|
argparser.add_argument('identifier', type=str, help='Contract identifier to look up')
|
2021-03-25 09:27:31 +01:00
|
|
|
args = argparser.parse_args()
|
|
|
|
|
2023-02-11 07:29:38 +01:00
|
|
|
logg = process_log(args, logg)
|
|
|
|
|
|
|
|
config = Config()
|
|
|
|
config = process_config(config, arg, args, flags, positional_name='identifier')
|
|
|
|
config = process_config_local(config, arg, args, flags)
|
|
|
|
logg.debug('config loaded:\n{}'.format(config))
|
|
|
|
|
|
|
|
settings = ChainSettings()
|
|
|
|
settings = process_settings(settings, config)
|
|
|
|
logg.debug('settings loaded:\n{}'.format(settings))
|
2021-03-25 09:27:31 +01:00
|
|
|
|
|
|
|
|
2021-07-30 08:13:47 +02:00
|
|
|
def out_element(e, w=sys.stdout):
|
2021-08-24 21:28:17 +02:00
|
|
|
if config.get('_RAW'):
|
|
|
|
w.write(e[1] + '\n')
|
|
|
|
else:
|
|
|
|
w.write(e[0] + '\t' + e[1] + '\n')
|
2021-03-25 09:27:31 +01:00
|
|
|
|
|
|
|
|
2023-02-13 08:48:14 +01:00
|
|
|
def element(ifc, conn, registry_address, identifier, w=sys.stdout, sender_address=ZERO_ADDRESS):
|
|
|
|
o = ifc.address_of(registry_address, identifier, sender_address=sender_address)
|
2021-07-30 08:13:47 +02:00
|
|
|
r = conn.do(o)
|
2021-03-25 09:27:31 +01:00
|
|
|
address = ifc.parse_address_of(r)
|
2021-07-30 08:13:47 +02:00
|
|
|
out_element((identifier, address), w)
|
2021-03-25 09:27:31 +01:00
|
|
|
|
|
|
|
|
2023-02-13 08:48:14 +01:00
|
|
|
def ls(ifc, conn, registry_address, w=sys.stdout, sender_address=ZERO_ADDRESS):
|
2021-03-25 09:27:31 +01:00
|
|
|
i = 0
|
|
|
|
while True:
|
2023-02-13 08:48:14 +01:00
|
|
|
o = ifc.identifier(registry_address, i, sender_address=sender_address)
|
2021-03-25 09:27:31 +01:00
|
|
|
try:
|
2021-07-30 08:13:47 +02:00
|
|
|
r = conn.do(o)
|
2021-03-25 09:27:31 +01:00
|
|
|
identifier = ifc.parse_identifier(r)
|
2021-07-30 08:13:47 +02:00
|
|
|
element(ifc, conn, registry_address, identifier, w)
|
2021-03-25 09:27:31 +01:00
|
|
|
i += 1
|
|
|
|
except JSONRPCException:
|
|
|
|
break
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
2023-02-11 07:29:38 +01:00
|
|
|
c = ContractRegistry(
|
|
|
|
settings.get('CHAIN_SPEC')
|
|
|
|
)
|
2021-07-30 08:13:47 +02:00
|
|
|
|
|
|
|
identifier = config.get('_IDENTIFIER')
|
|
|
|
|
|
|
|
registry_address = to_checksum_address(config.get('_EXEC_ADDRESS'))
|
2021-11-16 05:48:53 +01:00
|
|
|
if not config.true('_UNSAFE') and strip_0x(registry_address) != strip_0x(config.get('_EXEC_ADDRESS')):
|
2021-07-30 08:13:47 +02:00
|
|
|
raise ValueError('invalid checksum address for contract')
|
|
|
|
|
2021-03-25 09:27:31 +01:00
|
|
|
if identifier != None:
|
2023-02-11 07:29:38 +01:00
|
|
|
element(
|
|
|
|
c,
|
|
|
|
settings.get('CONN'),
|
|
|
|
settings.get('EXEC'),
|
|
|
|
config.get('_IDENTIFIER'),
|
|
|
|
w=sys.stdout,
|
2023-02-13 08:48:14 +01:00
|
|
|
sender_address=settings.get('SENDER_ADDRESS'),
|
2023-02-11 07:29:38 +01:00
|
|
|
)
|
2021-03-25 09:27:31 +01:00
|
|
|
else:
|
2023-02-11 07:29:38 +01:00
|
|
|
ls(
|
|
|
|
c,
|
|
|
|
settings.get('CONN'),
|
|
|
|
settings.get('EXEC'),
|
|
|
|
w=sys.stdout,
|
2023-02-13 08:48:14 +01:00
|
|
|
sender_address=settings.get('SENDER_ADDRESS'),
|
2023-02-11 07:29:38 +01:00
|
|
|
)
|
2021-03-25 09:27:31 +01:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|