Use new balance command from GVA

This commit is contained in:
poka 2020-11-26 02:16:38 +01:00
parent c633fba6a2
commit 7961e589e1
1 changed files with 7 additions and 31 deletions

View File

@ -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()