eth-accounts-index

Accounts index evm contract tooling with permissioned writes
Info | Log | Files | Refs

add.py (2560B)


      1 """Adds account entries to accounts index
      2 
      3 .. moduleauthor:: Louis Holbrook <dev@holbrook.no>
      4 .. pgp:: 0826EDA1702D1E87C6E2875121D2E7BB88C2A746 
      5 
      6 """
      7 
      8 # standard imports
      9 import os
     10 import json
     11 import argparse
     12 import logging
     13 import sys
     14 
     15 # external imports
     16 import chainlib.eth.cli
     17 from chainlib.chain import ChainSpec
     18 from chainlib.eth.connection import EthHTTPConnection
     19 from chainlib.eth.tx import receipt
     20 from chainlib.eth.address import to_checksum_address
     21 from chainlib.eth.cli.arg import (
     22         Arg,
     23         ArgFlag,
     24         process_args,
     25         )
     26 from chainlib.eth.cli.config import (
     27         Config,
     28         process_config,
     29         )
     30 from chainlib.eth.cli.log import process_log
     31 from chainlib.eth.settings import process_settings
     32 from chainlib.settings import ChainSettings
     33 
     34 # local imports
     35 from eth_accounts_index.registry import AccountRegistry
     36 
     37 logging.basicConfig(level=logging.WARNING)
     38 logg = logging.getLogger()
     39 
     40 
     41 def process_config_local(config, arg, args, flags):
     42     address = to_checksum_address(config.get('_POSARG'))
     43     config.add(address, '_ADDRESS')
     44     return config
     45 
     46 
     47 arg_flags = ArgFlag()
     48 arg = Arg(arg_flags)
     49 flags = arg_flags.STD_WRITE | arg_flags.EXEC 
     50 
     51 argparser = chainlib.eth.cli.ArgumentParser()
     52 argparser = process_args(argparser, arg, flags)
     53 argparser.add_argument('address', type=str, help='Address to add to registry')
     54 args = argparser.parse_args()
     55 
     56 logg = process_log(args, logg)
     57 
     58 config = Config()
     59 config = process_config(config, arg, args, flags, positional_name='address')
     60 config = process_config_local(config, arg, args, flags)
     61 logg.debug('config loaded:\n{}'.format(config))
     62 
     63 settings = ChainSettings()
     64 settings = process_settings(settings, config)
     65 logg.debug('settings loaded:\n{}'.format(settings))
     66 
     67 
     68 def main():
     69     conn = settings.get('CONN')
     70     c = AccountRegistry(
     71             settings.get('CHAIN_SPEC'),
     72             signer=settings.get('SIGNER'),
     73             gas_oracle=settings.get('FEE_ORACLE'),
     74             nonce_oracle=settings.get('NONCE_ORACLE'),
     75             )
     76 
     77     (tx_hash_hex, o) = c.add(
     78             settings.get('EXEC'),
     79             settings.get('SENDER_ADDRESS'),
     80             config.get('_ADDRESS'),
     81             )
     82 
     83     if settings.get('RPC_SEND'):
     84         conn.do(o)
     85         if config.true('_WAIT'):
     86             r = conn.wait(tx_hash_hex)
     87             if r['status'] == 0:
     88                 sys.stderr.write('EVM revert while deploying contract. Wish I had more to tell you')
     89                 sys.exit(1)
     90 
     91         print(tx_hash_hex)
     92     else:
     93         print(o)
     94 
     95 
     96 if __name__ == '__main__':
     97     main()