Use bases changes in history as elois advices
This commit is contained in:
parent
6dd6c65388
commit
c31a2a47ad
|
@ -23,7 +23,7 @@ class Balance:
|
||||||
self.client = Client(transport=transport, fetch_schema_from_transport=True)
|
self.client = Client(transport=transport, fetch_schema_from_transport=True)
|
||||||
|
|
||||||
def sendDoc(self):
|
def sendDoc(self):
|
||||||
# Build TX generation document
|
# Build balance generation document
|
||||||
queryBuild = gql(
|
queryBuild = gql(
|
||||||
"""
|
"""
|
||||||
query ($pubkey: String!){
|
query ($pubkey: String!){
|
||||||
|
@ -37,7 +37,7 @@ class Balance:
|
||||||
"pubkey": self.pubkey
|
"pubkey": self.pubkey
|
||||||
}
|
}
|
||||||
|
|
||||||
# Send TX document
|
# Send balance document
|
||||||
try:
|
try:
|
||||||
balanceResult = self.client.execute(queryBuild, variable_values=paramsBuild)
|
balanceResult = self.client.execute(queryBuild, variable_values=paramsBuild)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|
|
@ -25,7 +25,7 @@ class History:
|
||||||
self.client = Client(transport=transport, fetch_schema_from_transport=True)
|
self.client = Client(transport=transport, fetch_schema_from_transport=True)
|
||||||
|
|
||||||
def sendDoc(self):
|
def sendDoc(self):
|
||||||
# Build TX generation document
|
# Build history generation document
|
||||||
queryBuild = gql(
|
queryBuild = gql(
|
||||||
"""
|
"""
|
||||||
query ($pubkey: String!){
|
query ($pubkey: String!){
|
||||||
|
@ -62,6 +62,10 @@ class History:
|
||||||
currency
|
currency
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
currentUd {
|
||||||
|
amount
|
||||||
|
base
|
||||||
|
}
|
||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
|
@ -69,7 +73,7 @@ class History:
|
||||||
"pubkey": self.pubkey
|
"pubkey": self.pubkey
|
||||||
}
|
}
|
||||||
|
|
||||||
# Send TX document
|
# Send history document
|
||||||
try:
|
try:
|
||||||
self.historyDoc = self.client.execute(queryBuild, variable_values=paramsBuild)
|
self.historyDoc = self.client.execute(queryBuild, variable_values=paramsBuild)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
@ -81,7 +85,9 @@ class History:
|
||||||
def parseHistory(self):
|
def parseHistory(self):
|
||||||
trans = []
|
trans = []
|
||||||
i = 0
|
i = 0
|
||||||
|
|
||||||
|
currentBase = int(self.historyDoc['currentUd']['base'])
|
||||||
|
|
||||||
for sens in 'received','sent','receiving','sending':
|
for sens in 'received','sent','receiving','sending':
|
||||||
res = self.historyDoc['transactionsHistory'][sens]
|
res = self.historyDoc['transactionsHistory'][sens]
|
||||||
for bloc in res:
|
for bloc in res:
|
||||||
|
@ -101,16 +107,28 @@ class History:
|
||||||
trans[i].append(bloc['issuers'][0])
|
trans[i].append(bloc['issuers'][0])
|
||||||
amount = int(output.split(':')[0])
|
amount = int(output.split(':')[0])
|
||||||
base = int(output.split(':')[1])
|
base = int(output.split(':')[1])
|
||||||
trans[i].append(amount*pow(10,base)/100)
|
applyBase = base-currentBase
|
||||||
|
trans[i].append(round(amount*pow(10,applyBase)/100, 2))
|
||||||
trans[i].append(bloc['comment'])
|
trans[i].append(bloc['comment'])
|
||||||
|
trans[i].append(base)
|
||||||
i += 1
|
i += 1
|
||||||
|
|
||||||
|
# Order transactions by date
|
||||||
trans.sort(key=lambda x: x[1])
|
trans.sort(key=lambda x: x[1])
|
||||||
|
|
||||||
|
# Keep only base if there is base change
|
||||||
|
lastBase = 0
|
||||||
|
for i in trans:
|
||||||
|
if i[5] == lastBase:
|
||||||
|
i.pop(5)
|
||||||
|
else:
|
||||||
|
lastBase = i[5]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Get balance
|
# Get balance
|
||||||
balance = self.historyDoc['balance']['amount']
|
balance = self.historyDoc['balance']['amount']
|
||||||
baseBalance = self.historyDoc['balance']['base']
|
balance = balance/100
|
||||||
balance = balance*pow(10,baseBalance)/100
|
|
||||||
|
|
||||||
# Get currency
|
# Get currency
|
||||||
currency = self.historyDoc['node']['peer']['currency']
|
currency = self.historyDoc['node']['peer']['currency']
|
||||||
|
@ -132,6 +150,9 @@ class History:
|
||||||
|
|
||||||
date = datetime.fromtimestamp(t[1]).strftime("%d/%m/%Y à %H:%M")
|
date = datetime.fromtimestamp(t[1]).strftime("%d/%m/%Y à %H:%M")
|
||||||
print('-'.center(rows, '-'))
|
print('-'.center(rows, '-'))
|
||||||
|
if len(t) > 5:
|
||||||
|
print(' Changement de base : {0} '.format(t[5]).center(rows, '#'))
|
||||||
|
print('-'.center(rows, '-'))
|
||||||
print(colored("| {: <18} | {: <45} | {: <12} | {: <30}".format(date, *t[2:]), color))
|
print(colored("| {: <18} | {: <45} | {: <12} | {: <30}".format(date, *t[2:]), color))
|
||||||
print('-'.center(rows, '-'))
|
print('-'.center(rows, '-'))
|
||||||
print('\033[1mSolde du compte: {0} {1}\033[0m'.format(balance,currency).center(rows, ' '))
|
print('\033[1mSolde du compte: {0} {1}\033[0m'.format(balance,currency).center(rows, ' '))
|
||||||
|
|
Reference in New Issue