diff --git a/silkaj/commands.py b/silkaj/commands.py index 78e0e85fcf5c62673c111b86b8778f396c1fea42..8a47ee492737e7f6e3e8d6caaec3763b56ebbe21 100644 --- a/silkaj/commands.py +++ b/silkaj/commands.py @@ -15,15 +15,16 @@ 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 aiohttp +import pendulum +import jsonschema from click import command, option, argument, IntRange from os import system from collections import OrderedDict from tabulate import tabulate from operator import itemgetter from asyncio import sleep -import aiohttp from _socket import gaierror -import jsonschema from duniterpy.api import bma @@ -36,8 +37,7 @@ from silkaj.network_tools import ( ) from silkaj.blockchain_tools import HeadBlock from silkaj.tools import CurrencySymbol -from silkaj.tui import convert_time -from silkaj.constants import ASYNC_SLEEP +from silkaj.constants import ASYNC_SLEEP, ALL, DATE, HOUR @command("info", help="Display information about currency") @@ -45,6 +45,7 @@ from silkaj.constants import ASYNC_SLEEP async def currency_info(): head_block = await HeadBlock().head_block ep = EndPoint().ep + difference_time = head_block["time"] - head_block["medianTime"] print( "Connected to node:", ep[best_endpoint_address(ep, False)], @@ -58,11 +59,11 @@ async def currency_info(): "\nMinimal Proof-of-Work:", head_block["powMin"], "\nCurrent time:", - convert_time(head_block["time"], "all"), + pendulum.from_timestamp(head_block["time"]).format(ALL), "\nMedian time:", - convert_time(head_block["medianTime"], "all"), + pendulum.from_timestamp(head_block["medianTime"]).format(ALL), "\nDifference time:", - convert_time(head_block["time"] - head_block["medianTime"], "hour"), + pendulum.from_timestamp(difference_time).format(HOUR), ) client = ClientInstance().client await client.close() @@ -129,7 +130,7 @@ def display_diffi(current, diffi): Generation of next block n°{2} possible by at least {3}/{4} members\n\ Common Proof-of-Work difficulty level: {5}, hash starting with `{6}`\n{7}".format( current["number"], - convert_time(current["time"], "all"), + pendulum.from_timestamp(current["time"]).format(ALL), diffi["block"], issuers, len(diffi["levels"]), @@ -165,8 +166,9 @@ async def list_blocks(number, detailed): issuer["pubkey"] = block["issuer"] if detailed or number <= 30: issuer["block"] = block["number"] - issuer["gentime"] = convert_time(block["time"], "all") - issuer["mediantime"] = convert_time(block["medianTime"], "all") + issuer["gentime"] = pendulum.from_timestamp(block["time"]).format(ALL) + mediantime = block["medianTime"] + issuer["mediantime"] = pendulum.from_timestamp(mediantime).format(ALL) issuer["hash"] = block["hash"][:10] issuer["powMin"] = block["powMin"] issuers_dict[issuer["pubkey"]] = issuer @@ -242,6 +244,7 @@ async def argos_info(): href = "href=https://%s/" % (endpoint_address) else: href = "href=http://%s:%s/" % (endpoint_address, ep["port"]) + difference_time = head_block["time"] - head_block["medianTime"] print( "Connected to node:", ep[best_endpoint_address(ep, False)], @@ -257,11 +260,11 @@ async def argos_info(): "\nMinimal Proof-of-Work:", head_block["powMin"], "\nCurrent time:", - convert_time(head_block["time"], "all"), + pendulum.from_timestamp(head_block["time"]).format(ALL), "\nMedian time:", - convert_time(head_block["medianTime"], "all"), + pendulum.from_timestamp(head_block["medianTime"]).format(ALL), "\nDifference time:", - convert_time(head_block["time"] - head_block["medianTime"], "hour"), + pendulum.from_timestamp(difference_time).format(HOUR), ) client = ClientInstance().client await client.close()