chainlib/chainlib/eth/runnable/decode.py

65 lines
1.6 KiB
Python
Raw Normal View History

2021-02-08 11:23:07 +01:00
#!python3
"""Decode raw transaction
.. moduleauthor:: Louis Holbrook <dev@holbrook.no>
.. pgp:: 0826EDA1702D1E87C6E2875121D2E7BB88C2A746
"""
# SPDX-License-Identifier: GPL-3.0-or-later
# standard imports
2021-04-04 14:55:27 +02:00
import sys
2021-02-08 11:23:07 +01:00
import os
import json
import argparse
import logging
import select
2021-02-08 11:23:07 +01:00
# external imports
2021-02-17 10:13:22 +01:00
from chainlib.eth.tx import unpack
from chainlib.chain import ChainSpec
2021-02-08 11:23:07 +01:00
2021-04-04 14:55:27 +02:00
# local imports
from chainlib.eth.runnable.util import decode_for_puny_humans
2021-02-08 11:23:07 +01:00
logging.basicConfig(level=logging.WARNING)
logg = logging.getLogger()
default_abi_dir = os.environ.get('ETH_ABI_DIR', '/usr/share/local/cic/solidity/abi')
default_eth_provider = os.environ.get('ETH_PROVIDER', 'http://localhost:8545')
def stdin_arg():
h = select.select([sys.stdin], [], [], 0)
if len(h[0]) > 0:
v = h[0][0].read()
return v.rstrip()
return None
2021-02-08 11:23:07 +01:00
argparser = argparse.ArgumentParser()
2021-04-04 14:55:27 +02:00
argparser.add_argument('-i', '--chain-id', dest='i', default='evm:ethereum:1', type=str, help='Numeric network id')
argparser.add_argument('tx', type=str, nargs='?', default=stdin_arg(), help='hex-encoded signed raw transaction')
argparser.add_argument('-v', action='store_true', help='Be verbose')
argparser.add_argument('-vv', action='store_true', help='Be more verbose')
2021-02-08 11:23:07 +01:00
args = argparser.parse_args()
if args.tx == None:
argparser.error('need first positional argument or value from stdin')
if args.vv:
2021-02-08 11:23:07 +01:00
logg.setLevel(logging.DEBUG)
elif args.v:
logg.setLevel(logging.INFO)
2021-02-08 11:23:07 +01:00
chain_spec = ChainSpec.from_chain_str(args.i)
2021-02-08 11:23:07 +01:00
def main():
tx_raw = args.tx
2021-04-04 14:55:27 +02:00
decode_for_puny_humans(tx_raw, chain_spec, sys.stdout)
2021-02-08 11:23:07 +01:00
if __name__ == '__main__':
main()