eth-owned

EIP-173 interface and tools for chainlib-eth
git clone git://holbrook.no/eth-owned.git
Info | Log | Files | Refs

void_deploy.py (4015B)


      1 """Deploys the void owner 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 json
     12 import argparse
     13 import logging
     14 
     15 # external imports
     16 from funga.eth.signer import EIP155Signer
     17 from funga.eth.keystore.dict import DictKeystore
     18 from chainlib.chain import ChainSpec
     19 from chainlib.eth.nonce import (
     20         RPCNonceOracle,
     21         OverrideNonceOracle,
     22         )
     23 from chainlib.eth.gas import (
     24         RPCGasOracle,
     25         OverrideGasOracle,
     26         )
     27 from chainlib.eth.connection import EthHTTPConnection
     28 from chainlib.eth.tx import receipt
     29 
     30 # local imports
     31 from eth_owned.void import VoidOwner
     32 
     33 logging.basicConfig(level=logging.WARNING)
     34 logg = logging.getLogger()
     35 
     36 script_dir = os.path.dirname(__file__)
     37 data_dir = os.path.join(script_dir, '..', 'data')
     38 
     39 argparser = argparse.ArgumentParser()
     40 argparser.add_argument('-p', '--provider', dest='p', default='http://localhost:8545', type=str, help='Web3 provider url (http only)')
     41 argparser.add_argument('-w', action='store_true', help='Wait for the last transaction to be confirmed')
     42 argparser.add_argument('-ww', action='store_true', help='Wait for every transaction to be confirmed')
     43 argparser.add_argument('-i', '--chain-spec', dest='i', type=str, default='evm:ethereum:1', help='Chain specification string')
     44 argparser.add_argument('-y', '--key-file', dest='y', type=str, help='Ethereum keystore file to use for signing')
     45 argparser.add_argument('-v', action='store_true', help='Be verbose')
     46 argparser.add_argument('-vv', action='store_true', help='Be more verbose')
     47 argparser.add_argument('-d', action='store_true', help='Dump RPC calls to terminal and do not send')
     48 argparser.add_argument('--gas-price', type=int, dest='gas_price', help='Override gas price')
     49 argparser.add_argument('--nonce', type=int, help='Override transaction nonce')
     50 argparser.add_argument('--env-prefix', default=os.environ.get('CONFINI_ENV_PREFIX'), dest='env_prefix', type=str, help='environment prefix for variables to overwrite configuration')
     51 args = argparser.parse_args()
     52 
     53 if args.vv:
     54     logg.setLevel(logging.DEBUG)
     55 elif args.v:
     56     logg.setLevel(logging.INFO)
     57 
     58 block_last = args.w
     59 block_all = args.ww
     60 
     61 passphrase_env = 'ETH_PASSPHRASE'
     62 if args.env_prefix != None:
     63     passphrase_env = args.env_prefix + '_' + passphrase_env
     64 passphrase = os.environ.get(passphrase_env)
     65 if passphrase == None:
     66     logg.warning('no passphrase given')
     67     passphrase=''
     68 
     69 signer_address = None
     70 keystore = DictKeystore()
     71 if args.y != None:
     72     logg.debug('loading keystore file {}'.format(args.y))
     73     signer_address = keystore.import_keystore_file(args.y, password=passphrase)
     74     logg.debug('now have key for signer address {}'.format(signer_address))
     75 signer = EIP155Signer(keystore)
     76 
     77 chain_spec = ChainSpec.from_chain_str(args.i)
     78 
     79 rpc = EthHTTPConnection(args.p)
     80 nonce_oracle = None
     81 if args.nonce != None:
     82     nonce_oracle = OverrideNonceOracle(signer_address, args.nonce)
     83 else:
     84     nonce_oracle = RPCNonceOracle(signer_address, rpc)
     85 
     86 gas_oracle = None
     87 if args.gas_price !=None:
     88     gas_oracle = OverrideGasOracle(price=args.gas_price, conn=rpc, code_callback=VoidOwner.gas)
     89 else:
     90     gas_oracle = RPCGasOracle(rpc, code_callback=VoidOwner.gas)
     91 
     92 dummy = args.d
     93 
     94 
     95 def main():
     96     c = VoidOwner(chain_spec, signer=signer, gas_oracle=gas_oracle, nonce_oracle=nonce_oracle)
     97     (tx_hash_hex, o) = c.constructor(signer_address)
     98     if dummy:
     99         print(tx_hash_hex)
    100         print(o)
    101     else:
    102         rpc.do(o)
    103         if block_last:
    104             r = rpc.wait(tx_hash_hex)
    105             if r['status'] == 0:
    106                 sys.stderr.write('EVM revert while deploying contract. Wish I had more to tell you')
    107                 sys.exit(1)
    108             # TODO: pass through translator for keys (evm tester uses underscore instead of camelcase)
    109             address = r['contractAddress']
    110 
    111             print(address)
    112         else:
    113             print(tx_hash_hex)
    114 
    115 
    116 if __name__ == '__main__':
    117     main()