publish.py (4768B)
1 """Deploys sarafu faucet 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 import chainlib.eth.cli 17 from chainlib.chain import ChainSpec 18 from chainlib.eth.connection import EthHTTPConnection 19 from chainlib.eth.tx import ( 20 receipt, 21 TxFactory, 22 ) 23 from chainlib.eth.constant import ZERO_ADDRESS 24 from chainlib.eth.address import to_checksum_address 25 from hexathon import ( 26 add_0x, 27 strip_0x, 28 ) 29 30 # local imports 31 from erc20_faucet.faucet import SingleShotFaucet 32 33 logging.basicConfig(level=logging.WARNING) 34 logg = logging.getLogger() 35 36 arg_flags = chainlib.eth.cli.argflag_std_write 37 argparser = chainlib.eth.cli.ArgumentParser(arg_flags) 38 argparser.add_argument('--overrider-address', type=str, dest='overrider_address', default=ZERO_ADDRESS, help='Overrider address') 39 argparser.add_argument('--account-index-address', type=str, dest='account_index_address', default=ZERO_ADDRESS, help='Account index contract address') 40 argparser.add_argument('--store-address', type=str, dest='store_address', help='Faucet store address') 41 argparser.add_argument('token_address', type=str, help='Mintable token address') 42 args = argparser.parse_args() 43 44 extra_args = { 45 'overrider_address': None, 46 'account_index_address': None, 47 'store_address': None, 48 'token_address': None, 49 } 50 config = chainlib.eth.cli.Config.from_args(args, arg_flags, extra_args=extra_args, default_fee_limit=SingleShotFaucet.gas()) 51 52 wallet = chainlib.eth.cli.Wallet() 53 wallet.from_config(config) 54 55 rpc = chainlib.eth.cli.Rpc(wallet=wallet) 56 conn = rpc.connect_by_config(config) 57 58 chain_spec = ChainSpec.from_chain_str(config.get('CHAIN_SPEC')) 59 args = argparser.parse_args() 60 61 62 def main(): 63 signer = rpc.get_signer() 64 signer_address = rpc.get_sender_address() 65 66 gas_oracle = rpc.get_gas_oracle() 67 nonce_oracle = rpc.get_nonce_oracle() 68 69 c = SingleShotFaucet(chain_spec, signer=signer, nonce_oracle=nonce_oracle, gas_oracle=gas_oracle) 70 71 store_address = None 72 try: 73 store_address = to_checksum_address(config.get('_STORE_ADDRESS')) 74 if not config.true('_UNSAFE') and store_address != add_0x(config.get('_STORE_ADDRESS')): 75 raise ValueError('invalid checksum address for store') 76 logg.debug('using store address {}'.format(store_address)) 77 except TypeError: 78 pass 79 80 account_index_address = to_checksum_address(config.get('_ACCOUNT_INDEX_ADDRESS')) 81 if not config.true('_UNSAFE') and account_index_address != add_0x(config.get('_ACCOUNT_INDEX_ADDRESS')): 82 raise ValueError('invalid checksum address for account index address') 83 84 token_address = None 85 try: 86 token_address = to_checksum_address(config.get('_TOKEN_ADDRESS')) 87 if not config.true('_UNSAFE') and token_address != add_0x(config.get('_TOKEN_ADDRESS')): 88 raise ValueError('invalid checksum address for token address') 89 except TypeError: 90 pass 91 92 overrider_address = to_checksum_address(config.get('_OVERRIDER_ADDRESS')) 93 if not config.true('_UNSAFE') and overrider_address != add_0x(config.get('_OVERRIDER_ADDRESS')): 94 raise ValueError('invalid checksum address for overrider address') 95 96 97 if store_address == None: 98 (tx_hash_hex, o) = c.store_constructor(signer_address) 99 if not config.get('_WAIT'): 100 print(o) 101 else: 102 conn.do(o) 103 r = conn.wait(tx_hash_hex) 104 if r['status'] == 0: 105 sys.stderr.write('EVM revert while deploying contract. Wish I had more to tell you') 106 sys.exit(1) 107 # TODO: pass through translator for keys (evm tester uses underscore instead of camelcase) 108 store_address = r['contractAddress'] 109 logg.info('deployed faucet store on {}'.format(store_address)) 110 print(store_address) 111 112 if store_address != None: 113 c = SingleShotFaucet(chain_spec, signer=signer, gas_oracle=gas_oracle, nonce_oracle=nonce_oracle) 114 (tx_hash_hex, o) = c.constructor(signer_address, token_address, store_address, account_index_address, [overrider_address]) 115 conn.do(o) 116 if config.get('_WAIT'): 117 r = conn.wait(tx_hash_hex) 118 if r['status'] == 0: 119 sys.stderr.write('EVM revert while deploying contract. Wish I had more to tell you') 120 sys.exit(1) 121 # TODO: pass through translator for keys (evm tester uses underscore instead of camelcase) 122 address = r['contractAddress'] 123 124 print(address) 125 else: 126 print(tx_hash_hex) 127 128 129 if __name__ == '__main__': 130 main()