Skip to content
Snippets Groups Projects
Commit b19810c0 authored by Moul's avatar Moul Committed by GitHub
Browse files

Merge pull request #50 from duniter/wot_display_certs

Add 'wot' subcmd to display received and sent certifications
parents 9e378b68 7bca2214
No related branches found
No related tags found
No related merge requests found
...@@ -5,6 +5,7 @@ import sys ...@@ -5,6 +5,7 @@ import sys
from commandlines import Command from commandlines import Command
from commands import * from commands import *
from wot import *
def usage(): def usage():
...@@ -52,14 +53,16 @@ def usage(): ...@@ -52,14 +53,16 @@ def usage():
\n --auth-seed | --auth-file [--file=<path file>] | --auth-wif\ \n --auth-seed | --auth-file [--file=<path file>] | --auth-wif\
\n \ \n \
\n - id <pubkey> or <identity>: get corresponding identity or pubkey from pubkey or identity.\ \n - id <pubkey> or <identity>: get corresponding identity or pubkey from pubkey or identity.\
\n it could autocomplete the pubkey corresponding to an identity with three or four following characters.") \n it could autocomplete the pubkey corresponding to an identity with three or four following characters.\
\n \
\n - wot <pubkey> or <identity>: display received and sent certifications for an account.")
sys.exit() sys.exit()
def cli(): def cli():
# ep: endpoint, node's network interface # ep: endpoint, node's network interface
ep, c = dict(), Command() ep, c = dict(), Command()
subcmd = ["info", "diffi", "network", "issuers", "argos", "amount", "transaction", "generate_auth_file", "id"] subcmd = ["info", "diffi", "network", "issuers", "argos", "amount", "transaction", "generate_auth_file", "id", "wot"]
if c.is_version_request(): if c.is_version_request():
print("silkaj 0.3.0") print("silkaj 0.3.0")
sys.exit() sys.exit()
...@@ -108,6 +111,9 @@ def manage_cmd(ep, c): ...@@ -108,6 +111,9 @@ def manage_cmd(ep, c):
elif c.subcmd == "id": elif c.subcmd == "id":
id_pubkey_correspondence(ep, c.subsubcmd) id_pubkey_correspondence(ep, c.subsubcmd)
elif c.subcmd == "wot":
received_sent_certifications(ep, c.subsubcmd)
if __name__ == '__main__': if __name__ == '__main__':
ep, c = cli() ep, c = cli()
......
import os
import sys
from tabulate import tabulate
from collections import OrderedDict
from network_tools import request
from tools import get_pubkeys_from_id
from constants import *
def received_sent_certifications(ep, id):
"""
check id exist
many identities could exist
retrieve the one searched
get id of received and sent certifications
display on a chart the result with the numbers
"""
if get_pubkeys_from_id(ep, id) == NO_MATCHING_ID:
print(NO_MATCHING_ID)
sys.exit(1)
certs = request(ep, "wot/lookup/" + id)["results"]
for cert in certs:
if cert["uids"][0]["uid"].lower() == id.lower():
certs = cert
certifications = OrderedDict()
certifications["received"] = list()
certifications["sent"] = list()
received, sent = 0, 0
if certs["uids"]:
for received, cert in enumerate(certs["uids"][0]["others"]):
certifications["received"].append(cert["uids"][0])
if certs["signed"]:
for sent, cert in enumerate(certs["signed"]):
certifications["sent"].append(cert["uid"])
os.system("clear")
print("{0} received {1} and sent {2} certifications:\n{3}"
.format(id, received, sent, tabulate(certifications, headers="keys", tablefmt="orgtbl", stralign="center")))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment