eth-address-index

signed metadata declarations for ethereum addresses
Log | Files | Refs

publish.py (3085B)


      1 """Deploys address declaration contract
      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 from hexathon import (
     13         add_0x,
     14         strip_0x,
     15         )
     16 
     17 # external imports
     18 import chainlib.eth.cli
     19 from chainlib.chain import ChainSpec
     20 from chainlib.eth.connection import EthHTTPConnection
     21 from chainlib.eth.tx import receipt
     22 from chainlib.eth.cli.arg import (
     23         Arg,
     24         ArgFlag,
     25         process_args,
     26         )
     27 from chainlib.eth.cli.config import (
     28         Config,
     29         process_config,
     30         )
     31 from chainlib.eth.cli.log import process_log
     32 from chainlib.eth.settings import process_settings
     33 from chainlib.settings import ChainSettings
     34 from chainlib.eth.constant import ZERO_CONTENT
     35 
     36 # local imports
     37 from eth_address_declarator.declarator import AddressDeclarator
     38 
     39 logging.basicConfig(level=logging.WARNING)
     40 logg = logging.getLogger()
     41 
     42 
     43 def process_config_local(config, arg, args, flags):
     44     hsh = args.owner_description_hash
     45     if hsh == None:
     46         hsh = ZERO_CONTENT
     47     hsh = add_0x(hsh)
     48     config.add(hsh, '_OWNER_DESCRIPTION_HASH')
     49     return config
     50 
     51 
     52 arg_flags = ArgFlag()
     53 arg = Arg(arg_flags)
     54 flags = arg_flags.STD_WRITE 
     55 
     56 argparser = chainlib.eth.cli.ArgumentParser()
     57 argparser = process_args(argparser, arg, flags)
     58 argparser.add_argument('--owner-description-hash', type=str, help='SHA256 of description metadata of contract deployer')
     59 args = argparser.parse_args()
     60 
     61 logg = process_log(args, logg)
     62 
     63 config = Config()
     64 config = process_config(config, arg, args, flags)
     65 config = process_config_local(config, arg, args, flags)
     66 logg.debug('config loaded:\n{}'.format(config))
     67 
     68 settings = ChainSettings()
     69 settings = process_settings(settings, config)
     70 logg.debug('settings loaded:\n{}'.format(settings))
     71 
     72 
     73 def main():
     74     conn = settings.get('CONN')
     75     c = AddressDeclarator(
     76             settings.get('CHAIN_SPEC'),
     77             signer=settings.get('SIGNER'),
     78             gas_oracle=settings.get('FEE_ORACLE'),
     79             nonce_oracle=settings.get('NONCE_ORACLE'),
     80             )
     81     owner_description_hash = config.get('_OWNER_DESCRIPTION_HASH')
     82     owner_description_hash_bytes = bytes.fromhex(strip_0x(owner_description_hash))
     83     if len(owner_description_hash_bytes) != 32:
     84         raise ValueError('chain config hash must be 32 bytes')
     85 
     86     (tx_hash_hex, o) = c.constructor(
     87             settings.get('SENDER_ADDRESS'),
     88             owner_description_hash,
     89             )
     90     if settings.get('RPC_SEND'):
     91         conn.do(o)
     92         if config.true('_WAIT'):
     93             r = conn.wait(tx_hash_hex)
     94             if r['status'] == 0:
     95                 sys.stderr.write('EVM revert while deploying contract. Wish I had more to tell you')
     96                 sys.exit(1)
     97             # TODO: pass through translator for keys (evm tester uses underscore instead of camelcase)
     98             address = r['contractAddress']
     99 
    100             print(address)
    101         else:
    102             print(tx_hash_hex)
    103     else:
    104         print(o)
    105 
    106 
    107 if __name__ == '__main__':
    108     main()