118 lines
3.6 KiB
Python
Executable File
118 lines
3.6 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
|
|
import sys
|
|
import re, time
|
|
import os.path
|
|
import json
|
|
import ast
|
|
from termcolor import colored
|
|
from lib.natools import fmt, sign, get_privkey
|
|
from gql import gql, Client
|
|
from gql.transport.aiohttp import AIOHTTPTransport
|
|
|
|
PUBKEY_REGEX = "(?![OIl])[1-9A-Za-z]{42,45}"
|
|
|
|
|
|
class ListWallets:
|
|
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)
|
|
self.count = 0
|
|
|
|
def sendDoc(self, jsonBrut=[], cursor=None):
|
|
# Build wallets generation document
|
|
|
|
queryBuild = gql(
|
|
"""
|
|
query ($cursor: String!) { wallets(pagination: { cursor: $cursor, ord: ASC, pageSize: 999 }) {
|
|
pageInfo {
|
|
hasNextPage
|
|
endCursor
|
|
}
|
|
edges {
|
|
node {
|
|
script
|
|
balance {
|
|
amount
|
|
base
|
|
}
|
|
idty {
|
|
isMember
|
|
username
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
"""
|
|
)
|
|
paramsBuild = {
|
|
"cursor": cursor,
|
|
}
|
|
|
|
# Send wallets document
|
|
try:
|
|
queryResult = self.client.execute(queryBuild, variable_values=paramsBuild)
|
|
except Exception as e:
|
|
sys.stderr.write("Echec de récupération de la liste:\n" + str(e) + "\n")
|
|
sys.exit(1)
|
|
|
|
# Merge result
|
|
jsonBrut.extend(queryResult["wallets"]["edges"])
|
|
|
|
# Check pagination
|
|
endCursor = queryResult["wallets"]["pageInfo"]["endCursor"]
|
|
hasNextPage = queryResult["wallets"]["pageInfo"]["hasNextPage"]
|
|
|
|
if hasNextPage:
|
|
# print(jsonBrut[-1:][0]["node"]["script"])
|
|
print(self.count)
|
|
print(endCursor)
|
|
print(len(jsonBrut))
|
|
# print("---")
|
|
# if self.count % 3 == 1 and self.count != 0:
|
|
# time.sleep(3)
|
|
self.count += 1
|
|
self.sendDoc(jsonBrut, endCursor)
|
|
else:
|
|
return self.transformData(jsonBrut)
|
|
|
|
def transformData(self, jsonBrut):
|
|
walletList = []
|
|
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"] / 100,
|
|
"id": dataWork["idty"],
|
|
}
|
|
)
|
|
|
|
if self.brut:
|
|
names = []
|
|
for dataWork in walletList:
|
|
if self.mbr or self.nonMbr:
|
|
names.append(dataWork["pubkey"] + " " + dataWork["id"]["username"])
|
|
else:
|
|
names.append(dataWork["pubkey"])
|
|
|
|
return "\n".join(names)
|
|
else:
|
|
return json.dumps(walletList, indent=2)
|