From 21bda9d6468d7a1e1f75824efc87df0e020c03ef Mon Sep 17 00:00:00 2001 From: poka Date: Wed, 25 Nov 2020 05:06:57 +0100 Subject: [PATCH] Add pending transcations; Add node and key options --- history.py | 5 +++++ lib/historylib.py | 55 +++++++++++++++++++++++++++++++++++++++++------ 2 files changed, 54 insertions(+), 6 deletions(-) diff --git a/history.py b/history.py index 03b5cf4..ee7b553 100755 --- a/history.py +++ b/history.py @@ -21,9 +21,14 @@ if not node: # Parse arguments parser = argparse.ArgumentParser() parser.add_argument('-p', '--pubkey', help="Clé publique du compte visé") +parser.add_argument('-n', '--node', help="Sélection d'un noeud Duniter à utiliser") +parser.add_argument('-k', '--key', help="Chemin vers notre fichier de trousseau (PubSec)") parser.add_argument('--mempool', action='store_true', help="Utilise les sources en Mempool") args = parser.parse_args() +if args.node: node = args.node +if args.key: dunikey = args.key + # Create transaction and send it hist = History(dunikey, node, args.pubkey, args.mempool) result = hist.history() diff --git a/lib/historylib.py b/lib/historylib.py index eef7894..0daeb84 100644 --- a/lib/historylib.py +++ b/lib/historylib.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 -import sys, re, os.path, json, ast +import sys, re, os.path, json, ast, time from datetime import datetime from termcolor import colored from lib.natools import fmt, sign, get_privkey @@ -41,6 +41,16 @@ class History: outputs comment } + receiving { + issuers + outputs + comment + } + sending { + issuers + outputs + comment + } } } """ @@ -85,7 +95,33 @@ class History: transOut[i].append(bloc['comment']) i += 1 - trans = transIn + transOut + res = self.historyDoc['transactionsHistory']['receiving'] + transInMempool=[[0 for x in range(0)] for y in range(len(res))] + for i, bloc in enumerate(res): + for output in bloc['outputs']: + if re.search(self.pubkey, output): + transInMempool[i].append("INM") + transInMempool[i].append(int(time.time())) + transInMempool[i].append(bloc['issuers'][0]) + transInMempool[i].append(int(output.split(':')[0])/100) + transInMempool[i].append(bloc['comment']) + + res = self.historyDoc['transactionsHistory']['sending'] + transOutMempool=[[0 for x in range(0)] for y in range(len(res))] + i = 0 + for bloc in res: + for output in bloc['outputs']: + if not re.search(self.pubkey, output): + transOutMempool[i].append("OUTM") + transOutMempool[i].append(int(time.time())) + transOutMempool[i].append(output.split("SIG(")[1].replace(')','')) + transOutMempool[i].append(int(output.split(':')[0])/100) + transOutMempool[i].append(bloc['comment']) + i += 1 + + + + trans = transIn + transOut + transInMempool + transOutMempool trans = list(filter(None, trans)) trans.sort(key=lambda x: x[1]) @@ -93,16 +129,23 @@ class History: rows = int(os.popen('stty size', 'r').read().split()[1]) print('-'.center(rows, '-')) - print("{: <20} | {: <45} | {: <7} | {: <30}".format(" Date"," De la part de (clé publique)","Montant","Commentaire")) + print("{: <20} | {: <45} | {: <7} | {: <30}".format(" Date"," De / À (clé publique)","Montant","Commentaire")) for i in trans: - color = "green" if i[0] == "IN" else "blue" + if i[0] == "IN": + color = "green" + elif i[0] == "INM": + color = "yellow" + elif i[0] == "OUTM": + color = "red" + else: color = "blue" + 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(*i) - + print('-'.center(rows, '-')) def history(self): self.sendDoc() self.parseHistory() +