Add balance history; Improve history output
This commit is contained in:
parent
7961e589e1
commit
c186b3c13c
|
@ -27,3 +27,4 @@ args = parser.parse_args()
|
|||
# Create transaction and send it
|
||||
balance = Balance(dunikey, node, args.pubkey, args.mempool)
|
||||
result = balance.balance()
|
||||
print(result)
|
|
@ -45,10 +45,11 @@ class Balance:
|
|||
sys.stderr.write("Echec de récupération du solde:\n" + message + "\n")
|
||||
sys.exit(1)
|
||||
|
||||
balanceValue = balanceResult['balance']['amount']
|
||||
print(balanceValue)
|
||||
balanceValue = balanceResult['balance']['amount']/100
|
||||
# print(balanceValue)
|
||||
return balanceValue
|
||||
|
||||
def balance(self):
|
||||
self.sendDoc()
|
||||
balanceValue = self.sendDoc()
|
||||
return balanceValue
|
||||
|
||||
|
|
|
@ -15,6 +15,7 @@ class History:
|
|||
self.dunikey = dunikey
|
||||
self.pubkey = pubkey if pubkey else get_privkey(dunikey, "pubsec").pubkey
|
||||
self.useMempool = useMempool
|
||||
self.node = node
|
||||
if not re.match(PUBKEY_REGEX, self.pubkey) or len(self.pubkey) > 45:
|
||||
sys.stderr.write("La clé publique n'est pas au bon format.\n")
|
||||
sys.exit(1)
|
||||
|
@ -52,6 +53,9 @@ class History:
|
|||
comment
|
||||
}
|
||||
}
|
||||
balance(script: $pubkey) {
|
||||
amount
|
||||
}
|
||||
}
|
||||
"""
|
||||
)
|
||||
|
@ -125,11 +129,14 @@ class History:
|
|||
trans = list(filter(None, trans))
|
||||
trans.sort(key=lambda x: x[1])
|
||||
|
||||
# Get balance
|
||||
balance = self.historyDoc['balance']['amount']/100
|
||||
|
||||
# Get terminal size
|
||||
rows = int(os.popen('stty size', 'r').read().split()[1])
|
||||
|
||||
print('-'.center(rows, '-'))
|
||||
print("{: <20} | {: <45} | {: <7} | {: <30}".format(" Date"," De / À (clé publique)","Montant","Commentaire"))
|
||||
print("\033[1m{: <20} | {: <45} | {: <7} | {: <30}\033[0m".format(" Date"," De / À (clé publique)","Montant (Ḡ1)","Commentaire"))
|
||||
for i in trans:
|
||||
if i[0] == "IN":
|
||||
color = "green"
|
||||
|
@ -141,8 +148,11 @@ class History:
|
|||
|
||||
date = datetime.fromtimestamp(i[1]).strftime("%d/%m/%Y à %H:%M")
|
||||
print('-'.center(rows, '-'))
|
||||
print(colored("{: <20} | {: <45} | {: <7} | {: <30}".format(date, *i[2:]), color))
|
||||
print(colored("| {: <18} | {: <45} | {: <9} | {: <30}".format(date, *i[2:]), color))
|
||||
print('-'.center(rows, '-'))
|
||||
print('\033[1mSolde du compte: {0} Ḡ1\033[0m'.format(balance).center(rows, ' '))
|
||||
print('-'.center(rows, '-'))
|
||||
print(colored('Reçus', 'green'), '-', colored('En cours de réception', 'yellow'), '-', colored('Envoyé', 'blue'), '-', colored("En cours d'envoi", 'red'))
|
||||
|
||||
def history(self):
|
||||
self.sendDoc()
|
||||
|
|
Reference in New Issue