Improve listWallets options and algo

This commit is contained in:
poka 2021-08-28 02:47:20 +02:00
parent 314dc74404
commit e8aa6723ee
3 changed files with 28 additions and 27 deletions

View File

@ -114,7 +114,10 @@ id_cmd.add_argument('-u', '--username', help="Username du compte visé")
id_balance_cmd.add_argument('-p', '--pubkey', help="Pubkey du compte visé")
currentUd.add_argument('-p', '--pubkey', help="Pubkey du compte visé")
listWallets.add_argument('-b', '--balance', action='store_true', help="Affiche les soldes")
listWallets.add_argument('--brut', action='store_true', help="Affiche une liste de pubkey brut")
listWallets.add_argument('--mbr', action='store_true', help="Affiche la liste de pubkey membres brut")
listWallets.add_argument('--non_mbr', action='store_true', help="Affiche la liste de pubkey des identités non membres brut")
listWallets.add_argument('--larf', action='store_true', help="Affiche la liste des pubkey non membres brut")
listWallets.add_argument('--brut', action='store_true', help="Affiche la liste de toutes les pubkey brut")
listWallets.add_argument('-p', '--pubkey', help="useless but needed")
args = parser.parse_args()
@ -263,7 +266,7 @@ elif cmd in ("pay","history","balance","id","idBalance","currentUd","listWallets
elif cmd == "currentUd":
gva.currentUd()
elif cmd == "listWallets":
gva.listWallets(args.balance, args.brut)
gva.listWallets(args.brut, args.mbr, args.non_mbr, args.larf)
if keyPath:

View File

@ -76,10 +76,8 @@ class GvaApi():
result = gva.sendDoc()
print(result)
def listWallets(self, getBalance, brut):
gva = ListWallets(self.node, getBalance, brut)
result = gva.sendDoc(getBalance, brut)
if brut:
print("\n".join(result))
else:
print(result)
def listWallets(self, brut, brutMbr, brutNonMbr, brutLarf):
gva = ListWallets(self.node, brut, brutMbr, brutNonMbr, brutLarf)
result = gva.sendDoc()
print(result)

View File

@ -10,14 +10,16 @@ PUBKEY_REGEX = "(?![OIl])[1-9A-Za-z]{42,45}"
class ListWallets:
def __init__(self, node, getBalance, brut):
self.getBalance = getBalance
def __init__(self, node, brut, mbr, nonMbr, larf):
self.mbr = mbr
self.larf = larf
self.nonMbr = nonMbr
self.brut = brut
# Define Duniter GVA node
transport = AIOHTTPTransport(url=node)
self.client = Client(transport=transport, fetch_schema_from_transport=True)
def sendDoc(self, getBalance=True, brut=False):
def sendDoc(self):
# Build wallets generation document
queryBuild = gql(
@ -55,20 +57,18 @@ class ListWallets:
jsonBrut = queryResult['wallets']['edges']
walletList = []
if (brut):
names = []
for dictionary in jsonBrut:
dataWork = dictionary['node']
if "script" in dataWork:
names.append(dataWork["script"])
return names
else:
for i, trans in enumerate(jsonBrut):
dataWork = trans['node']
walletList.append(i)
walletList[i] = {}
walletList[i]['pubkey'] = dataWork['script']
walletList[i]['id'] = dataWork['idty']
for i, trans in enumerate(jsonBrut):
dataWork = trans['node']
if (self.mbr and (dataWork['idty'] == None or dataWork['idty']['isMember'] == False)): continue
if (self.nonMbr and (dataWork['idty'] == None or dataWork['idty']['isMember'] == True)): continue
if (self.larf and (dataWork['idty'] != None)): continue
walletList.append({'pubkey': dataWork['script'],'balance': dataWork['balance']['amount'],'id': dataWork['idty']})
if (self.brut):
names = []
for dataWork in walletList:
names.append(dataWork["pubkey"])
return "\n".join(names)
else:
return json.dumps(walletList, indent=2)