Improve listWallets options and algo
This commit is contained in:
parent
314dc74404
commit
e8aa6723ee
|
@ -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é")
|
id_balance_cmd.add_argument('-p', '--pubkey', help="Pubkey du compte visé")
|
||||||
currentUd.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('-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")
|
listWallets.add_argument('-p', '--pubkey', help="useless but needed")
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
@ -263,7 +266,7 @@ elif cmd in ("pay","history","balance","id","idBalance","currentUd","listWallets
|
||||||
elif cmd == "currentUd":
|
elif cmd == "currentUd":
|
||||||
gva.currentUd()
|
gva.currentUd()
|
||||||
elif cmd == "listWallets":
|
elif cmd == "listWallets":
|
||||||
gva.listWallets(args.balance, args.brut)
|
gva.listWallets(args.brut, args.mbr, args.non_mbr, args.larf)
|
||||||
|
|
||||||
|
|
||||||
if keyPath:
|
if keyPath:
|
||||||
|
|
12
lib/gva.py
12
lib/gva.py
|
@ -76,10 +76,8 @@ class GvaApi():
|
||||||
result = gva.sendDoc()
|
result = gva.sendDoc()
|
||||||
print(result)
|
print(result)
|
||||||
|
|
||||||
def listWallets(self, getBalance, brut):
|
def listWallets(self, brut, brutMbr, brutNonMbr, brutLarf):
|
||||||
gva = ListWallets(self.node, getBalance, brut)
|
gva = ListWallets(self.node, brut, brutMbr, brutNonMbr, brutLarf)
|
||||||
result = gva.sendDoc(getBalance, brut)
|
result = gva.sendDoc()
|
||||||
if brut:
|
|
||||||
print("\n".join(result))
|
print(result)
|
||||||
else:
|
|
||||||
print(result)
|
|
|
@ -10,14 +10,16 @@ PUBKEY_REGEX = "(?![OIl])[1-9A-Za-z]{42,45}"
|
||||||
|
|
||||||
class ListWallets:
|
class ListWallets:
|
||||||
|
|
||||||
def __init__(self, node, getBalance, brut):
|
def __init__(self, node, brut, mbr, nonMbr, larf):
|
||||||
self.getBalance = getBalance
|
self.mbr = mbr
|
||||||
|
self.larf = larf
|
||||||
|
self.nonMbr = nonMbr
|
||||||
self.brut = brut
|
self.brut = brut
|
||||||
# Define Duniter GVA node
|
# Define Duniter GVA node
|
||||||
transport = AIOHTTPTransport(url=node)
|
transport = AIOHTTPTransport(url=node)
|
||||||
self.client = Client(transport=transport, fetch_schema_from_transport=True)
|
self.client = Client(transport=transport, fetch_schema_from_transport=True)
|
||||||
|
|
||||||
def sendDoc(self, getBalance=True, brut=False):
|
def sendDoc(self):
|
||||||
# Build wallets generation document
|
# Build wallets generation document
|
||||||
|
|
||||||
queryBuild = gql(
|
queryBuild = gql(
|
||||||
|
@ -55,20 +57,18 @@ class ListWallets:
|
||||||
jsonBrut = queryResult['wallets']['edges']
|
jsonBrut = queryResult['wallets']['edges']
|
||||||
|
|
||||||
walletList = []
|
walletList = []
|
||||||
if (brut):
|
for i, trans in enumerate(jsonBrut):
|
||||||
names = []
|
dataWork = trans['node']
|
||||||
for dictionary in jsonBrut:
|
if (self.mbr and (dataWork['idty'] == None or dataWork['idty']['isMember'] == False)): continue
|
||||||
dataWork = dictionary['node']
|
if (self.nonMbr and (dataWork['idty'] == None or dataWork['idty']['isMember'] == True)): continue
|
||||||
if "script" in dataWork:
|
if (self.larf and (dataWork['idty'] != None)): continue
|
||||||
names.append(dataWork["script"])
|
walletList.append({'pubkey': dataWork['script'],'balance': dataWork['balance']['amount'],'id': dataWork['idty']})
|
||||||
|
|
||||||
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']
|
|
||||||
|
|
||||||
|
if (self.brut):
|
||||||
|
names = []
|
||||||
|
for dataWork in walletList:
|
||||||
|
names.append(dataWork["pubkey"])
|
||||||
|
|
||||||
|
return "\n".join(names)
|
||||||
|
else:
|
||||||
return json.dumps(walletList, indent=2)
|
return json.dumps(walletList, indent=2)
|
||||||
|
|
Loading…
Reference in New Issue