Skip to content
Snippets Groups Projects
Commit 413dd243 authored by Moul's avatar Moul
Browse files

[feat] #314: cert: Implement display option

The generated document is displayed
In case the option is passed, display the table and
the generated document
Use send_doc_confirmation()
parent 5a40e408
No related branches found
No related tags found
No related merge requests found
...@@ -24,19 +24,19 @@ from duniterpy.documents import BlockUID, block_uid, Identity, Certification ...@@ -24,19 +24,19 @@ from duniterpy.documents import BlockUID, block_uid, Identity, Certification
from silkaj.auth import auth_method from silkaj.auth import auth_method
from silkaj.tools import message_exit, coroutine from silkaj.tools import message_exit, coroutine
from silkaj.tui import convert_time, display_pubkey_and_checksum
from silkaj.network_tools import ClientInstance from silkaj.network_tools import ClientInstance
from silkaj.blockchain_tools import BlockchainParams, HeadBlock from silkaj.blockchain_tools import BlockchainParams, HeadBlock
from silkaj.license import license_approval from silkaj.license import license_approval
from silkaj import wot from silkaj import wot, tui
from silkaj.constants import SUCCESS_EXIT_STATUS from silkaj.constants import SUCCESS_EXIT_STATUS
from silkaj.crypto_tools import is_pubkey_and_check from silkaj.crypto_tools import is_pubkey_and_check
@click.command("cert", help="Send certification") @click.command("cert", help="Send certification")
@click.argument("uid_pubkey_to_certify") @click.argument("uid_pubkey_to_certify")
@click.pass_context
@coroutine @coroutine
async def send_certification(uid_pubkey_to_certify): async def send_certification(ctx, uid_pubkey_to_certify):
client = ClientInstance().client client = ClientInstance().client
checked_pubkey = is_pubkey_and_check(uid_pubkey_to_certify) checked_pubkey = is_pubkey_and_check(uid_pubkey_to_certify)
...@@ -84,7 +84,7 @@ async def send_certification(uid_pubkey_to_certify): ...@@ -84,7 +84,7 @@ async def send_certification(uid_pubkey_to_certify):
# Certification confirmation # Certification confirmation
await certification_confirmation( await certification_confirmation(
issuer, issuer_pubkey, pubkey_to_certify, idty_to_certify ctx, issuer, issuer_pubkey, pubkey_to_certify, idty_to_certify
) )
identity = Identity( identity = Identity(
...@@ -105,6 +105,10 @@ async def send_certification(uid_pubkey_to_certify): ...@@ -105,6 +105,10 @@ async def send_certification(uid_pubkey_to_certify):
signature="", signature="",
) )
if ctx.obj["DISPLAY_DOCUMENT"]:
click.echo(certification.signed_raw(), nl=False)
await tui.send_doc_confirmation("certification")
# Sign document # Sign document
certification.sign([key]) certification.sign([key])
...@@ -120,7 +124,7 @@ async def send_certification(uid_pubkey_to_certify): ...@@ -120,7 +124,7 @@ async def send_certification(uid_pubkey_to_certify):
async def certification_confirmation( async def certification_confirmation(
issuer, issuer_pubkey, pubkey_to_certify, idty_to_certify ctx, issuer, issuer_pubkey, pubkey_to_certify, idty_to_certify
): ):
cert = list() cert = list()
cert.append(["Cert", "Issuer", "–>", "Recipient: Published: #block-hash date"]) cert.append(["Cert", "Issuer", "–>", "Recipient: Published: #block-hash date"])
...@@ -129,22 +133,21 @@ async def certification_confirmation( ...@@ -129,22 +133,21 @@ async def certification_confirmation(
block_uid_idty = block_uid(idty_timestamp) block_uid_idty = block_uid(idty_timestamp)
block = await client(bma.blockchain.block, block_uid_idty.number) block = await client(bma.blockchain.block, block_uid_idty.number)
block_uid_date = ( block_uid_date = (
": #" + idty_timestamp[:15] + "" + convert_time(block["time"], "all") ": #" + idty_timestamp[:15] + "" + tui.convert_time(block["time"], "all")
) )
cert.append(["ID", issuer["uid"], "–>", idty_to_certify["uid"] + block_uid_date]) cert.append(["ID", issuer["uid"], "–>", idty_to_certify["uid"] + block_uid_date])
cert.append( cert.append(
[ [
"Pubkey", "Pubkey",
display_pubkey_and_checksum(issuer_pubkey), tui.display_pubkey_and_checksum(issuer_pubkey),
"–>", "–>",
display_pubkey_and_checksum(pubkey_to_certify), tui.display_pubkey_and_checksum(pubkey_to_certify),
] ]
) )
params = await BlockchainParams().params params = await BlockchainParams().params
cert_begins = convert_time(time(), "date") cert_begins = tui.convert_time(time(), "date")
cert_ends = convert_time(time() + params["sigValidity"], "date") cert_ends = tui.convert_time(time() + params["sigValidity"], "date")
cert.append(["Valid", cert_begins, "—>", cert_ends]) cert.append(["Valid", cert_begins, "—>", cert_ends])
click.echo(tabulate(cert, tablefmt="fancy_grid")) click.echo(tabulate(cert, tablefmt="fancy_grid"))
if not click.confirm("Do you confirm sending this certification?"): if not ctx.obj["DISPLAY_DOCUMENT"]:
await client.close() await tui.send_doc_confirmation("certification")
sys.exit(SUCCESS_EXIT_STATUS)
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