gift.py (2631B)
1 """Set identifier value on contract registry 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 receipt 20 from chainlib.eth.constant import ZERO_CONTENT 21 from chainlib.eth.address import to_checksum_address 22 from hexathon import ( 23 add_0x, 24 strip_0x, 25 ) 26 27 # local imports 28 from erc20_faucet import Faucet 29 from erc20_faucet.faucet import SingleShotFaucet 30 31 logging.basicConfig(level=logging.WARNING) 32 logg = logging.getLogger() 33 34 arg_flags = chainlib.eth.cli.argflag_std_write | chainlib.eth.cli.Flag.EXEC 35 argparser = chainlib.eth.cli.ArgumentParser(arg_flags) 36 argparser.add_positional('address', type=str, help='Contract address to invoke faucet for') 37 args = argparser.parse_args() 38 39 extra_args = { 40 'address': None, 41 } 42 config = chainlib.eth.cli.Config.from_args(args, arg_flags, extra_args=extra_args, default_fee_limit=SingleShotFaucet.gas()) 43 44 wallet = chainlib.eth.cli.Wallet() 45 wallet.from_config(config) 46 47 rpc = chainlib.eth.cli.Rpc(wallet=wallet) 48 conn = rpc.connect_by_config(config) 49 50 chain_spec = ChainSpec.from_chain_str(config.get('CHAIN_SPEC')) 51 52 53 def main(): 54 55 signer = rpc.get_signer() 56 signer_address = rpc.get_sender_address() 57 58 gas_oracle = rpc.get_gas_oracle() 59 nonce_oracle = rpc.get_nonce_oracle() 60 61 c = Faucet(chain_spec, signer=signer, nonce_oracle=nonce_oracle, gas_oracle=gas_oracle) 62 63 faucet_address = to_checksum_address(config.get('_EXEC_ADDRESS')) 64 if not config.true('_UNSAFE') and faucet_address != add_0x(config.get('_EXEC_ADDRESS')): 65 raise ValueError('invalid checksum address for faucet') 66 67 address = config.get('_ADDRESS') 68 if address == None: 69 address = signer_address 70 else: 71 address = to_checksum_address(address) 72 if not config.true('_UNSAFE') and address != add_0x(config.get('_EXEC_ADDRESS')): 73 raise ValueError('invalid checksum address for faucet') 74 75 (tx_hash_hex, o) = c.give_to(faucet_address, signer_address, address) 76 77 if config.get('_RPC_SEND'): 78 conn.do(o) 79 if config.get('_WAIT'): 80 r = conn.wait(tx_hash_hex) 81 if r['status'] == 0: 82 sys.stderr.write('EVM revert while deploying contract. Wish I had more to tell you') 83 sys.exit(1) 84 85 print(tx_hash_hex) 86 else: 87 print(o) 88 89 90 if __name__ == '__main__': 91 main()