From 1e735798241c739531f6deea06d4b4806e9df374 Mon Sep 17 00:00:00 2001 From: nolash Date: Tue, 15 Jun 2021 11:22:36 +0200 Subject: [PATCH] Revert "Add stdin input to replace single positional argument" This reverts commit 494cb1e0aff331bbfdfae5e99c4b269aa3d6d60c. --- MANIFEST.in | 2 +- chainlib/eth/runnable/checksum.py | 20 +------------------- chainlib/eth/runnable/count.py | 17 +++-------------- chainlib/eth/runnable/decode.py | 22 ++++------------------ chainlib/eth/runnable/get.py | 15 ++------------- 5 files changed, 11 insertions(+), 65 deletions(-) diff --git a/MANIFEST.in b/MANIFEST.in index 829a7e6..f9bd145 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1 +1 @@ -include *requirements.txt LICENSE +include requirements.txt diff --git a/chainlib/eth/runnable/checksum.py b/chainlib/eth/runnable/checksum.py index 8a9daca..ad0d2c6 100644 --- a/chainlib/eth/runnable/checksum.py +++ b/chainlib/eth/runnable/checksum.py @@ -1,6 +1,5 @@ # standard imports import sys -import select # external imports from hexathon import strip_0x @@ -8,25 +7,8 @@ from hexathon import strip_0x # local imports from chainlib.eth.address import to_checksum_address -v = None -if len(sys.argv) > 1: - v = sys.argv[1] -else: - h = select.select([sys.stdin], [], [], 0) - if len(h[0]) > 0: - v = h[0][0].read() - v = v.rstrip() - -if v == None: - sys.stderr.write('input missing\n') - sys.exit(1) - def main(): - try: - print(to_checksum_address(strip_0x(v))) - except ValueError as e: - sys.stderr.write('invalid input: {}\n'.format(e)) - sys.exit(1) + print(to_checksum_address(strip_0x(sys.argv[1]))) if __name__ == '__main__': diff --git a/chainlib/eth/runnable/count.py b/chainlib/eth/runnable/count.py index 13e037f..969d207 100644 --- a/chainlib/eth/runnable/count.py +++ b/chainlib/eth/runnable/count.py @@ -6,7 +6,6 @@ import os import json import argparse import logging -import select # local imports from chainlib.eth.address import to_checksum @@ -15,20 +14,12 @@ from chainlib.eth.tx import count from chainlib.chain import ChainSpec from crypto_dev_signer.keystore.dict import DictKeystore from crypto_dev_signer.eth.signer import ReferenceSigner as EIP155Signer -from hexathon import add_0x logging.basicConfig(level=logging.WARNING) logg = logging.getLogger() 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 - argparser = argparse.ArgumentParser() argparser.add_argument('-p', '--provider', dest='p', default='http://localhost:8545', type=str, help='Web3 provider url (http only)') argparser.add_argument('-i', '--chain-spec', dest='i', type=str, default='evm:ethereum:1', help='Chain specification string') @@ -37,17 +28,15 @@ argparser.add_argument('--env-prefix', default=os.environ.get('CONFINI_ENV_PREFI argparser.add_argument('-u', '--unsafe', dest='u', action='store_true', help='Auto-convert address to checksum adddress') argparser.add_argument('-v', action='store_true', help='Be verbose') argparser.add_argument('-vv', action='store_true', help='Be more verbose') -argparser.add_argument('address', nargs='?', type=str, default=stdin_arg(), help='Ethereum address of recipient') +argparser.add_argument('address', type=str, help='Ethereum address of recipient') args = argparser.parse_args() -if args.address == None: - argparser.error('need first positional argument or value from stdin') - if args.vv: logg.setLevel(logging.DEBUG) elif args.v: logg.setLevel(logging.INFO) + signer_address = None keystore = DictKeystore() if args.y != None: @@ -63,7 +52,7 @@ def main(): if not args.u and recipient != add_0x(args.address): raise ValueError('invalid checksum address') - o = count(recipient) + o = count(args.address) print(rpc.do(o)) diff --git a/chainlib/eth/runnable/decode.py b/chainlib/eth/runnable/decode.py index ee9e8bf..211451e 100644 --- a/chainlib/eth/runnable/decode.py +++ b/chainlib/eth/runnable/decode.py @@ -15,9 +15,8 @@ import os import json import argparse import logging -import select -# external imports +# third-party imports from chainlib.eth.tx import unpack from chainlib.chain import ChainSpec @@ -31,27 +30,14 @@ 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 - argparser = argparse.ArgumentParser() -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') +argparser.add_argument('-i', '--chain-id', dest='i', default='evm:ethereum:1', type=str, help='Numeric network id') +argparser.add_argument('tx', type=str, help='hex-encoded signed raw transaction') args = argparser.parse_args() -if args.tx == None: - argparser.error('need first positional argument or value from stdin') - -if args.vv: +if args.v: logg.setLevel(logging.DEBUG) -elif args.v: - logg.setLevel(logging.INFO) chain_spec = ChainSpec.from_chain_str(args.i) diff --git a/chainlib/eth/runnable/get.py b/chainlib/eth/runnable/get.py index 3176748..8579a48 100644 --- a/chainlib/eth/runnable/get.py +++ b/chainlib/eth/runnable/get.py @@ -16,7 +16,6 @@ import json import argparse import logging import enum -import select # external imports from hexathon import ( @@ -44,14 +43,7 @@ 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 - -argparser = argparse.ArgumentParser('eth-get', description='display information about an Ethereum address or transaction', epilog='address/transaction can be provided as an argument or from standard input') +argparser = argparse.ArgumentParser() argparser.add_argument('-p', '--provider', dest='p', default=default_eth_provider, type=str, help='Web3 provider url (http only)') argparser.add_argument('-i', '--chain-spec', dest='i', type=str, default='evm:ethereum:1', help='Chain specification string') argparser.add_argument('-t', '--token-address', dest='t', type=str, help='Token address. If not set, will return gas balance') @@ -59,12 +51,9 @@ argparser.add_argument('-u', '--unsafe', dest='u', action='store_true', help='Au argparser.add_argument('--abi-dir', dest='abi_dir', type=str, default=default_abi_dir, help='Directory containing bytecode and abi (default {})'.format(default_abi_dir)) argparser.add_argument('-v', action='store_true', help='Be verbose') argparser.add_argument('-vv', action='store_true', help='Be more verbose') -argparser.add_argument('item', nargs='?', default=stdin_arg(), type=str, help='Item to get information for (address og transaction)') +argparser.add_argument('item', type=str, help='Item to get information for (address og transaction)') args = argparser.parse_args() -if args.item == None: - argparser.error('need first positional argument or value from stdin') - if args.vv: logg.setLevel(logging.DEBUG) elif args.v: