Compare commits

...

2 Commits

Author SHA1 Message Date
poka 21bda9d646 Add pending transcations; Add node and key options 2020-11-25 05:06:57 +01:00
poka 481d13269d Add --node and --key options 2020-11-25 05:06:04 +01:00
3 changed files with 59 additions and 6 deletions

View File

@ -21,9 +21,14 @@ if not node:
# Parse arguments # Parse arguments
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
parser.add_argument('-p', '--pubkey', help="Clé publique du compte visé") 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") parser.add_argument('--mempool', action='store_true', help="Utilise les sources en Mempool")
args = parser.parse_args() args = parser.parse_args()
if args.node: node = args.node
if args.key: dunikey = args.key
# Create transaction and send it # Create transaction and send it
hist = History(dunikey, node, args.pubkey, args.mempool) hist = History(dunikey, node, args.pubkey, args.mempool)
result = hist.history() result = hist.history()

View File

@ -1,6 +1,6 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import sys, re, os.path, json, ast import sys, re, os.path, json, ast, time
from datetime import datetime from datetime import datetime
from termcolor import colored from termcolor import colored
from lib.natools import fmt, sign, get_privkey from lib.natools import fmt, sign, get_privkey
@ -41,6 +41,16 @@ class History:
outputs outputs
comment comment
} }
receiving {
issuers
outputs
comment
}
sending {
issuers
outputs
comment
}
} }
} }
""" """
@ -85,7 +95,33 @@ class History:
transOut[i].append(bloc['comment']) transOut[i].append(bloc['comment'])
i += 1 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 = list(filter(None, trans))
trans.sort(key=lambda x: x[1]) trans.sort(key=lambda x: x[1])
@ -93,16 +129,23 @@ class History:
rows = int(os.popen('stty size', 'r').read().split()[1]) rows = int(os.popen('stty size', 'r').read().split()[1])
print('-'.center(rows, '-')) 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: 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") date = datetime.fromtimestamp(i[1]).strftime("%d/%m/%Y à %H:%M")
print('-'.center(rows, '-')) print('-'.center(rows, '-'))
print(colored("{: <20} | {: <45} | {: <7} | {: <30}".format(date, *i[2:]), color)) print(colored("{: <20} | {: <45} | {: <7} | {: <30}".format(date, *i[2:]), color))
# print(*i) print('-'.center(rows, '-'))
def history(self): def history(self):
self.sendDoc() self.sendDoc()
self.parseHistory() self.parseHistory()

5
pay.py
View File

@ -25,6 +25,8 @@ parser = argparse.ArgumentParser()
parser.add_argument('-d', '--destinataire', help="Destinataire du paiement") parser.add_argument('-d', '--destinataire', help="Destinataire du paiement")
parser.add_argument('-m', '--montant', type=int, help="Montant de la transaction") parser.add_argument('-m', '--montant', type=int, help="Montant de la transaction")
parser.add_argument('-c', '--commentaire', default="", help="Commentaire de la transaction") parser.add_argument('-c', '--commentaire', default="", help="Commentaire de la transaction")
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") parser.add_argument('--mempool', action='store_true', help="Utilise les sources en Mempool")
parser.add_argument('-v', '--verbose', action='store_true', help="Affiche le résultat JSON de la transaction") parser.add_argument('-v', '--verbose', action='store_true', help="Affiche le résultat JSON de la transaction")
parser.add_argument('--version', action='store_true', help="Affiche la version actuelle du programme") parser.add_argument('--version', action='store_true', help="Affiche la version actuelle du programme")
@ -39,6 +41,9 @@ if not args.destinataire or not args.montant:
parser.print_help() parser.print_help()
sys.exit(1) sys.exit(1)
if args.node: node = args.node
if args.key: dunikey = args.key
# Create transaction and send it # Create transaction and send it
trans = Transaction(dunikey, node, args.destinataire, args.montant, args.commentaire, args.mempool, args.verbose) trans = Transaction(dunikey, node, args.destinataire, args.montant, args.commentaire, args.mempool, args.verbose)
result = trans.send() result = trans.send()