diff --git a/silkaj/wot/status.py b/silkaj/wot/status.py index 6c8af73933aa7345a53f2c4d6c1112a53cddbd3c..6fdfb75ee4fa7a8f65ca676434299f466e202c2f 100644 --- a/silkaj/wot/status.py +++ b/silkaj/wot/status.py @@ -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,