Пример #1
0
def start_api(account_id: str, iroha_host: str, private_key: str, timer):
    """Starts REST API"""
    if not account_id:
        account_id = click.prompt(
            "Please enter the API AccountID e.g. admin@test")
    if not private_key:
        try:
            # look for file first
            private_key_file = f"./{account_id}.priv"
            private_key = open(private_key_file, "rb+").read()
        except FileNotFoundError:
            _print("Private key file not found")
            private_key = click.prompt(
                f"Please enter private key for AccountID: {account_id}")
            if not private_key:
                use_demo_key = click.prompt(
                    f"Do you want to use the demo private key for: {account_id}?"
                )
                if str(use_demo_key).lower() == "y":
                    private_key = "164879bd94411cb7c88308b6423f7dde1e6df19a98961c8aebf7d70990ade5b7"
                else:
                    _print(
                        "Exiting...\nPlease set all required params and restart."
                    )
                    sys.exit()
    if not timer:
        timer = click.prompt("Block Parser Cron Job in Minutes")
        os.environ["IROHA_DB_CRON"] = timer
    try:
        timer = int(timer)
        iroha_api = IrohaBlockAPI(api_user=account_id,
                                  private_key=private_key,
                                  iroha_host=iroha_host)
        _print(f"Current Iroha WSV Height: {iroha_api.get_wsv_height()}")
        schedule.every(timer).minutes.do(iroha_api.cron_block_parser)
    except:
        raise

    worker_active = True
    while worker_active:
        schedule.run_pending()
Пример #2
0
def main_menu(iroha_api, cli_active):
    while cli_active:
        _print(menu_text)
        user_choice = click.prompt(
            "Please Select Your Option", show_choices=["1", "2", "3"]
        )
        if user_choice == "1":
            _print(f"[bold green]Starting Genesis Block Parsing...[/bold green]")
            iroha_api.parse_genesis_iroha_block_to_db()
        elif user_choice == "2":
            scan_range = click.prompt(
                "How many blocks must be parsed?", default=100, type=int
            )
            iroha_api.run_block_paser(scan_range)
        elif user_choice == "3":
            scan_range = click.prompt(
                "How often in seconds should the cro", default=100, type=int
            )
            iroha_api.run_block_paser(scan_range)
        else:
            cli_active = False
Пример #3
0
def start_worker(account_id: str, iroha_host: str, private_key: str, timer):
    """Starts DB Cronjob Worker"""

    if not account_id:
        account_id = click.prompt(
            "Please enter the API AccountID e.g. admin@test")
    if not private_key:
        try:
            # look for file first
            script_dir = os.path.dirname(__file__)
            rel_path = f"{account_id}.priv"
            private_key_file = os.path.join(script_dir, rel_path)
            private_key = open(private_key_file, "rb+").read()
        except FileNotFoundError:
            _print("Private key file not found")
            private_key = click.prompt(
                f"Please enter private key for AccountID: {account_id}")
            if not private_key:
                _print(
                    "Exiting...\nPlease set all required params and restart.")
                sys.exit()
    if not timer:
        timer = click.prompt("Block Parser Cron Job in Minutes")
        os.environ["API_DB_CRON"] = timer
    try:
        timer = int(timer)
        iroha_api = IrohaBlockAPI(api_user=account_id,
                                  private_key=private_key,
                                  iroha_host=iroha_host)
        _print(f"Current Iroha WSV Height: {iroha_api.get_wsv_height()}")
        schedule.every(timer).minutes.do(iroha_api.cron_block_parser)
    except Exception:
        _print(Exception)

    worker_active = True
    while worker_active:
        schedule.run_pending()
Пример #4
0
def start_api(account_id: str, iroha_host, private_key):
    """Starts REST API"""
    if not account_id:
        account_id = click.prompt(
            "Please enter the API AccountID e.g. admin@test")
    if not private_key:
        try:
            script_dir = os.path.dirname(__file__)
            rel_path = f"{account_id}.priv"
            private_key_file = os.path.join(script_dir, rel_path)
            private_key = open(private_key_file, "rb+").read()
            os.environ["IROHA_DB_API_SECRET"] = private_key
        except FileNotFoundError:
            _print("[bold red]Private key file not found[/bold red]")
            sys.exit()
    os.environ["IROHA_HOST"] = iroha_host
    app.run()
Пример #5
0
def main(account_id, iroha_host, private_key):
    "Command Line Interface for Block DB API"
    _print(welcome_msg)
    if not account_id:
        account_id = click.prompt(
            "Please enter the API AccountID e.g. admin@test")
    if not private_key:
        try:
            script_dir = os.path.dirname(__file__)
            rel_path = f"{account_id}.priv"
            private_key_file = os.path.join(script_dir, rel_path)
            private_key = open(private_key_file, "rb+").read()
        except FileNotFoundError:
            _print("Private key not found")
            sys.exit()
    try:
        iroha_api = IrohaBlockAPI(api_user=account_id,
                                  private_key=private_key,
                                  iroha_host=iroha_host)
        print(iroha_api.get_wsv_height())
        cli_active = True
        main_menu(iroha_api, cli_active)
    except Exception as error:
        _print(error)