def generate_keys_arguments_decorator( function: Callable[..., Any]) -> Callable[..., Any]: ''' This is a decorator that, when applied to a parent-command, implements the to obtain the necessary arguments for the generate_keys() subcommand. ''' decorators = [ click.option( '--num_validators', prompt='Please choose how many validators you wish to run', help= 'The number of validators keys you want to generate (you can always generate more later)', required=True, type=click.IntRange(0, 2**32 - 1), ), click.option( '--folder', default=os.getcwd(), help= 'The folder to place the generated keystores and deposit_data.json in', type=click.Path(exists=True, file_okay=False, dir_okay=True), ), click.option( '--chain', default=MAINNET, help= 'The version of eth2 you are targeting. use "mainnet" if you are depositing ETH', prompt='Please choose the (mainnet or testnet) network/chain name', type=click.Choice(ALL_CHAINS.keys(), case_sensitive=False), ), click.password_option( '--keystore_password', callback=validate_password, help= ('The password that will secure your keystores. You will need to re-enter this to decrypt them when ' 'you setup your eth2 validators. (It is reccomened not to use this argument, and wait for the CLI ' 'to ask you for your mnemonic as otherwise it will appear in your shell history.)' ), prompt='Type the password that secures your validator keystore(s)', ), click.option( '--eth1_withdrawal_address', default=None, callback=validate_eth1_withdrawal_address, help= ('If this field is set and valid, the given Eth1 address will be used to create the ' 'withdrawal credentials. Otherwise, it will generate withdrawal credentials with the ' 'mnemonic-derived withdrawal public key.'), ), click.option( '--quiet', '-q', help=('Suppress the output of useless stuff.'), is_flag=True, ), ] for decorator in reversed(decorators): function = decorator(function) return function
def decorator(func: Callable) -> Callable: for option in reversed([ click.option( "--keystore-file", required=True, type=click.Path(exists=True, dir_okay=False, readable=True), help="Path to a keystore file.", ), click.password_option( "--password", confirmation_prompt=False, help="Password to unlock the keystore file.", ), click.option( "--state-db", type=str, help= "Path to SQLite3 db which stores the application state", ), click.option( "--log-level", default="INFO", type=click.Choice( ["CRITICAL", "ERROR", "WARNING", "INFO", "DEBUG"]), help= "Print log messages of this level and more important ones", ), ]): func = option(func) @wraps(func) def call_with_common_options_initialized(**params: Any) -> Callable: params["private_key"] = _open_keystore(params.pop("keystore_file"), params.pop("password")) try: setup_logging(params.pop("log_level")) if not params["state_db"]: # only RC has `chain_id`, MS and PFS have `web3` object chain_id = str( params.get("chain_id") or params["web3"].net.version) contracts_version = CONTRACTS_VERSION.replace(".", "_") filename = f"{app_name}-{chain_id}-{contracts_version}.db" data_dir = click.get_app_dir(app_name) params["state_db"] = os.path.join(data_dir, filename) # Need to delete the `chain_id` key if params.get("chain_id") is not None: del params["chain_id"] return func(**params) finally: structlog.reset_defaults() return call_with_common_options_initialized
def decorator(func: Callable) -> Callable: for option in reversed([ click.option( '--keystore-file', required=True, type=click.Path(exists=True, dir_okay=False, readable=True), help='Path to a keystore file.', ), click.password_option( '--password', help='Password to unlock the keystore file.'), click.option( '--state-db', default=os.path.join(click.get_app_dir(app_name), 'state.db'), type=str, help= 'Path to SQLite3 db which stores the application state', ), click.option( '--log-level', default='INFO', type=click.Choice( ['CRITICAL', 'ERROR', 'WARNING', 'INFO', 'DEBUG']), help= 'Print log messages of this level and more important ones', callback=lambda ctx, param, value: setup_logging(str(value) ), expose_value=False, ), ]): func = option(func) @wraps(func) def call_with_opened_keystore(**params: Any) -> Callable: params['private_key'] = _open_keystore(params.pop('keystore_file'), params.pop('password')) return func(**params) return call_with_opened_keystore
def decorator(func: Callable) -> Callable: for option in reversed([ click.option( "--keystore-file", required=True, type=click.Path(exists=True, dir_okay=False, readable=True), help="Path to a keystore file.", ), click.password_option( "--password", confirmation_prompt=False, help="Password to unlock the keystore file.", ), click.option( "--state-db", type=str, help= "Path to SQLite3 db which stores the application state", ), click.option( "--log-level", default="INFO", type=click.Choice( ["CRITICAL", "ERROR", "WARNING", "INFO", "DEBUG"]), help= "Print log messages of this level and more important ones", ), click.option( "--log-json/--no-log-json", default=False, help="Enable or disable logging in JSON format", ), click.option( "--flamegraph", help= "Directory in which to save a stack profile to produce flame graphs.", type=click.Path( exists=False, dir_okay=True, file_okay=False, writable=True, resolve_path=True, allow_dash=False, ), default=None, ), ]): func = option(func) @wraps(func) def call_with_common_options_initialized(**params: Any) -> Callable: profiler = start_profiler(params.pop("flamegraph")) params["private_key"] = _open_keystore(params.pop("keystore_file"), params.pop("password")) # Don't print traceback on KeyboardInterrupt gevent.get_hub().NOT_ERROR += (KeyboardInterrupt, ) try: setup_logging(log_level=params.pop("log_level"), log_json=params.pop("log_json")) if not params["state_db"]: # only RC has `chain_id`, MS and PFS have `web3` object chain_id = str( params.get("chain_id") or params["web3"].net.version) contracts_version = CONTRACTS_VERSION.replace(".", "_") filename = f"{app_name}-{chain_id}-{contracts_version}.db" data_dir = click.get_app_dir(app_name) params["state_db"] = os.path.join(data_dir, filename) # Need to delete the `chain_id` key if params.get("chain_id") is not None: del params["chain_id"] return func(**params) finally: if profiler: profiler.stop() structlog.reset_defaults() return call_with_common_options_initialized