From 58b92837ffa45ebaca3032b97abd1ec3ecccec51 Mon Sep 17 00:00:00 2001 From: nolash Date: Wed, 6 Oct 2021 07:14:31 +0200 Subject: [PATCH] Add override config defaults, reset arg flag method --- chainlib/cli/__init__.py | 1 + chainlib/cli/arg.py | 4 ++-- chainlib/cli/base.py | 7 ++++++- chainlib/cli/config.py | 10 +++++++++- chainlib/cli/rpc.py | 4 ++++ requirements.txt | 2 +- setup.cfg | 2 +- 7 files changed, 24 insertions(+), 6 deletions(-) diff --git a/chainlib/cli/__init__.py b/chainlib/cli/__init__.py index a182b3a..b587477 100644 --- a/chainlib/cli/__init__.py +++ b/chainlib/cli/__init__.py @@ -3,6 +3,7 @@ from .base import ( argflag_std_read, argflag_std_write, argflag_std_base, + reset, ) from .arg import ArgumentParser from .config import Config diff --git a/chainlib/cli/arg.py b/chainlib/cli/arg.py index b29e356..2036e9a 100644 --- a/chainlib/cli/arg.py +++ b/chainlib/cli/arg.py @@ -50,8 +50,8 @@ class ArgumentParser(argparse.ArgumentParser): :type epilog: str """ - def __init__(self, arg_flags=0x0f, env=os.environ, usage=None, description=None, epilog=None): - super(ArgumentParser, self).__init__(usage=usage, description=description, epilog=epilog, formatter_class=argparse.RawDescriptionHelpFormatter) + def __init__(self, arg_flags=0x0f, env=os.environ, usage=None, description=None, epilog=None, *args, **kwargs): + super(ArgumentParser, self).__init__(usage=usage, description=description, epilog=epilog, formatter_class=argparse.RawDescriptionHelpFormatter, *args, **kwargs) self.process_flags(arg_flags, env) self.pos_args = [] diff --git a/chainlib/cli/base.py b/chainlib/cli/base.py index d3121ac..446e89b 100644 --- a/chainlib/cli/base.py +++ b/chainlib/cli/base.py @@ -2,7 +2,6 @@ import enum import os - script_dir = os.path.dirname(os.path.realpath(__file__)) default_config_dir = os.path.join(script_dir, '..', 'data', 'config') @@ -39,3 +38,9 @@ argflag_std_read = 0x23ff argflag_std_write = 0xff31ff argflag_std_base = 0x200f argflag_std_target = 0x00e000 +argflag_all = 0xffffff + +def reset(flags, v): + mask = ~(argflag_all & v) + r = flags & mask + return r diff --git a/chainlib/cli/config.py b/chainlib/cli/config.py index a1a3c01..8716958 100644 --- a/chainlib/cli/config.py +++ b/chainlib/cli/config.py @@ -35,6 +35,15 @@ class Config(confini.Config): default_base_config_dir = default_parent_config_dir default_fee_limit = 0 + + @staticmethod + def override_defaults(base_dir=None, default_fee_limit=None): + if base_dir != None: + Config.default_base_config_dir = os.path.realpath(base_dir) + if default_fee_limit != None: + Config.default_fee_limit = int(default_fee_limit) + + @classmethod def from_args(cls, args, arg_flags=0x0f, env=os.environ, extra_args={}, base_config_dir=None, default_config_dir=None, user_config_dir=None, default_fee_limit=None, logger=None, load_callback=logcallback, dump_writer=sys.stdout): """Parses arguments in argparse.ArgumentParser instance, then match and override configuration values that match them. @@ -157,7 +166,6 @@ class Config(confini.Config): config.process() config.add(getattr(args, 'raw'), '_RAW') - args_override = {} diff --git a/chainlib/cli/rpc.py b/chainlib/cli/rpc.py index 93db1c4..fd76b01 100644 --- a/chainlib/cli/rpc.py +++ b/chainlib/cli/rpc.py @@ -113,3 +113,7 @@ class Rpc: :returns: Wallet address in canonical string representation """ return self.wallet.signer_address + + + def get_signer_address(self): + return self.get_sender_address() diff --git a/requirements.txt b/requirements.txt index 2ea3d62..1a6813d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,3 @@ -crypto-dev-signer>=0.4.15a1,<=0.4.15 +crypto-dev-signer>=0.4.15rc2,<=0.4.15 pysha3==1.0.2 hexathon~=0.0.1a8 diff --git a/setup.cfg b/setup.cfg index 56f552a..255edb3 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = chainlib -version = 0.0.9a9 +version = 0.0.9rc1 description = Generic blockchain access library and tooling author = Louis Holbrook author_email = dev@holbrook.no