Add pending transcations; Add node and key options

This commit is contained in:
poka 2020-11-25 05:06:57 +01:00
parent 481d13269d
commit 21bda9d646
2 changed files with 54 additions and 6 deletions

View File

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

View File

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