From 7961e589e16423079c9c9a2e8536b3e8c16aaa42 Mon Sep 17 00:00:00 2001 From: poka Date: Thu, 26 Nov 2020 02:16:38 +0100 Subject: [PATCH] Use new balance command from GVA --- lib/balancelib.py | 38 +++++++------------------------------- 1 file changed, 7 insertions(+), 31 deletions(-) diff --git a/lib/balancelib.py b/lib/balancelib.py index cb65660..afbc42f 100644 --- a/lib/balancelib.py +++ b/lib/balancelib.py @@ -27,13 +27,8 @@ class Balance: queryBuild = gql( """ query ($pubkey: String!){ - transactionsHistory(pubkey: $pubkey) { - received { - outputs - } - sent { - outputs - } + balance(script: $pubkey) { + amount } } """ @@ -44,34 +39,15 @@ class Balance: # Send TX document try: - self.historyDoc = self.client.execute(queryBuild, variable_values=paramsBuild) + balanceResult = self.client.execute(queryBuild, variable_values=paramsBuild) except Exception as e: message = ast.literal_eval(str(e))["message"] - sys.stderr.write("Echec de récupération de l'historique:\n" + message + "\n") + sys.stderr.write("Echec de récupération du solde:\n" + message + "\n") sys.exit(1) - res = self.historyDoc['transactionsHistory']['received'] - amount=[] - for i in res: - for output in i['outputs']: - if re.search(self.pubkey, output): - amount.append(int(output.split(':')[0])) - receivedTotal = sum(amount) - - res = self.historyDoc['transactionsHistory']['sent'] - amount=[] - for i in res: - for output in i['outputs']: - if not re.search(self.pubkey, output): - amount.append(int(output.split(':')[0])) - sentTotal = sum(amount) - - - # TODO: Get all UD from pubkey - - - total = (receivedTotal-sentTotal)/100 - print(total) + balanceValue = balanceResult['balance']['amount'] + print(balanceValue) + return balanceValue def balance(self): self.sendDoc()