chainlib-eth

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

decode.py (2367B)


      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 import chainlib.eth.cli
     13 from chainlib.eth.tx import unpack
     14 from chainlib.settings import ChainSettings
     15 from chainlib.chain import ChainSpec
     16 from hexathon import (
     17         strip_0x,
     18         )
     19 
     20 # local imports
     21 import chainlib.eth.cli
     22 from chainlib.eth.cli.decode import decode_for_puny_humans
     23 from chainlib.eth.cli.arg import (
     24         Arg,
     25         ArgFlag,
     26         process_args,
     27         stdin_arg,
     28         )
     29 from chainlib.eth.cli.config import (
     30         Config,
     31         process_config,
     32         )
     33 from chainlib.eth.cli.log import process_log
     34 from chainlib.eth.settings import process_settings
     35 
     36 
     37 logging.basicConfig(level=logging.WARNING)
     38 logg = logging.getLogger()
     39 
     40 script_dir = os.path.dirname(os.path.realpath(__file__)) 
     41 config_dir = os.path.join(script_dir, '..', 'data', 'config')
     42 
     43 
     44 def process_config_local(config, arg, args, flags):
     45     data = config.get('_POSARG')
     46 
     47     try:
     48         data = strip_0x(data)
     49     except TypeError:
     50         data = stdin_arg()
     51         data = strip_0x(data)
     52 
     53     config.add(data, '_TX_DATA', False)
     54     
     55     # workaround to avoid rpc lookup of fee parameters when using arg mode
     56     config.add(0, '_FEE_PRICE', True)
     57     config.add(0, '_FEE_LIMIT', True)
     58     return config
     59 
     60 
     61 arg_flags = ArgFlag()
     62 arg = Arg(arg_flags)
     63 flags = arg_flags.VERBOSE | arg_flags.CHAIN_SPEC | arg_flags.RAW | arg_flags.ENV | arg_flags.SEQ | arg_flags.TAB
     64 
     65 argparser = chainlib.eth.cli.ArgumentParser()
     66 argparser = process_args(argparser, arg, flags)
     67 argparser.add_argument('tx_data', type=str, help='Transaction data to decode')
     68 args = argparser.parse_args()
     69 
     70 logg = process_log(args, logg)
     71 
     72 config = Config()
     73 config = process_config(config, arg, args, flags, positional_name='tx_data')
     74 config = process_config_local(config, arg, args, flags)
     75 logg.debug('config loaded:\n{}'.format(config))
     76 
     77 settings = ChainSettings()
     78 settings = process_settings(settings, config)
     79 logg.debug('settings loaded:\n{}'.format(settings))
     80 
     81 
     82 def main():
     83     decode_for_puny_humans(
     84             config.get('_TX_DATA'),
     85             settings.get('CHAIN_SPEC'),
     86             sys.stdout,
     87             fields=config.get('_OUTARG'),
     88             skip_keys=config.true('_RAW'),
     89             )
     90 
     91 if __name__ == '__main__':
     92     main()