Commit b4005b32 authored by matograine's avatar matograine
parents 4f45bd39 fa2c3066
......@@ -10,6 +10,18 @@ Le logiciel n'est pas encore packagé, vous devez l'installer à la main.
## Installation des dépendances DEBIAN
<<<<<<< HEAD
=======
- `python3`
- `pip3`
- `git`
Nous avons rencontré des soucis sur ces dépendances :
- `tkinter` -> installer le paquet python3-tk (sur Debian Buster)
### Debian :
>>>>>>> fa2c3066473df9428a933dbbb59a4af2449b1a6a
```
$ sudo apt-get install python3 python3-pip git python3-qrcode python3-reportlab python3-pil ; sudo python3.5 -m pip install duniterpy
......@@ -26,11 +38,12 @@ $ pip3 install -r requirements.txt
# Utilisation
Actuellement le logiciel s'exécute en ligne de commande :
Actuellement le logiciel se lance en ligne de commande :
```
$ ./main.py <pages>
$ ./main.py
```
Une interface graphique se lance.
Les pourboires générés sont stockés dans `~/Documents/G1pourboire/`. Deux fichiers sont créés :
......
......@@ -28,3 +28,65 @@ root.mainloop () # on affiche enfin la fenêtre principal et on attend
##### JE NE SAIS PAS CE QUI SUIT #####
# await Creating(amount, pages).create()
# c=Creating(float(argv[1]), int(argv[2]))
# await c.create()
=======
from tkinter import *
from generator import Generator
## Variables ##
## Classes ##
## Fonctions ##
def logger (texte) :
logs.config (state = NORMAL)
logs.insert (END, texte + "\n")
logs.config (state = DISABLED)
def generer () :
nombre = nbr_feuille.get ()
g = Generator(int(nombre))
g.generate()
logger ("Les Ğ1Pourboires ont été générés.\nVous les trouverez dans le dossier Documents/G1pourboires.")
def generer_evt (evt) :
generer ()
## Fenêtre ##
root = Tk () # création de la fenêtre principale
root.title ("Ğ1pourboire")
# Premier frame (générateur)
f1 = LabelFrame (root, text = "Générateur de Ğ1Pourboires", width = 80, borderwidth = 2, relief = GROOVE, padx = 10 , pady = 10)
f1.pack ()
q_nombre = Label (f1, text = "Les pourboires sont générés par pages de 6.\nCombien de pages voulez-vous créer ?", width = 40)
q_nombre.pack (side = LEFT)
nbr_feuille = Entry (f1, width = 10)
nbr_feuille.pack (side = LEFT, padx = 5)
nbr_feuille.bind ( "<Return>" , generer_evt )
nbr_feuille.focus_set ()
bouton = Button (f1, text = "Générer", width = 10, command = generer )
bouton.pack (side = LEFT, padx = 50)
bouton.bind ("<Return>", generer_evt)
# Second frame (logs)
f3 = LabelFrame (root, text = "Logs" , width = 1000, borderwidth = 2, relief = GROOVE, padx = 10 , pady = 10)
f3.pack ()
logs = Text (f3, height = 10, bg = "white")
logs.pack ()
logs.config (state = DISABLED)
# Fin de la fenêtre
root.mainloop ()
>>>>>>> fa2c3066473df9428a933dbbb59a4af2449b1a6a
\ No newline at end of file
#!/usr/bin/env python3
#<<<<<<< HEAD
# -*- coding: utf-8 -*-
# Voir https://stackoverflow.com/questions/42009202/how-to-call-a-async-function-contained-in-a-class
......@@ -36,10 +37,3 @@ async def create(session, amount, pages):
if __name__ == "__main__":
loop = asyncio.get_event_loop()
loop.run_until_complete(main(loop, amount, pages))
# await Creating(amount, pages).create()
# c=Creating(float(argv[1]), int(argv[2]))
# await c.create()
<<<<<<< HEAD
python>=3.7
=======
>>>>>>> fa2c3066473df9428a933dbbb59a4af2449b1a6a
duniterpy>=0.54.3
Pillow>=6.0.0
qrcode>=6.1
reportlab>=3.5.23
<<<<<<< HEAD
silkaj==0.6.5
=======
>>>>>>> fa2c3066473df9428a933dbbb59a4af2449b1a6a
......@@ -4,3 +4,82 @@
# sign transactions
# It should be more efficient to rewrite this than to use silkaj as a module (it needs a click context).
from utils.network import ClientInstance
from duniterpy.api.bma import tx, blockchain
from duniterpy.api.client import Client
async def get_amount_from_pubkey(pubkey):
listinput, amount = await get_sources(pubkey)
totalAmountInput = 0
for input in listinput:
totalAmountInput += amount_in_current_base(input)
return totalAmountInput, amount
# get sources
async def get_sources(pubkey):
"""
Get unused sources of a pubkey
"""
client = ClientInstance().client
# Sources written into the blockchain
sources = await client(tx.sources, pubkey)
listinput = list()
amount = 0
for source in sources["sources"]:
if source["conditions"] == "SIG(" + pubkey + ")":
listinput.append(
InputSource(
amount=source["amount"],
base=source["base"],
source=source["type"],
origin_id=source["identifier"],
index=source["noffset"],
)
)
amount += amount_in_current_base(listinput[-1])
# pending source
history = await client(tx.pending, pubkey)
history = history["history"]
pendings = history["sending"] + history["receiving"] + history["pending"]
# add pending output
pending_sources = list()
for i, pending in enumerate(pendings):
identifier = pending["hash"]
for output in pending["outputs"]:
outputsplited = output.split(":")
if outputsplited[2] == "SIG(" + pubkey + ")":
inputgenerated = InputSource(
amount=int(outputsplited[0]),
base=int(outputsplited[1]),
source="T",
origin_id=identifier,
index=i,
)
if inputgenerated not in listinput:
listinput.append(inputgenerated)
for input in pending["inputs"]:
pending_sources.append(InputSource.from_inline(input))
# remove input already used
for input in listinput:
if input in pending_sources:
listinput.remove(input)
await client.close() #ajouté par TN
return listinput, amount
def amount_in_current_base(source):
"""
Get amount in current base from input or output source
"""
return source.amount * 10 ** source.base
......@@ -3,3 +3,19 @@
# close a connection with BMA
# send documents
# receive documents (?)
# May get lot of code from Silkaj.
#from asyncio import sleep
from duniterpy.api.client import Client
#from duniterpy.api.bma import blockchain, network
#Defaults (to be moved after tests)
BMA_ENDPOINT="BMAS ts.gt.librelois.fr 443"
#BMA_ENDPOINT=["BMAS", "ts.gt.librelois.fr", "443"]
#BMA_ENDPOINT=["BASIC_MERKLED_API", "ts.gt.librelois.fr", 443]
#from Silkaj : create client instance
class ClientInstance(object):
def __init__(self):
self.client = Client(BMA_ENDPOINT)
from duniterpy.key import SigningKey
from datetime import datetime
from time import sleep
from utils.diceware import diceware
from utils.money import get_amount_from_pubkey
from utils.network import ClientInstance
import os
import json
......@@ -25,12 +27,14 @@ class Transfer:
Ask for transferring the total amount on an intermediary account,
transfer the money to tips
"""
# client = ClientInstance().client
total_amount = round(self.amount * 6 * self.pages, 2)
self.add_transfer_wallet()
self.save_json() # A verifier
print("Send ", total_amount, "Ğ1 to : ", self.key.pubkey)
await self.wait_funding(total_amount, self.key.pubkey)
await self.transfer_tips()
# await client.close()
def add_transfer_wallet(self):
""" Add data for transfer_wallet to wallets"""
......@@ -49,14 +53,19 @@ class Transfer:
check that the amount is correct
send back incorrect amounts.
"""
print("FALSE Waiting for payment on ", key)
# pubkey_amount = await balance (key)
# check amount
# if pubkey_amount != amount:
# print ("Waiting for reception of ", amount, " Ğ1 on account : ", key, ". Waiting 3 minutes.")
# sleep 180
# else :
return 0 # TEST
# client = ClientInstance().client
pubkey_amount = 0, 0
if pubkey_amount[0] != amount:
pubkey_amount = await get_amount_from_pubkey (key)
print ("Waiting for reception of ", amount, " Ğ1 on account : ", key, ". Waiting 3 minutes.")
sleep (20)
print("TEST amount : ", pubkey_amount)
# await client.close()
else :
print("TEST amount : ", pubkey_amount)
# await client.close()
return 0 # TEST
async def transfer_tips(self):
"""
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment