eth-owned

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

void.py (4216B)


      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.owned import Owned
     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('-a', '--contract-address', dest='a', required=True, type=str, help='Void owner contract address')
     46 argparser.add_argument('-v', action='store_true', help='Be verbose')
     47 argparser.add_argument('-vv', action='store_true', help='Be more verbose')
     48 #argparser.add_argument('-d', action='store_true', help='Dump RPC calls to terminal and do not send')
     49 argparser.add_argument('--gas-price', type=int, dest='gas_price', help='Override gas price')
     50 argparser.add_argument('--nonce', type=int, help='Override transaction nonce')
     51 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')
     52 argparser.add_argument('address_to_void', type=str, help='EIP172 enabled contract to void ownership for')
     53 args = argparser.parse_args()
     54 
     55 if args.vv:
     56     logg.setLevel(logging.DEBUG)
     57 elif args.v:
     58     logg.setLevel(logging.INFO)
     59 
     60 block_last = args.w
     61 block_all = args.ww
     62 
     63 passphrase_env = 'ETH_PASSPHRASE'
     64 if args.env_prefix != None:
     65     passphrase_env = args.env_prefix + '_' + passphrase_env
     66 passphrase = os.environ.get(passphrase_env)
     67 if passphrase == None:
     68     logg.warning('no passphrase given')
     69     passphrase=''
     70 
     71 signer_address = None
     72 keystore = DictKeystore()
     73 if args.y != None:
     74     logg.debug('loading keystore file {}'.format(args.y))
     75     signer_address = keystore.import_keystore_file(args.y, password=passphrase)
     76     logg.debug('now have key for signer address {}'.format(signer_address))
     77 signer = EIP155Signer(keystore)
     78 
     79 chain_spec = ChainSpec.from_chain_str(args.i)
     80 
     81 rpc = EthHTTPConnection(args.p)
     82 nonce_oracle = None
     83 if args.nonce != None:
     84     nonce_oracle = OverrideNonceOracle(signer_address, args.nonce)
     85 else:
     86     nonce_oracle = RPCNonceOracle(signer_address, rpc)
     87 
     88 gas_oracle = None
     89 if args.gas_price !=None:
     90     gas_oracle = OverrideGasOracle(price=args.gas_price, conn=rpc, code_callback=VoidOwner.gas)
     91 else:
     92     gas_oracle = RPCGasOracle(rpc, code_callback=VoidOwner.gas)
     93 
     94 #dummy = args.d
     95 address_to_void = args.address_to_void
     96 void_receiver_address = args.a
     97 
     98 
     99 def main():
    100     c = Owned(chain_spec, signer=signer, gas_oracle=gas_oracle, nonce_oracle=nonce_oracle)
    101     (tx_hash_hex, o) = c.transfer_ownership(signer_address, address_to_void)
    102     rpc.do(o)
    103     r = rpc.wait(tx_hash_hex)
    104     if r['status'] == 0:
    105         sys.stderr.write('EVM revert while transferring ownership')
    106         sys.exit(1)
    107 
    108     (tx_hash_hex, o) = c.take_ownership(signer_address, void_receiver_address)
    109     rpc.do(o)
    110     r = rpc.wait(tx_hash_hex)
    111     if r['status'] == 0:
    112         sys.stderr.write('EVM revert while taking ownership')
    113         sys.exit(1)
    114 
    115     print(tx_hash_hex)
    116 
    117 
    118 if __name__ == '__main__':
    119     main()