From 3492643d4fcd61f9ea7ad749be6a1f4184122345 Mon Sep 17 00:00:00 2001 From: poka Date: Sat, 9 Sep 2023 10:14:31 +0200 Subject: [PATCH] add map option to walletList --- lib/geolocProfiles.py | 2 +- lib/gvaWallets.py | 31 +++++++++++++++++++++++-------- 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/lib/geolocProfiles.py b/lib/geolocProfiles.py index 9f3716b..094be7a 100755 --- a/lib/geolocProfiles.py +++ b/lib/geolocProfiles.py @@ -70,7 +70,7 @@ class GeolocProfiles(CesiumCommon): return finalResult def getGVAProfiles(self, node): - gva = ListWallets(node, False, False, False, False) + gva = ListWallets(node, False, False, False, False, True) return gva.sendDoc() def formatProfiles(self, cesiumProfiles, gvaProfiles): diff --git a/lib/gvaWallets.py b/lib/gvaWallets.py index 61cd679..bce7226 100755 --- a/lib/gvaWallets.py +++ b/lib/gvaWallets.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 -import sys, json +import sys, re, os.path, json, ast from termcolor import colored from lib.natools import fmt, sign, get_privkey from gql import gql, Client @@ -10,11 +10,12 @@ PUBKEY_REGEX = "(?![OIl])[1-9A-Za-z]{42,45}" class ListWallets: - def __init__(self, node, brut, mbr, nonMbr, larf): + def __init__(self, node, brut, mbr, nonMbr, larf, map=False): self.mbr = mbr self.larf = larf self.nonMbr = nonMbr self.brut = brut + self.map = map # Define Duniter GVA node transport = AIOHTTPTransport(url=node) self.client = Client(transport=transport, fetch_schema_from_transport=True) @@ -57,6 +58,7 @@ class ListWallets: jsonBrut = queryResult["wallets"]["edges"] + walletList = [] walletMap = {} for i, trans in enumerate(jsonBrut): dataWork = trans["node"] @@ -70,14 +72,24 @@ class ListWallets: continue if self.larf and (dataWork["idty"] != None): continue - walletMap[dataWork["script"]] = { - "balance": dataWork["balance"]["amount"] / 100, - "id": dataWork["idty"], - } + + if self.map: + walletMap[dataWork["script"]] = { + "balance": dataWork["balance"]["amount"] / 100, + "id": dataWork["idty"], + } + else: + walletList.append( + { + "pubkey": dataWork["script"], + "balance": dataWork["balance"]["amount"] / 100, + "id": dataWork["idty"], + } + ) if self.brut: names = [] - for dataWork in walletMap: + for dataWork in walletList: if self.mbr or self.nonMbr: names.append(dataWork["pubkey"] + " " + dataWork["id"]["username"]) else: @@ -85,4 +97,7 @@ class ListWallets: return "\n".join(names) else: - return json.dumps(walletMap, indent=2) + if self.map: + return json.dumps(walletMap, indent=2) + else: + return json.dumps(walletList, indent=2)