Mise à jour de GitLab prévue ce samedi 8 mai 2021 à partir de 9h00 CET | GitLab upgrade planned this Saturday May 4th of 2021 from 9:00 AM CET

Commit 56d44193 authored by Moul's avatar Moul

[enh] #189: Handle wot/lookup call exceptions:

- Rename f() to wot_lookup()

- Remove no longer used constant
parent 953c3529
...@@ -16,7 +16,6 @@ along with Silkaj. If not, see <https://www.gnu.org/licenses/>. ...@@ -16,7 +16,6 @@ along with Silkaj. If not, see <https://www.gnu.org/licenses/>.
""" """
SILKAJ_VERSION = "0.6.0" SILKAJ_VERSION = "0.6.0"
NO_MATCHING_ID = "No matching identity"
G1_SYMBOL = "Ğ1" G1_SYMBOL = "Ğ1"
GTEST_SYMBOL = "ĞTest" GTEST_SYMBOL = "ĞTest"
G1_DEFAULT_ENDPOINT = "g1.duniter.org", "443" G1_DEFAULT_ENDPOINT = "g1.duniter.org", "443"
......
...@@ -26,7 +26,6 @@ from silkaj.network_tools import ClientInstance ...@@ -26,7 +26,6 @@ from silkaj.network_tools import ClientInstance
from silkaj.crypto_tools import check_public_key from silkaj.crypto_tools import check_public_key
from silkaj.tools import message_exit, convert_time, coroutine from silkaj.tools import message_exit, convert_time, coroutine
from silkaj.blockchain_tools import BlockchainParams from silkaj.blockchain_tools import BlockchainParams
from silkaj.constants import NO_MATCHING_ID
def get_sent_certifications(certs, time_first_block, params): def get_sent_certifications(certs, time_first_block, params):
...@@ -166,18 +165,15 @@ async def id_pubkey_correspondence(id_pubkey): ...@@ -166,18 +165,15 @@ async def id_pubkey_correspondence(id_pubkey):
) )
) )
else: else:
pubkeys = await get_informations_for_identities(id_pubkey) pubkeys = await wot_lookup(id_pubkey)
if pubkeys == NO_MATCHING_ID: print("Public keys found matching '{}':\n".format(id_pubkey))
print(NO_MATCHING_ID) for pubkey in pubkeys:
else: print("→", pubkey["pubkey"], end=" ")
print("Public keys found matching '{}':\n".format(id_pubkey)) try:
for pubkey in pubkeys: corresponding_id = await client(wot.identity_of, pubkey["pubkey"])
print("→", pubkey["pubkey"], end=" ") print("↔ " + corresponding_id["uid"])
try: except:
corresponding_id = await client(wot.identity_of, pubkey["pubkey"]) print("")
print("↔ " + corresponding_id["uid"])
except:
print("")
await client.close() await client.close()
...@@ -187,13 +183,11 @@ async def get_informations_for_identity(id): ...@@ -187,13 +183,11 @@ async def get_informations_for_identity(id):
many identities could match many identities could match
return the one searched return the one searched
""" """
certs_req = await get_informations_for_identities(id) certs_req = await wot_lookup(id)
if certs_req == NO_MATCHING_ID:
message_exit(NO_MATCHING_ID)
for certs_id in certs_req: for certs_id in certs_req:
if certs_id["uids"][0]["uid"].lower() == id.lower(): if certs_id["uids"][0]["uid"].lower() == id.lower():
return certs_id return certs_id
message_exit(NO_MATCHING_ID) message_exit("No matching identity")
async def identity_of(pubkey_uid): async def identity_of(pubkey_uid):
...@@ -222,7 +216,7 @@ async def is_member(pubkey_uid): ...@@ -222,7 +216,7 @@ async def is_member(pubkey_uid):
return False return False
async def get_informations_for_identities(identifier): async def wot_lookup(identifier):
""" """
:identifier: identity or pubkey in part or whole :identifier: identity or pubkey in part or whole
Return received and sent certifications lists of matching identities Return received and sent certifications lists of matching identities
...@@ -231,6 +225,8 @@ async def get_informations_for_identities(identifier): ...@@ -231,6 +225,8 @@ async def get_informations_for_identities(identifier):
client = ClientInstance().client client = ClientInstance().client
try: try:
results = await client(wot.lookup, identifier) results = await client(wot.lookup, identifier)
except: return results["results"]
return NO_MATCHING_ID except DuniterError as e:
return results["results"] message_exit(e.message)
except ValueError as e:
pass
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment