eth-accounts-index/python/eth_accounts_index/runnable/deploy.py

118 lines
4.0 KiB
Python
Raw Normal View History

2020-12-01 13:08:14 +01:00
"""Deploys accounts index, registering arbitrary number of writers
.. moduleauthor:: Louis Holbrook <dev@holbrook.no>
.. pgp:: 0826EDA1702D1E87C6E2875121D2E7BB88C2A746
"""
# standard imports
2021-03-31 16:07:23 +02:00
import sys
2020-12-01 23:51:17 +01:00
import os
2020-12-01 13:08:14 +01:00
import json
import argparse
import logging
# third-party imports
2021-01-10 20:40:29 +01:00
from crypto_dev_signer.eth.signer import ReferenceSigner as EIP155Signer
2021-03-31 16:07:23 +02:00
from crypto_dev_signer.keystore.dict import DictKeystore
2021-02-19 20:17:15 +01:00
from chainlib.chain import ChainSpec
2021-04-12 16:25:22 +02:00
from chainlib.eth.nonce import (
RPCNonceOracle,
OverrideNonceOracle,
)
from chainlib.eth.gas import (
RPCGasOracle,
OverrideGasOracle,
)
2021-03-31 16:07:23 +02:00
from chainlib.eth.connection import EthHTTPConnection
from chainlib.eth.tx import receipt
# local imports
2021-04-30 13:14:48 +02:00
from eth_accounts_index.registry import AccountRegistry
2020-12-01 13:08:14 +01:00
logging.basicConfig(level=logging.WARNING)
logg = logging.getLogger()
script_dir = os.path.dirname(__file__)
data_dir = os.path.join(script_dir, '..', 'data')
2020-12-01 13:08:14 +01:00
argparser = argparse.ArgumentParser()
argparser.add_argument('-p', '--provider', dest='p', default='http://localhost:8545', type=str, help='Web3 provider url (http only)')
2021-01-10 20:40:29 +01:00
argparser.add_argument('-w', action='store_true', help='Wait for the last transaction to be confirmed')
argparser.add_argument('-ww', action='store_true', help='Wait for every transaction to be confirmed')
2021-04-04 14:54:17 +02:00
argparser.add_argument('-i', '--chain-spec', dest='i', type=str, default='evm:ethereum:1', help='Chain specification string')
2021-01-10 20:40:29 +01:00
argparser.add_argument('-y', '--key-file', dest='y', type=str, help='Ethereum keystore file to use for signing')
2020-12-01 13:08:14 +01:00
argparser.add_argument('-v', action='store_true', help='Be verbose')
2021-01-10 20:40:29 +01:00
argparser.add_argument('-vv', action='store_true', help='Be more verbose')
2021-04-12 16:25:22 +02:00
argparser.add_argument('-d', action='store_true', help='Dump RPC calls to terminal and do not send')
argparser.add_argument('--gas-price', type=int, dest='gas_price', help='Override gas price')
argparser.add_argument('--nonce', type=int, help='Override transaction nonce')
2021-03-31 16:07:23 +02:00
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')
2020-12-01 13:08:14 +01:00
args = argparser.parse_args()
2021-01-10 20:40:29 +01:00
if args.vv:
2020-12-01 13:08:14 +01:00
logg.setLevel(logging.DEBUG)
2021-01-10 20:40:29 +01:00
elif args.v:
logg.setLevel(logging.INFO)
2021-04-30 22:04:34 +02:00
block_all = args.ww
block_last = args.w or block_all
2021-01-10 20:40:29 +01:00
2021-03-31 16:07:23 +02:00
passphrase_env = 'ETH_PASSPHRASE'
if args.env_prefix != None:
passphrase_env = args.env_prefix + '_' + passphrase_env
passphrase = os.environ.get(passphrase_env)
if passphrase == None:
logg.warning('no passphrase given')
passphrase=''
2021-01-10 20:40:29 +01:00
signer_address = None
keystore = DictKeystore()
if args.y != None:
logg.debug('loading keystore file {}'.format(args.y))
2021-03-31 16:07:23 +02:00
signer_address = keystore.import_keystore_file(args.y, password=passphrase)
2021-01-10 20:40:29 +01:00
logg.debug('now have key for signer address {}'.format(signer_address))
signer = EIP155Signer(keystore)
2021-02-19 20:17:15 +01:00
chain_spec = ChainSpec.from_chain_str(args.i)
2021-01-10 20:40:29 +01:00
2021-03-31 16:07:23 +02:00
rpc = EthHTTPConnection(args.p)
2021-04-12 16:25:22 +02:00
nonce_oracle = None
if args.nonce != None:
nonce_oracle = OverrideNonceOracle(signer_address, args.nonce)
else:
nonce_oracle = RPCNonceOracle(signer_address, rpc)
gas_oracle = None
if args.gas_price !=None:
gas_oracle = OverrideGasOracle(price=args.gas_price, conn=rpc, code_callback=AccountRegistry.gas)
else:
gas_oracle = RPCGasOracle(rpc, code_callback=AccountRegistry.gas)
dummy = args.d
2020-12-01 13:08:14 +01:00
2021-01-10 20:40:29 +01:00
def main():
2021-04-04 14:54:17 +02:00
c = AccountRegistry(chain_spec, signer=signer, gas_oracle=gas_oracle, nonce_oracle=nonce_oracle)
2021-03-31 16:07:23 +02:00
(tx_hash_hex, o) = c.constructor(signer_address)
2021-04-12 16:25:22 +02:00
if dummy:
2021-03-31 16:07:23 +02:00
print(tx_hash_hex)
2021-04-12 16:25:22 +02:00
print(o)
else:
rpc.do(o)
if block_last:
r = rpc.wait(tx_hash_hex)
if r['status'] == 0:
sys.stderr.write('EVM revert while deploying contract. Wish I had more to tell you')
sys.exit(1)
# TODO: pass through translator for keys (evm tester uses underscore instead of camelcase)
address = r['contractAddress']
print(address)
else:
print(tx_hash_hex)
2020-12-01 13:08:14 +01:00
2020-12-01 23:51:17 +01:00
if __name__ == '__main__':
main()