Compare commits

...

12 Commits

4 changed files with 99 additions and 5 deletions

View File

@ -51,6 +51,7 @@ balance_cmd = subparsers.add_parser('balance', help="Voir le solde d'un compte
id_cmd = subparsers.add_parser('id', help="Voir l'identité d'une clé publique/username")
id_balance_cmd = subparsers.add_parser('idBalance', help="Voir l'identité d'une clé publique/username et son solde")
currentUd = subparsers.add_parser('currentUd', help="Affiche la montant actuel du dividende Universel")
listWallets = subparsers.add_parser('listWallets', help="Liste de toutes les portefeuilles G1")
# Messages management
read_cmd.add_argument('-n', '--number',type=int, default=3, help="Affiche les NUMBER derniers messages")
@ -112,7 +113,12 @@ id_cmd.add_argument('-p', '--pubkey', help="Clé publique du compte visé")
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('--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()
cmd = args.cmd
@ -133,7 +139,8 @@ def createTmpDunikey():
nonce = ''.join(nonce)
keyPath = "/tmp/secret.dunikey-" + nonce
key = SigningKey.from_credentials(getpass.getpass("Identifiant: "), getpass.getpass("Mot de passe: "), None)
# key = SigningKey.from_credentials(getpass.getpass("Identifiant: "), getpass.getpass("Mot de passe: "), None)
key = SigningKey.from_credentials("sgse547yhd54xv6541srdh", "sfdgwdrhpkxdawsbszqpof1sdg65xc", None)
key.save_pubsec_file(keyPath)
return keyPath
@ -148,7 +155,8 @@ try:
except:
profile = False
if cmd in ('history','balance','get','id','idBalance') and (pubkey or profile):
# print(pubkey, profile)
if cmd in ('history','balance','get','id','idBalance','listWallets') and (pubkey or profile):
noNeedDunikey = True
keyPath = False
try:
@ -234,7 +242,7 @@ if cmd in ("read","send","delete","set","get","erase","stars","unstars","getoffe
cesium.deleteOffer(args.id)
# Construct GVA object
elif cmd in ("pay","history","balance","id","idBalance","currentUd"):
elif cmd in ("pay","history","balance","id","idBalance","currentUd","listWallets"):
from lib.gva import GvaApi
if args.node:
@ -257,6 +265,8 @@ elif cmd in ("pay","history","balance","id","idBalance","currentUd"):
gva.idBalance(args.pubkey)
elif cmd == "currentUd":
gva.currentUd()
elif cmd == "listWallets":
gva.listWallets(args.brut, args.mbr, args.non_mbr, args.larf)
if keyPath:

View File

@ -1,4 +1,5 @@
from lib.currentUd import currentUd
from lib.gvaWallets import ListWallets
import sys, re
from lib.natools import get_privkey
from lib.gvaPay import Transaction, PUBKEY_REGEX
@ -73,4 +74,10 @@ class GvaApi():
def currentUd(self):
gva = currentUd(self.node)
result = gva.sendDoc()
print(result)
def listWallets(self, brut, brutMbr, brutNonMbr, brutLarf):
gva = ListWallets(self.node, brut, brutMbr, brutNonMbr, brutLarf)
result = gva.sendDoc()
print(result)

77
lib/gvaWallets.py Normal file
View File

@ -0,0 +1,77 @@
#!/usr/bin/env python3
import sys, re, os.path, json, 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)
def sendDoc(self):
# Build wallets generation document
queryBuild = gql(
"""
{
wallets(pagination: { cursor: null, ord: ASC, pageSize: 0 }) {
pageInfo {
hasNextPage
endCursor
}
edges {
node {
script
balance {
amount
base
}
idty {
isMember
username
}
}
}
}
}
""")
# Send wallets document
try:
queryResult = self.client.execute(queryBuild)
except Exception as e:
sys.stderr.write("Echec de récupération de la liste:\n" + str(e) + "\n")
sys.exit(1)
jsonBrut = queryResult['wallets']['edges']
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)

View File

@ -26,7 +26,7 @@ class Offers(CesiumCommon):
data['thumbnail']['_content_type'] = "image/png"
# if category: data['category'] = category
# else:
data['category'] = {"parent":"cat90","localizedNames":{"en":"Fruits & Vegetables","es-ES":"Frutas y Vegetales","fr-FR":"Fruits & Légumes"},"name":"Fruits & Légumes","id":"cat92"}
data['category'] = {"parent":"cat24","localizedNames":{"en":"DVD / Films","es-ES":"DVDs / Cine","fr-FR":"DVD / Films"},"name":"DVD / Films","id":"cat25"}
if price: data['price'] = float(price) * 100
data['type'] = 'offer'
data['time'] = timeSent