chainlib-eth

Ethereum implementation of the chainlib interface
Info | Log | Files | Refs | README | LICENSE

count.py (2364B)


      1 # SPDX-License-Identifier: GPL-3.0-or-later
      2 
      3 # standard imports
      4 import sys
      5 import os
      6 import json
      7 #import argparse
      8 import logging
      9 import select
     10 
     11 # external imports
     12 from chainlib.settings import ChainSettings
     13 from chainlib.chain import ChainSpec
     14 from chainlib.jsonrpc import IntSequenceGenerator
     15 from funga.eth.keystore.dict import DictKeystore
     16 from funga.eth.signer import EIP155Signer
     17 from hexathon import add_0x
     18 
     19 # local imports
     20 import chainlib.eth.cli
     21 from chainlib.eth.cli.arg import (
     22         Arg,
     23         ArgFlag,
     24         process_args,
     25         )
     26 from chainlib.eth.cli.config import (
     27         Config,
     28         process_config,
     29         )
     30 from chainlib.eth.cli.log import process_log
     31 from chainlib.eth.address import AddressChecksum
     32 from chainlib.eth.connection import EthHTTPConnection
     33 from chainlib.eth.tx import count
     34 from chainlib.eth.settings import process_settings
     35 
     36 logg = logging.getLogger()
     37 
     38 script_dir = os.path.dirname(os.path.realpath(__file__)) 
     39 config_dir = os.path.join(script_dir, '..', 'data', 'config')
     40 
     41 
     42 def process_config_local(config, arg, args, flags):
     43     recipient = config.get('_POSARG')
     44     config.add(recipient, '_RECIPIENT', False)
     45     return config
     46 
     47 
     48 argparser = chainlib.eth.cli.ArgumentParser()
     49 arg_flags = ArgFlag()
     50 arg = Arg(arg_flags)
     51 flags = arg_flags.STD_BASE_READ | arg_flags.WALLET | arg_flags.UNSAFE
     52 argparser = process_args(argparser, arg, flags)
     53 
     54 argparser.add_argument('address', type=str, help='Ethereum address of recipient')
     55 args = argparser.parse_args()
     56 
     57 logg = process_log(args, logg)
     58 logg.debug('flags {} {} {}'.format(flags, arg_flags.SEQ, flags & arg_flags.SEQ))
     59 
     60 config = Config()
     61 config = process_config(config, arg, args, flags, positional_name='address')
     62 config = process_config_local(config, arg, args, flags)
     63 logg.debug('config loaded:\n{}'.format(config))
     64 
     65 settings = ChainSettings()
     66 settings = process_settings(settings, config)
     67 logg.debug('settings loaded:\n{}'.format(settings))
     68 
     69 
     70 def main():
     71     # TODO: should tolerate if address not prefixed with 0x 
     72     o = count(
     73             settings.get('RECIPIENT'),
     74             id_generator=settings.get('RPC_ID_GENERATOR'),
     75             )
     76     r = settings.get('CONN').do(o)
     77     count_result = None
     78     try:
     79         count_result = int(r, 16)
     80     except ValueError:
     81         count_result = int(r, 10)
     82     print(count_result)
     83 
     84 
     85 if __name__ == '__main__':
     86     main()