contract-registry

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

publish.py (2919B)


      1 """Deploys contract registry
      2 
      3 .. moduleauthor:: Louis Holbrook <dev@holbrook.no>
      4 .. pgp:: 0826EDA1702D1E87C6E2875121D2E7BB88C2A746 
      5 
      6 """
      7 
      8 # standard imports
      9 import sys
     10 import os
     11 import logging
     12 
     13 # external imports
     14 import chainlib.eth.cli
     15 from chainlib.chain import ChainSpec
     16 from chainlib.eth.connection import EthHTTPConnection
     17 from chainlib.eth.tx import receipt
     18 from chainlib.eth.cli.arg import (
     19         Arg,
     20         ArgFlag,
     21         process_args,
     22         )
     23 from chainlib.eth.cli.config import (
     24         Config,
     25         process_config,
     26         )
     27 from chainlib.eth.cli.log import process_log
     28 from chainlib.eth.settings import process_settings
     29 from chainlib.settings import ChainSettings
     30 from chainlib.eth.constant import ZERO_CONTENT
     31 
     32 # local imports
     33 from eth_contract_registry.registry import ContractRegistry
     34 
     35 logging.basicConfig(level=logging.WARNING)
     36 logg = logging.getLogger()
     37 
     38 
     39 def process_config_local(config, arg, args, flags):
     40     identifiers = args.identifier
     41     if len(identifiers) == 0:
     42         raise ValueError('at least one identifier must be defined')
     43     for idntfr in identifiers:
     44         if len(idntfr) > 32:
     45             raise ValueError('identifier must be max 32 characters')
     46     config.add(identifiers, '_IDENTIFIER')
     47     return config
     48 
     49 
     50 arg_flags = ArgFlag()
     51 arg = Arg(arg_flags)
     52 flags = arg_flags.STD_WRITE 
     53 
     54 argparser = chainlib.eth.cli.ArgumentParser()
     55 argparser = process_args(argparser, arg, flags)
     56 argparser.add_argument('--identifier', type=str, action='append', help='SHA256 of description metadata of contract deployer')
     57 args = argparser.parse_args()
     58 
     59 logg = process_log(args, logg)
     60 
     61 config = Config()
     62 config = process_config(config, arg, args, flags)
     63 config = process_config_local(config, arg, args, flags)
     64 logg.debug('config loaded:\n{}'.format(config))
     65 
     66 settings = ChainSettings()
     67 settings = process_settings(settings, config)
     68 logg.debug('settings loaded:\n{}'.format(settings))
     69 
     70 
     71 def main():
     72     conn = settings.get('CONN')
     73     c = ContractRegistry(
     74             settings.get('CHAIN_SPEC'),
     75             signer=settings.get('SIGNER'),
     76             gas_oracle=settings.get('FEE_ORACLE'),
     77             nonce_oracle=settings.get('NONCE_ORACLE'),
     78             )
     79 
     80     (tx_hash_hex, o) = c.constructor(
     81             settings.get('SENDER_ADDRESS'),
     82             identifier_strings=config.get('_IDENTIFIER'),
     83             )
     84 
     85     if settings.get('RPC_SEND'):
     86         conn.do(o)
     87         if config.true('_WAIT'):
     88             r = conn.wait(tx_hash_hex)
     89             if r['status'] == 0:
     90                 sys.stderr.write('EVM revert while deploying contract. Wish I had more to tell you')
     91                 sys.exit(1)
     92             # TODO: pass through translator for keys (evm tester uses underscore instead of camelcase)
     93             address = r['contractAddress']
     94 
     95             print(address)
     96         else:
     97             print(tx_hash_hex)
     98     else:
     99         print(o)
    100 
    101 
    102 if __name__ == '__main__':
    103     main()