diff --git a/silkaj/blockchain/__init__.py b/silkaj/blockchain/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..58426bbc2bbfc951dc181bdd19b5b2569c074af0 --- /dev/null +++ b/silkaj/blockchain/__init__.py @@ -0,0 +1,14 @@ +# Copyright 2016-2022 Maël Azimi <m.a@moul.re> +# +# Silkaj is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Silkaj is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with Silkaj. If not, see <https://www.gnu.org/licenses/>. diff --git a/silkaj/blockchain/information.py b/silkaj/blockchain/information.py new file mode 100644 index 0000000000000000000000000000000000000000..6ca4b577897637ec3ac89209d12a8621acf4d7f7 --- /dev/null +++ b/silkaj/blockchain/information.py @@ -0,0 +1,87 @@ +# Copyright 2016-2022 Maël Azimi <m.a@moul.re> +# +# Silkaj is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Silkaj is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with Silkaj. If not, see <https://www.gnu.org/licenses/>. + +import click +from pendulum import from_timestamp + +from silkaj.blockchain_tools import get_head_block +from silkaj.constants import ALL +from silkaj.network_tools import determine_endpoint +from silkaj.tools import get_currency_symbol + + +@click.command("info", help="Display information about currency") +def currency_info() -> None: + head_block = get_head_block() + ep = determine_endpoint() + current_time = from_timestamp(head_block["time"], tz="local") + mediantime = from_timestamp(head_block["medianTime"], tz="local") + print( + "Connected to node:", + ep.host, + ep.port, + "\nCurrent block number:", + head_block["number"], + "\nCurrency name:", + get_currency_symbol(), + "\nNumber of members:", + head_block["membersCount"], + "\nMinimal Proof-of-Work:", + head_block["powMin"], + "\nCurrent time:", + current_time.format(ALL), + "\nMedian time:", + mediantime.format(ALL), + "\nDifference time:", + current_time.diff_for_humans(mediantime, True), + ) + + +@click.command( + "argos", help="Display currency information formatted for Argos or BitBar" +) +def argos_info() -> None: + head_block = get_head_block() + currency_symbol = get_currency_symbol() + print(currency_symbol, "|") + print("---") + ep = determine_endpoint() + if ep.port == 443: + href = f"href=https://{ep.host}/" + else: + href = f"href=http://{ep.host}:{ep.port}/" + current_time = from_timestamp(head_block["time"], tz="local") + mediantime = from_timestamp(head_block["medianTime"], tz="local") + print( + "Connected to node:", + ep.host, + ep.port, + "|", + href, + "\nCurrent block number:", + head_block["number"], + "\nCurrency name:", + currency_symbol, + "\nNumber of members:", + head_block["membersCount"], + "\nMinimal Proof-of-Work:", + head_block["powMin"], + "\nCurrent time:", + current_time.format(ALL), + "\nMedian time:", + mediantime.format(ALL), + "\nDifference time:", + current_time.diff_for_humans(mediantime, True), + ) diff --git a/silkaj/cli.py b/silkaj/cli.py index 585b86ff25e2b53bc8ed0a40532eaadb7cc3ee07..54c83cb670f38f6414a3164b13c72047a59504e7 100644 --- a/silkaj/cli.py +++ b/silkaj/cli.py @@ -20,10 +20,11 @@ from duniterpy.api.endpoint import endpoint as du_endpoint from silkaj import revocation from silkaj.auth import generate_auth_file +from silkaj.blockchain.information import argos_info, currency_info from silkaj.blocks import verify_blocks_signatures from silkaj.cert import send_certification from silkaj.checksum import checksum_command -from silkaj.commands import argos_info, currency_info, difficulties, list_blocks +from silkaj.commands import difficulties, list_blocks from silkaj.constants import ( G1_DEFAULT_ENDPOINT, G1_TEST_DEFAULT_ENDPOINT, diff --git a/silkaj/commands.py b/silkaj/commands.py index 8ebb775bf98ce3e5722d262bf4f28e7561cde075..f0ba6c6233298dac896e81bc61d318ec944280ca 100644 --- a/silkaj/commands.py +++ b/silkaj/commands.py @@ -29,38 +29,10 @@ from websocket._exceptions import WebSocketConnectionClosedException from silkaj import tui from silkaj.blockchain_tools import get_head_block from silkaj.constants import ALL -from silkaj.network_tools import client_instance, determine_endpoint -from silkaj.tools import get_currency_symbol +from silkaj.network_tools import client_instance from silkaj.wot_tools import identity_of -@command("info", help="Display information about currency") -def currency_info() -> None: - head_block = get_head_block() - ep = determine_endpoint() - current_time = from_timestamp(head_block["time"], tz="local") - mediantime = from_timestamp(head_block["medianTime"], tz="local") - print( - "Connected to node:", - ep.host, - ep.port, - "\nCurrent block number:", - head_block["number"], - "\nCurrency name:", - get_currency_symbol(), - "\nNumber of members:", - head_block["membersCount"], - "\nMinimal Proof-of-Work:", - head_block["powMin"], - "\nCurrent time:", - current_time.format(ALL), - "\nMedian time:", - mediantime.format(ALL), - "\nDifference time:", - current_time.diff_for_humans(mediantime, True), - ) - - def match_pattern(_pow: int, match: str = "", p: int = 1) -> Tuple[str, int]: while _pow > 0: if _pow >= 16: @@ -209,39 +181,3 @@ def print_blocks_views(issuers, current_nbr, number, detailed): table.set_cols_align(["l", "r", "r"]) table.set_cols_dtype(["t", "i", "i"]) print(f"from {len(list_issued)} issuers\n{table.draw()}") - - -@command("argos", help="Display currency information formatted for Argos or BitBar") -def argos_info() -> None: - head_block = get_head_block() - currency_symbol = get_currency_symbol() - print(currency_symbol, "|") - print("---") - ep = determine_endpoint() - if ep.port == 443: - href = f"href=https://{ep.host}/" - else: - href = f"href=http://{ep.host}:{ep.port}/" - current_time = from_timestamp(head_block["time"], tz="local") - mediantime = from_timestamp(head_block["medianTime"], tz="local") - print( - "Connected to node:", - ep.host, - ep.port, - "|", - href, - "\nCurrent block number:", - head_block["number"], - "\nCurrency name:", - currency_symbol, - "\nNumber of members:", - head_block["membersCount"], - "\nMinimal Proof-of-Work:", - head_block["powMin"], - "\nCurrent time:", - current_time.format(ALL), - "\nMedian time:", - mediantime.format(ALL), - "\nDifference time:", - current_time.diff_for_humans(mediantime, True), - )