erc20-faucet

ERC20 token faucet
Info | Log | Files | Refs

list.py (2309B)


      1 """Query faucet store
      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.error import JSONRPCException
     22 from chainlib.eth.address import to_checksum_address
     23 from hexathon import (
     24         add_0x,
     25         strip_0x,
     26         )
     27 
     28 # local imports
     29 from erc20_faucet import Faucet
     30 from erc20_faucet.faucet import SingleShotFaucet
     31 
     32 logging.basicConfig(level=logging.WARNING)
     33 logg = logging.getLogger()
     34 
     35 
     36 arg_flags = chainlib.eth.cli.argflag_std_write | chainlib.eth.cli.Flag.EXEC
     37 argparser = chainlib.eth.cli.ArgumentParser(arg_flags)
     38 argparser.add_positional('address', required=False, type=str, help='Check only whether given address has been used')
     39 args = argparser.parse_args()
     40 
     41 extra_args = {
     42     'address': None,
     43         }
     44 config = chainlib.eth.cli.Config.from_args(args, arg_flags, extra_args=extra_args, default_fee_limit=SingleShotFaucet.gas())
     45 
     46 wallet = chainlib.eth.cli.Wallet()
     47 wallet.from_config(config)
     48 
     49 rpc = chainlib.eth.cli.Rpc(wallet=wallet)
     50 conn = rpc.connect_by_config(config)
     51 
     52 chain_spec = ChainSpec.from_chain_str(config.get('CHAIN_SPEC'))
     53 
     54 
     55 def out_element(e, conn, w=sys.stdout):
     56     w.write(str(e[1]) + '\n')
     57 
     58 
     59 def element(ifc, conn, faucet_address, address, w=sys.stdout):
     60     o = ifc.usable_for(faucet_address, address)
     61     r =  conn.do(o)
     62     usable = ifc.parse_usable_for(r)
     63     if usable:
     64         out_element((0, address), conn, w)
     65 
     66 
     67 def main():
     68     faucet_address = to_checksum_address(config.get('_EXEC_ADDRESS'))
     69     if not config.true('_UNSAFE') and faucet_address != add_0x(config.get('_EXEC_ADDRESS')):
     70         raise ValueError('invalid checksum address for faucet')
     71 
     72     address = to_checksum_address(config.get('_EXEC_ADDRESS'))
     73     if not config.true('_UNSAFE') and address != add_0x(config.get('_EXEC_ADDRESS')):
     74         raise ValueError('invalid checksum address for faucet')
     75 
     76 
     77     c = Faucet(chain_spec)
     78     element(c, conn, faucet_address, address, w=sys.stdout)
     79 
     80 
     81 if __name__ == '__main__':
     82     main()