commit 16e5876af31ae2d4aa04df8eec64bb370d8ee90e
parent 9d9ed134c3099d80a55f8f45578dd9ba1fe42256
Author: lash <dev@holbrook.no>
Date: Thu, 3 Nov 2022 12:34:24 +0000
Reimplement stdin args
Diffstat:
5 files changed, 26 insertions(+), 11 deletions(-)
diff --git a/chainlib/eth/cli/arg.py b/chainlib/eth/cli/arg.py
@@ -3,6 +3,7 @@ from chainlib.cli.arg import (
Arg as BaseArg,
ArgFlag,
process_args,
+ stdin_arg,
)
diff --git a/chainlib/eth/cli/config.py b/chainlib/eth/cli/config.py
@@ -19,7 +19,7 @@ class Config(BaseConfig):
default_fee_limit = 21000
-def process_config(config, arg, args, flags):
+def process_config(config, arg, args, flags, pos_arg_name=None):
config = base_process_config(config, arg, args, flags)
if arg.match('provider', flags):
@@ -34,4 +34,5 @@ def process_config(config, arg, args, flags):
if arg.match('wallet', flags):
config.add(getattr(args, 'z'), '_Z')
+
return config
diff --git a/chainlib/eth/runnable/balance.py b/chainlib/eth/runnable/balance.py
@@ -24,6 +24,7 @@ from chainlib.eth.cli.arg import (
Arg,
ArgFlag,
process_args,
+ stdin_arg,
)
from chainlib.eth.cli.config import (
Config,
@@ -46,7 +47,12 @@ script_dir = os.path.dirname(os.path.realpath(__file__))
def process_config_local(config, arg, args, flags):
- config.add(args.address, '_RECIPIENT', False)
+ recipient = None
+ if args.address:
+ recipient = add_0x(args.address)
+ else:
+ recipient = stdin_arg()
+ config.add(recipient, '_RECIPIENT', False)
return config
@@ -56,8 +62,8 @@ flags = arg_flags.STD_READ
argparser = chainlib.eth.cli.ArgumentParser()
argparser = process_args(argparser, arg, flags)
-
argparser.add_argument('address', type=str, help='Ethereum address of recipient')
+
args = argparser.parse_args()
logg = process_log(args, logg)
@@ -86,11 +92,14 @@ def main():
balance_str = str(balance_value)
balance_len = len(balance_str)
- if balance_len < decimals + 1:
- print('0.{}'.format(balance_str.zfill(decimals)))
+ if config.get('_RAW'):
+ print(balance_str)
else:
- offset = balance_len-decimals
- print('{}.{}'.format(balance_str[:offset],balance_str[offset:]))
+ if balance_len < decimals + 1:
+ print('0.{}'.format(balance_str.zfill(decimals)))
+ else:
+ offset = balance_len-decimals
+ print('{}.{}'.format(balance_str[:offset],balance_str[offset:]))
if __name__ == '__main__':
diff --git a/chainlib/eth/runnable/gas.py b/chainlib/eth/runnable/gas.py
@@ -49,17 +49,21 @@ logg = logging.getLogger()
def from_data_arg(data):
try:
- return strip_0x(data)
+ data = strip_0x(data)
+ logg.info('appended input hex data: {}'.format(data))
+ return data
except ValueError:
pass
+ filename = data
try:
- f = open(data, 'r')
+ f = open(filename, 'r')
except:
raise ValueError("data not hex and not file we can open")
data = f.read()
f.close()
+ logg.info('appended input data from file {}: {}'.format(filename, data))
data = data.rstrip()
return strip_0x(data)
@@ -72,7 +76,7 @@ def process_config_local(config, arg, args, flags):
if data == '':
data = None
config.add(data, '_DATA', False)
- config.add(args.amount, '_VALUE', False)
+ config.add(args.amount[0], '_VALUE', False)
return config
diff --git a/requirements.txt b/requirements.txt
@@ -3,4 +3,4 @@ pysha3==1.0.2
hexathon~=0.1.7
websocket-client==0.57.0
potaahto~=0.1.1
-chainlib~=0.3.0
+chainlib~=0.3.2