diff --git a/silkaj/commands.py b/silkaj/commands.py index 092b499eef2bf739cb21f1b5e9da2c9d892f7b6a..d65a124d6481657809f0514968559881f00a9810 100644 --- a/silkaj/commands.py +++ b/silkaj/commands.py @@ -16,10 +16,12 @@ from collections import OrderedDict from operator import itemgetter from os import system +from typing import Dict, List, Tuple import jsonschema from click import IntRange, argument, command, option from duniterpy.api import bma +from duniterpy.api.client import WSConnection from pendulum import from_timestamp from tabulate import tabulate from websocket._exceptions import WebSocketConnectionClosedException @@ -32,7 +34,7 @@ from silkaj.wot_tools import identity_of @command("info", help="Display information about currency") -def currency_info(): +def currency_info() -> None: head_block = get_head_block() ep = determine_endpoint() current_time = from_timestamp(head_block["time"], tz="local") @@ -58,7 +60,7 @@ def currency_info(): ) -def match_pattern(pow, match="", p=1): +def match_pattern(pow: int, match: str = "", p: int = 1) -> Tuple[str, int]: while pow > 0: if pow >= 16: match += "0" @@ -71,7 +73,7 @@ def match_pattern(pow, match="", p=1): return f"{match}*", p -def power(nbr, pow=0): +def power(nbr: float, pow: int = 0) -> str: while nbr >= 10: nbr /= 10 pow += 1 @@ -82,7 +84,7 @@ def power(nbr, pow=0): "diffi", help="Display the current Proof of Work difficulty level to generate the next block", ) -def difficulties(): +def difficulties() -> None: client = client_instance() try: ws = client(bma.ws.block) @@ -95,7 +97,7 @@ def difficulties(): print(f"{str(e.__class__.__name__)}: {str(e)}") -def display_diffi(current, diffi): +def display_diffi(current: WSConnection, diffi: Dict) -> None: levels = [OrderedDict((i, d[i]) for i in ("uid", "level")) for d in diffi["levels"]] diffi["levels"] = levels issuers = 0 @@ -125,7 +127,7 @@ Common Proof-of-Work difficulty level: {current["powMin"]}, hash starting with ` is_flag=True, help="Force detailed view. Compact view happen over 30 blocks", ) -def list_blocks(number, detailed): +def list_blocks(number: int, detailed: bool) -> None: head_block = get_head_block() current_nbr = head_block["number"] if number == 0: @@ -169,7 +171,7 @@ def list_blocks(number, detailed): ) print(f"\n{table}") else: - list_issued = list() + list_issued = list() # type: List[OrderedDict] for issuer in issuers: found = False for issued in list_issued: @@ -196,7 +198,7 @@ def list_blocks(number, detailed): @command("argos", help="Display currency information formatted for Argos or BitBar") -def argos_info(): +def argos_info() -> None: head_block = get_head_block() currency_symbol = get_currency_symbol() print(currency_symbol, "|")