Mixte CLI/GUI
This commit is contained in:
parent
2a1819e0f3
commit
7b8c0c82bc
29
pay-gui.py
29
pay-gui.py
|
@ -1,25 +1,36 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
from tkinter import *
|
from tkinter import *
|
||||||
import pay
|
from pay import *
|
||||||
|
|
||||||
window = Tk()
|
window = Tk()
|
||||||
|
|
||||||
title = Label(window, text="Paiement Ḡ1")
|
title = Label(window, text="Paiement Ḡ1")
|
||||||
title.pack()
|
title.pack()
|
||||||
|
|
||||||
# Issuer input
|
# Recipient input
|
||||||
issuer = StringVar()
|
recipientEntry = Entry()
|
||||||
xIssuer = Entry(window, textvariable=issuer, width=30)
|
# xRecipient = Entry(window, textvariable=recipient, width=30)
|
||||||
xIssuer.pack()
|
recipientEntry.pack()
|
||||||
|
|
||||||
|
|
||||||
|
# Amount input
|
||||||
|
AmountEntry = Entry()
|
||||||
|
AmountEntry.pack()
|
||||||
|
|
||||||
# Comment input
|
# Comment input
|
||||||
comment = StringVar()
|
commentEntry = Entry()
|
||||||
xComment = Entry(window, textvariable=comment, width=30)
|
commentEntry.pack()
|
||||||
xComment.pack()
|
|
||||||
|
|
||||||
def ProceedPaiement():
|
def ProceedPaiement():
|
||||||
print("Paiement en cours ...")
|
recipient = str(recipientEntry.get())
|
||||||
|
amount = int(AmountEntry.get())
|
||||||
|
comment = str(commentEntry.get())
|
||||||
|
print("Paiement en cours ... " + recipient)
|
||||||
|
returnGen = sendGenDoc(recipient, amount, comment)
|
||||||
|
checkTXDoc(returnGen)
|
||||||
|
returnSigned = signDoc(returnGen)
|
||||||
|
sendTXDoc(returnSigned)
|
||||||
|
|
||||||
sendButton = Button(window, text="Envoyer", command=ProceedPaiement)
|
sendButton = Button(window, text="Envoyer", command=ProceedPaiement)
|
||||||
sendButton.pack()
|
sendButton.pack()
|
||||||
|
|
34
pay.py
34
pay.py
|
@ -17,17 +17,22 @@ if not (dunikey):
|
||||||
# Define Duniter GVA node
|
# Define Duniter GVA node
|
||||||
transport = AIOHTTPTransport(url=node)
|
transport = AIOHTTPTransport(url=node)
|
||||||
client = Client(transport=transport, fetch_schema_from_transport=True)
|
client = Client(transport=transport, fetch_schema_from_transport=True)
|
||||||
|
|
||||||
issuer = get_privkey(dunikey, "pubsec").pubkey
|
issuer = get_privkey(dunikey, "pubsec").pubkey
|
||||||
|
|
||||||
|
try:
|
||||||
recipient = sys.argv[1]
|
recipient = sys.argv[1]
|
||||||
amount = int(sys.argv[2])
|
amount = int(sys.argv[2])
|
||||||
if len(sys.argv) > 3:
|
if len(sys.argv) > 3:
|
||||||
comment = sys.argv[3]
|
comment = sys.argv[3]
|
||||||
else:
|
else:
|
||||||
comment = ""
|
comment = ""
|
||||||
|
graphic = False
|
||||||
|
except:
|
||||||
|
graphic = True
|
||||||
|
|
||||||
## GraphQL queries
|
|
||||||
# Build the TX Document
|
def sendGenDoc(recipient, amount, comment):
|
||||||
|
# Build TX generation document
|
||||||
queryBuild = gql(
|
queryBuild = gql(
|
||||||
"""
|
"""
|
||||||
query ($recipient: String!, $issuer: String!, $amount: Int!, $comment: String!){ genTxs(
|
query ($recipient: String!, $issuer: String!, $amount: Int!, $comment: String!){ genTxs(
|
||||||
|
@ -49,14 +54,15 @@ paramsBuild = {
|
||||||
# Send TX document
|
# Send TX document
|
||||||
try:
|
try:
|
||||||
txDoc = str(client.execute(queryBuild, variable_values=paramsBuild))[13:-3].replace('\\n','\n')
|
txDoc = str(client.execute(queryBuild, variable_values=paramsBuild))[13:-3].replace('\\n','\n')
|
||||||
|
return txDoc
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
#e = json.dumps(str(e))
|
#e = json.dumps(str(e))
|
||||||
sys.stderr.write("Echec de la génération du document:\n" + str(e) + "\n")
|
sys.stderr.write("Echec de la génération du document:\n" + str(e) + "\n")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
# Check document
|
|
||||||
|
|
||||||
# print(txDoc) # For debug
|
# Check document
|
||||||
|
def checkTXDoc(txDoc):
|
||||||
docList = txDoc.splitlines()
|
docList = txDoc.splitlines()
|
||||||
for i, line in enumerate(docList):
|
for i, line in enumerate(docList):
|
||||||
if re.search("Issuers:", line):
|
if re.search("Issuers:", line):
|
||||||
|
@ -74,15 +80,19 @@ if issuerRaw != issuer or int(outAmount) != amount or outPubkey != recipient or
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
else:
|
else:
|
||||||
print("Le document généré est conforme.")
|
print("Le document généré est conforme.")
|
||||||
|
return True
|
||||||
|
|
||||||
# sys.exit(0) # For debug
|
|
||||||
|
|
||||||
|
def signDoc(txDoc):
|
||||||
# Sign TX document
|
# Sign TX document
|
||||||
signature = fmt["64"](sign(txDoc.encode(), get_privkey(dunikey, "pubsec"))[:-len(txDoc.encode())])
|
signature = fmt["64"](sign(txDoc.encode(), get_privkey(dunikey, "pubsec"))[:-len(txDoc.encode())])
|
||||||
signedDoc = txDoc + signature.decode()
|
signedDoc = txDoc + signature.decode()
|
||||||
|
|
||||||
#print(signedDoc) # For debug
|
return signedDoc
|
||||||
|
|
||||||
|
|
||||||
|
def sendTXDoc(signedDoc):
|
||||||
|
# Build TX document
|
||||||
querySign = gql(
|
querySign = gql(
|
||||||
"""
|
"""
|
||||||
mutation ($signedDoc: String!){ tx(
|
mutation ($signedDoc: String!){ tx(
|
||||||
|
@ -101,12 +111,20 @@ paramsSign = {
|
||||||
|
|
||||||
# Send TX Signed document
|
# Send TX Signed document
|
||||||
try:
|
try:
|
||||||
sentTX = client.execute(querySign, variable_values=paramsSign)
|
client.execute(querySign, variable_values=paramsSign)
|
||||||
print(colored("Transaction effectué avec succès !", "green"))
|
print(colored("Transaction effectué avec succès !", "green"))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
sys.stderr.write("Echec de la transaction:\n" + str(e) + "\n")
|
sys.stderr.write("Echec de la transaction:\n" + str(e) + "\n")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
|
# Execute workflow
|
||||||
|
if not graphic:
|
||||||
|
returnGen = sendGenDoc(recipient, amount, comment)
|
||||||
|
docIsOK = checkTXDoc(returnGen)
|
||||||
|
returnSigned = signDoc(returnGen)
|
||||||
|
sendTXDoc(returnSigned)
|
||||||
|
|
||||||
#print(sentTX) #For debug
|
#print(sentTX) #For debug
|
||||||
|
|
||||||
|
|
||||||
|
|
Reference in New Issue