Esempio n. 1
0
def check_python_version() -> None:
    '''
    Checks that the python version running is sufficient and exits if not.
    '''
    if sys.version_info < (3, 7):
        click.pause(load_text(['err_python_version']))
        sys.exit()


@click.group()
@click.pass_context
@jit_option(
    '--language',
    callback=captive_prompt_callback(
        lambda language: fuzzy_reverse_dict_lookup(language, INTL_LANG_OPTIONS
                                                   ),
        choice_prompt_func(lambda: 'Please choose your language',
                           get_first_options(INTL_LANG_OPTIONS)),
    ),
    default='English',
    help='The language you wish to use the CLI in.',
    prompt=choice_prompt_func(lambda: 'Please choose your language',
                              get_first_options(INTL_LANG_OPTIONS))(),
    type=str,
)
@click.option(
    '--non_interactive',
    default=False,
    is_flag=True,
    help='Disables interactive prompts.',
    hidden=True,
)
Esempio n. 2
0
from .generate_keys import (
    generate_keys,
    generate_keys_arguments_decorator,
)

languages = get_first_options(MNEMONIC_LANG_OPTIONS)


@click.command(
    help=load_text(['arg_new_mnemonic', 'help'], func='new_mnemonic'), )
@click.pass_context
@jit_option(
    callback=captive_prompt_callback(
        lambda mnemonic_language: fuzzy_reverse_dict_lookup(
            mnemonic_language, MNEMONIC_LANG_OPTIONS),
        choice_prompt_func(
            lambda: load_text(['arg_mnemonic_language', 'prompt'],
                              func='new_mnemonic'), languages),
    ),
    default=lambda: load_text(['arg_mnemonic_language', 'default'],
                              func='new_mnemonic'),
    help=lambda: load_text(['arg_mnemonic_language', 'help'],
                           func='new_mnemonic'),
    param_decls='--mnemonic_language',
    prompt=choice_prompt_func(
        lambda: load_text(['arg_mnemonic_language', 'prompt'],
                          func='new_mnemonic'), languages),
)
@generate_keys_arguments_decorator
def new_mnemonic(ctx: click.Context, mnemonic_language: str,
                 **kwargs: Any) -> None:
Esempio n. 3
0
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 = [
        jit_option(
            callback=captive_prompt_callback(
                lambda num: validate_int_range(num, 1, 2**32),
                lambda: load_text(['num_validators', 'prompt'],
                                  func='generate_keys_arguments_decorator')),
            help=lambda: load_text(['num_validators', 'help'],
                                   func='generate_keys_arguments_decorator'),
            param_decls="--num_validators",
            prompt=lambda: load_text(['num_validators', 'prompt'],
                                     func='generate_keys_arguments_decorator'),
        ),
        jit_option(
            default=os.getcwd(),
            help=lambda: load_text(['folder', 'help'],
                                   func='generate_keys_arguments_decorator'),
            param_decls='--folder',
            type=click.Path(exists=True, file_okay=False, dir_okay=True),
        ),
        jit_option(
            callback=captive_prompt_callback(
                lambda x: closest_match(x, list(ALL_CHAINS.keys())),
                choice_prompt_func(
                    lambda: load_text(['chain', 'prompt'],
                                      func='generate_keys_arguments_decorator'
                                      ), list(ALL_CHAINS.keys())),
            ),
            default=MAINNET,
            help=lambda: load_text(['chain', 'help'],
                                   func='generate_keys_arguments_decorator'),
            param_decls='--chain',
            prompt=choice_prompt_func(
                lambda: load_text(['chain', 'prompt'],
                                  func='generate_keys_arguments_decorator'),
                list(ALL_CHAINS.keys())),
        ),
        jit_option(
            callback=captive_prompt_callback(
                validate_password_strength,
                lambda: load_text(['keystore_password', 'prompt'],
                                  func='generate_keys_arguments_decorator'),
                lambda: load_text(['keystore_password', 'confirm'],
                                  func='generate_keys_arguments_decorator'),
                lambda: load_text(['keystore_password', 'mismatch'],
                                  func='generate_keys_arguments_decorator'),
                True,
            ),
            help=lambda: load_text(['keystore_password', 'help'],
                                   func='generate_keys_arguments_decorator'),
            hide_input=True,
            param_decls='--keystore_password',
            prompt=lambda: load_text(['keystore_password', 'prompt'],
                                     func='generate_keys_arguments_decorator'),
        ),
        jit_option(
            callback=validate_eth1_withdrawal_address,
            default=None,
            help=lambda: load_text(['eth1_withdrawal_address', 'help'],
                                   func='generate_keys_arguments_decorator'),
            param_decls='--eth1_withdrawal_address',
        ),
    ]
    for decorator in reversed(decorators):
        function = decorator(function)
    return function
Esempio n. 4
0
    help=load_text(['arg_existing_mnemonic', 'help'],
                   func='existing_mnemonic'), )
@jit_option(
    callback=validate_mnemonic,
    help=lambda: load_text(['arg_mnemonic', 'help'], func='existing_mnemonic'),
    param_decls='--mnemonic',
    prompt=lambda: load_text(['arg_mnemonic', 'prompt'],
                             func='existing_mnemonic'),
    type=str,
)
@jit_option(
    callback=captive_prompt_callback(
        lambda x: x,
        lambda: load_text(['arg_mnemonic_password', 'prompt'],
                          func='existing_mnemonic'),
        lambda: load_text(['arg_mnemonic_password', 'confirm'],
                          func='existing_mnemonic'),
        lambda: load_text(['arg_mnemonic_password', 'mismatch'],
                          func='existing_mnemonic'),
        True,
    ),
    default='',
    help=lambda: load_text(['arg_mnemonic_password', 'help'],
                           func='existing_mnemonic'),
    hidden=True,
    param_decls='--mnemonic-password',
    prompt=False,
)
@jit_option(
    callback=captive_prompt_callback(
        lambda num: validate_int_range(num, 0, 2**32),
        lambda: load_text(['arg_validator_start_index', 'prompt'],