Skip to content
Snippets Groups Projects
Commit 48cd3211 authored by Moul's avatar Moul
Browse files

wot status: Use wot.requirements to get precise received certs expiration dates (#490)

Instead of unprecise computed value from wot.lookup

cross wot.lookup and wot.requirements return values,
since wot.lookup gives the uids

Delete cert_written_in_the_blockchain()

Re-add pending certs from wot.requirements
Add ✘ legend

Computed expiration due to cert expiration should not take
care into account pending certs

Remove get_sent_certifications() call
repeatedly called for no reason in a loop

Move get_sent_certifications() below
parent 2d5a868f
No related branches found
No related tags found
1 merge request!268wot status: Display precise expiration date of received certifications(#490)
Pipeline #39104 passed
......@@ -25,26 +25,6 @@ from silkaj.tui import Table
from silkaj.wot import tools as wt
def get_sent_certifications(
signed: list,
time_first_block: int,
params: dict,
) -> tuple[list[str], list[str]]:
sent = []
expire = []
if signed:
for cert in signed:
sent.append(cert["uid"])
expire.append(
expiration_date_from_block_id(
cert["cert_time"]["block"],
time_first_block,
params,
),
)
return sent, expire
@click.command(
"status",
help="Check received and sent certifications and \
......@@ -74,21 +54,27 @@ def status(uid_pubkey: str) -> None:
certifications["received"] = []
certifications["sent"] = []
certifications["sent_expire"] = []
for cert in identity["others"]:
certifications["received_expire"].append(
expiration_date_from_block_id(
cert["meta"]["block_number"],
time_first_block,
params,
),
)
for lookup_cert in identity["others"]:
for req_cert in req["certifications"]:
if req_cert["from"] == lookup_cert["pubkey"]:
certifications["received_expire"].append(
now().add(seconds=req_cert["expiresIn"]).format(DATE),
)
certifications["received"].append(f'{lookup_cert["uids"][0]}')
break
for pending_cert in req["pendingCerts"]:
certifications["received"].append(
cert_written_in_the_blockchain(req["certifications"], cert),
f'{(wt.identity_of(pending_cert["from"]))["uid"]}',
)
certifications["received_expire"].append(
from_timestamp(pending_cert["expires_on"], tz="local").format(DATE),
)
(
certifications["sent"],
certifications["sent_expire"],
) = get_sent_certifications(signed, time_first_block, params)
certifications["sent"], certifications["sent_expire"] = get_sent_certifications(
signed,
time_first_block,
params,
)
nbr_sent_certs = len(certifications["sent"]) if "sent" in certifications else 0
table = Table(style="columns").set_cols_align(["r", "r", "r", "r"])
......@@ -100,18 +86,12 @@ from block #{identity["meta"]["timestamp"][:15]}…\n\
received {len(certifications["received"])} and sent \
{nbr_sent_certs}/{params["sigStock"]} certifications:\n\
{table.draw()}\n\
✔: Certification available to be written or already written into the blockchain\n',
✔: Certification written in the blockchain\n\
✘: Pending certification, deadline treatment\n',
)
membership_status(certifications, pubkey, req)
def cert_written_in_the_blockchain(written_certs: dict, certifieur: dict):
for cert in written_certs:
if cert["from"] == certifieur["pubkey"]:
return certifieur["uids"][0] + ""
return certifieur["uids"][0]
def membership_status(certifications: dict, pubkey: str, req: dict) -> None:
params = get_blockchain_parameters()
if len(certifications["received"]) >= params["sigQty"]:
......@@ -134,6 +114,26 @@ def membership_status(certifications: dict, pubkey: str, req: dict) -> None:
print("outdistanced:", req["outdistanced"])
def get_sent_certifications(
signed: list,
time_first_block: int,
params: dict,
) -> tuple[list[str], list[str]]:
sent = []
expire = []
if signed:
for cert in signed:
sent.append(cert["uid"])
expire.append(
expiration_date_from_block_id(
cert["cert_time"]["block"],
time_first_block,
params,
),
)
return sent, expire
def expiration_date_from_block_id(
block_id: str,
time_first_block: int,
......
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