eth-address-index/python/eth_token_index/runnable/deploy.py

70 lines
1.8 KiB
Python
Raw Normal View History

2020-12-29 20:05:15 +01:00
"""Deploys the token symbol index
2020-12-21 23:00:45 +01:00
.. moduleauthor:: Louis Holbrook <dev@holbrook.no>
.. pgp:: 0826EDA1702D1E87C6E2875121D2E7BB88C2A746
"""
# standard imports
2021-03-22 17:11:20 +01:00
import sys
2020-12-21 23:00:45 +01:00
import os
import json
import argparse
import logging
# external imports
import chainlib.eth.cli
2021-02-19 15:35:33 +01:00
from chainlib.chain import ChainSpec
2021-03-22 17:11:20 +01:00
from chainlib.eth.tx import receipt
# local imports
from eth_token_index import TokenUniqueSymbolIndex
2020-12-21 23:00:45 +01:00
logging.basicConfig(level=logging.WARNING)
logg = logging.getLogger()
arg_flags = chainlib.eth.cli.argflag_std_write
argparser = chainlib.eth.cli.ArgumentParser(arg_flags)
2020-12-21 23:00:45 +01:00
args = argparser.parse_args()
config = chainlib.eth.cli.Config.from_args(args, arg_flags, default_fee_limit=TokenUniqueSymbolIndex.gas())
2020-12-21 23:00:45 +01:00
wallet = chainlib.eth.cli.Wallet()
wallet.from_config(config)
2021-01-10 22:03:26 +01:00
rpc = chainlib.eth.cli.Rpc(wallet=wallet)
conn = rpc.connect_by_config(config)
2021-01-10 22:03:26 +01:00
chain_spec = ChainSpec.from_chain_str(config.get('CHAIN_SPEC'))
2021-01-10 22:03:26 +01:00
2020-12-21 23:00:45 +01:00
def main():
signer = rpc.get_signer()
signer_address = rpc.get_sender_address()
2021-01-10 22:03:26 +01:00
gas_oracle = rpc.get_gas_oracle()
nonce_oracle = rpc.get_nonce_oracle()
2021-01-10 22:03:26 +01:00
2021-04-04 14:40:12 +02:00
c = TokenUniqueSymbolIndex(chain_spec, signer=signer, gas_oracle=gas_oracle, nonce_oracle=nonce_oracle)
2021-03-22 17:11:20 +01:00
(tx_hash_hex, o) = c.constructor(signer_address)
if config.get('_RPC_SEND'):
conn.do(o)
if config.get('_WAIT'):
r = conn.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)
else:
print(o)
2020-12-21 23:00:45 +01:00
if __name__ == '__main__':
main()