Skip to content
Snippets Groups Projects
Commit d0d236df authored by matograine's avatar matograine
Browse files

[mod] #344 use pendulum in silkaj.cert

parent 1cc86af8
No related branches found
No related tags found
1 merge request!177#344: Fix import loop issue, Generalize pendulum usage
......@@ -17,7 +17,8 @@ along with Silkaj. If not, see <https://www.gnu.org/licenses/>.
import sys
import click
from time import time
from pendulum import from_timestamp, now
from tabulate import tabulate
from duniterpy.api import bma
from duniterpy.documents import BlockUID, block_uid, Identity, Certification
......@@ -28,7 +29,7 @@ from silkaj.network_tools import ClientInstance
from silkaj.blockchain_tools import BlockchainParams, HeadBlock
from silkaj.license import license_approval
from silkaj import wot, tui
from silkaj.constants import SUCCESS_EXIT_STATUS
from silkaj.constants import SUCCESS_EXIT_STATUS, DATE, ALL
from silkaj.crypto_tools import is_pubkey_and_check
......@@ -108,8 +109,8 @@ async def pre_checks(client, issuer_pubkey, pubkey_to_certify):
# ĞT: 0<–>4.8m - 4.8m + 12.5d
renewable = cert["expiresIn"] - params["sigValidity"] + params["sigReplay"]
if renewable > 0:
renewable_date = tui.convert_time(time() + renewable, "date")
message_exit("Certification renewable the " + renewable_date)
renewable_date = now().add(seconds=renewable).format(DATE)
message_exit("Certification renewable from " + renewable_date)
# Check if the certification is already in the pending certifications
for pending_cert in req["pendingCerts"]:
......@@ -127,9 +128,8 @@ async def certification_confirmation(
idty_timestamp = idty_to_certify["meta"]["timestamp"]
block_uid_idty = block_uid(idty_timestamp)
block = await client(bma.blockchain.block, block_uid_idty.number)
block_uid_date = (
": #" + idty_timestamp[:15] + "" + tui.convert_time(block["time"], "all")
)
timestamp_date = from_timestamp(block["time"], tz="local").format(ALL)
block_uid_date = f": #{idty_timestamp[:15]}{timestamp_date}"
cert.append(["ID", issuer["uid"], "–>", idty_to_certify["uid"] + block_uid_date])
cert.append(
[
......@@ -140,8 +140,8 @@ async def certification_confirmation(
]
)
params = await BlockchainParams().params
cert_begins = tui.convert_time(time(), "date")
cert_ends = tui.convert_time(time() + params["sigValidity"], "date")
cert_begins = now().format(DATE)
cert_ends = now().add(seconds=params["sigValidity"]).format(DATE)
cert.append(["Valid", cert_begins, "—>", cert_ends])
click.echo(tabulate(cert, tablefmt="fancy_grid"))
if not ctx.obj["DISPLAY_DOCUMENT"]:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment