Add stdin input to replace single positional argument
This commit is contained in:
parent
5bac222e9c
commit
494cb1e0af
@ -1 +1 @@
|
|||||||
include requirements.txt
|
include *requirements.txt LICENSE
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
# standard imports
|
# standard imports
|
||||||
import sys
|
import sys
|
||||||
|
import select
|
||||||
|
|
||||||
# external imports
|
# external imports
|
||||||
from hexathon import strip_0x
|
from hexathon import strip_0x
|
||||||
@ -7,8 +8,25 @@ from hexathon import strip_0x
|
|||||||
# local imports
|
# local imports
|
||||||
from chainlib.eth.address import to_checksum_address
|
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():
|
def main():
|
||||||
print(to_checksum_address(strip_0x(sys.argv[1])))
|
try:
|
||||||
|
print(to_checksum_address(strip_0x(v)))
|
||||||
|
except ValueError as e:
|
||||||
|
sys.stderr.write('invalid input: {}\n'.format(e))
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
@ -6,6 +6,7 @@ import os
|
|||||||
import json
|
import json
|
||||||
import argparse
|
import argparse
|
||||||
import logging
|
import logging
|
||||||
|
import select
|
||||||
|
|
||||||
# local imports
|
# local imports
|
||||||
from chainlib.eth.address import to_checksum
|
from chainlib.eth.address import to_checksum
|
||||||
@ -14,12 +15,20 @@ from chainlib.eth.tx import count
|
|||||||
from chainlib.chain import ChainSpec
|
from chainlib.chain import ChainSpec
|
||||||
from crypto_dev_signer.keystore.dict import DictKeystore
|
from crypto_dev_signer.keystore.dict import DictKeystore
|
||||||
from crypto_dev_signer.eth.signer import ReferenceSigner as EIP155Signer
|
from crypto_dev_signer.eth.signer import ReferenceSigner as EIP155Signer
|
||||||
|
from hexathon import add_0x
|
||||||
|
|
||||||
logging.basicConfig(level=logging.WARNING)
|
logging.basicConfig(level=logging.WARNING)
|
||||||
logg = logging.getLogger()
|
logg = logging.getLogger()
|
||||||
|
|
||||||
default_eth_provider = os.environ.get('ETH_PROVIDER', 'http://localhost:8545')
|
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 = argparse.ArgumentParser()
|
||||||
argparser.add_argument('-p', '--provider', dest='p', default='http://localhost:8545', type=str, help='Web3 provider url (http only)')
|
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')
|
argparser.add_argument('-i', '--chain-spec', dest='i', type=str, default='evm:ethereum:1', help='Chain specification string')
|
||||||
@ -28,15 +37,17 @@ 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('-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('-v', action='store_true', help='Be verbose')
|
||||||
argparser.add_argument('-vv', action='store_true', help='Be more verbose')
|
argparser.add_argument('-vv', action='store_true', help='Be more verbose')
|
||||||
argparser.add_argument('address', type=str, help='Ethereum address of recipient')
|
argparser.add_argument('address', nargs='?', type=str, default=stdin_arg(), help='Ethereum address of recipient')
|
||||||
args = argparser.parse_args()
|
args = argparser.parse_args()
|
||||||
|
|
||||||
|
if args.address == None:
|
||||||
|
argparser.error('need first positional argument or value from stdin')
|
||||||
|
|
||||||
if args.vv:
|
if args.vv:
|
||||||
logg.setLevel(logging.DEBUG)
|
logg.setLevel(logging.DEBUG)
|
||||||
elif args.v:
|
elif args.v:
|
||||||
logg.setLevel(logging.INFO)
|
logg.setLevel(logging.INFO)
|
||||||
|
|
||||||
|
|
||||||
signer_address = None
|
signer_address = None
|
||||||
keystore = DictKeystore()
|
keystore = DictKeystore()
|
||||||
if args.y != None:
|
if args.y != None:
|
||||||
@ -52,7 +63,7 @@ def main():
|
|||||||
if not args.u and recipient != add_0x(args.address):
|
if not args.u and recipient != add_0x(args.address):
|
||||||
raise ValueError('invalid checksum address')
|
raise ValueError('invalid checksum address')
|
||||||
|
|
||||||
o = count(args.address)
|
o = count(recipient)
|
||||||
print(rpc.do(o))
|
print(rpc.do(o))
|
||||||
|
|
||||||
|
|
||||||
|
@ -15,8 +15,9 @@ import os
|
|||||||
import json
|
import json
|
||||||
import argparse
|
import argparse
|
||||||
import logging
|
import logging
|
||||||
|
import select
|
||||||
|
|
||||||
# third-party imports
|
# external imports
|
||||||
from chainlib.eth.tx import unpack
|
from chainlib.eth.tx import unpack
|
||||||
from chainlib.chain import ChainSpec
|
from chainlib.chain import ChainSpec
|
||||||
|
|
||||||
@ -30,14 +31,27 @@ logg = logging.getLogger()
|
|||||||
default_abi_dir = os.environ.get('ETH_ABI_DIR', '/usr/share/local/cic/solidity/abi')
|
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')
|
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 = argparse.ArgumentParser()
|
||||||
argparser.add_argument('-v', action='store_true', help='Be verbose')
|
|
||||||
argparser.add_argument('-i', '--chain-id', dest='i', default='evm:ethereum:1', type=str, help='Numeric network id')
|
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')
|
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')
|
||||||
args = argparser.parse_args()
|
args = argparser.parse_args()
|
||||||
|
|
||||||
if args.v:
|
if args.tx == None:
|
||||||
|
argparser.error('need first positional argument or value from stdin')
|
||||||
|
|
||||||
|
if args.vv:
|
||||||
logg.setLevel(logging.DEBUG)
|
logg.setLevel(logging.DEBUG)
|
||||||
|
elif args.v:
|
||||||
|
logg.setLevel(logging.INFO)
|
||||||
|
|
||||||
chain_spec = ChainSpec.from_chain_str(args.i)
|
chain_spec = ChainSpec.from_chain_str(args.i)
|
||||||
|
|
||||||
|
@ -16,6 +16,7 @@ import json
|
|||||||
import argparse
|
import argparse
|
||||||
import logging
|
import logging
|
||||||
import enum
|
import enum
|
||||||
|
import select
|
||||||
|
|
||||||
# external imports
|
# external imports
|
||||||
from hexathon import (
|
from hexathon import (
|
||||||
@ -43,7 +44,14 @@ logg = logging.getLogger()
|
|||||||
default_abi_dir = os.environ.get('ETH_ABI_DIR', '/usr/share/local/cic/solidity/abi')
|
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')
|
default_eth_provider = os.environ.get('ETH_PROVIDER', 'http://localhost:8545')
|
||||||
|
|
||||||
argparser = argparse.ArgumentParser()
|
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.add_argument('-p', '--provider', dest='p', default=default_eth_provider, type=str, help='Web3 provider url (http only)')
|
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('-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')
|
argparser.add_argument('-t', '--token-address', dest='t', type=str, help='Token address. If not set, will return gas balance')
|
||||||
@ -51,9 +59,12 @@ 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('--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('-v', action='store_true', help='Be verbose')
|
||||||
argparser.add_argument('-vv', action='store_true', help='Be more verbose')
|
argparser.add_argument('-vv', action='store_true', help='Be more verbose')
|
||||||
argparser.add_argument('item', type=str, help='Item to get information for (address og transaction)')
|
argparser.add_argument('item', nargs='?', default=stdin_arg(), type=str, help='Item to get information for (address og transaction)')
|
||||||
args = argparser.parse_args()
|
args = argparser.parse_args()
|
||||||
|
|
||||||
|
if args.item == None:
|
||||||
|
argparser.error('need first positional argument or value from stdin')
|
||||||
|
|
||||||
if args.vv:
|
if args.vv:
|
||||||
logg.setLevel(logging.DEBUG)
|
logg.setLevel(logging.DEBUG)
|
||||||
elif args.v:
|
elif args.v:
|
||||||
|
Loading…
Reference in New Issue
Block a user