Test if generated document by Duniter is conforme to request.
This commit is contained in:
parent
94b007d3ea
commit
925da50f64
40
pay.py
40
pay.py
|
@ -1,9 +1,10 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
import sys, os.path, json
|
||||
import sys, re, os.path, json
|
||||
from shutil import copyfile
|
||||
if not os.path.isfile("userEnv.py"):
|
||||
copyfile("userEnv.py.template", "userEnv.py")
|
||||
from termcolor import colored
|
||||
from userEnv import issuer, dunikey, node
|
||||
from natools import fmt, sign, get_privkey
|
||||
from gql import gql, Client
|
||||
|
@ -43,17 +44,38 @@ paramsBuild = {
|
|||
|
||||
# Send TX document
|
||||
try:
|
||||
txDoc = str(client.execute(queryBuild, variable_values=paramsBuild))[13:-3].replace('\\n','\n').encode()
|
||||
print("Document généré avec succès.")
|
||||
txDoc = str(client.execute(queryBuild, variable_values=paramsBuild))[13:-3].replace('\\n','\n')
|
||||
except Exception as e:
|
||||
print("Echec d'obtention du document de transaction:" + str(e))
|
||||
#e = json.dumps(str(e))
|
||||
sys.stderr.write("Echec de la génération du document:\n" + str(e) + "\n")
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
# Check document
|
||||
|
||||
#print(txDoc) # For debug
|
||||
|
||||
docList = txDoc.splitlines()
|
||||
for i, line in enumerate(docList):
|
||||
if re.search("Issuers:", line):
|
||||
issuerRaw = docList[(i + 1) % len(docList)]
|
||||
if re.search("Outputs:", line):
|
||||
outputRaw = docList[(i + 1) % len(docList)].split(":")
|
||||
outAmount = outputRaw[0]
|
||||
outPubkey = outputRaw[2].split("SIG(")[1].replace(')','')
|
||||
if re.search("Comment:", line):
|
||||
commentRaw = line.split(': ')[-1]
|
||||
|
||||
if issuerRaw != issuer or int(outAmount) != amount or outPubkey != recipient or commentRaw != comment:
|
||||
sys.stderr.write(colored("Le document généré est corrompu !\nNe fait plus confiance au noeud " + node + "\n", 'red'))
|
||||
sys.stderr.write(colored(issuerRaw + " envoi " + outAmount + " vers " + outPubkey + " with comment: " + commentRaw + "\n", "yellow"))
|
||||
sys.exit(1)
|
||||
|
||||
print("Le document généré est conforme.")
|
||||
# sys.exit(0)
|
||||
|
||||
# Sign TX document
|
||||
signature = fmt["64"](sign(txDoc, get_privkey(dunikey, "pubsec"))[:-len(txDoc)])
|
||||
signedDoc = txDoc.decode() + signature.decode()
|
||||
signature = fmt["64"](sign(txDoc.encode(), get_privkey(dunikey, "pubsec"))[:-len(txDoc.encode())])
|
||||
signedDoc = txDoc + signature.decode()
|
||||
|
||||
#print(signedDoc) # For debug
|
||||
|
||||
|
@ -76,9 +98,9 @@ paramsSign = {
|
|||
# Send TX Signed document
|
||||
try:
|
||||
sentTX = client.execute(querySign, variable_values=paramsSign)
|
||||
print("Transaction effectué avec succès !")
|
||||
print(colored("Transaction effectué avec succès !", "green"))
|
||||
except Exception as e:
|
||||
print("Echec de la transaction:" + str(e))
|
||||
sys.stderr.write("Echec de la transaction:\n" + str(e) + "\n")
|
||||
sys.exit(1)
|
||||
|
||||
#print(sentTX) #For debug
|
||||
|
|
|
@ -1,2 +1,3 @@
|
|||
gql
|
||||
duniterpy
|
||||
duniterpy
|
||||
termcolor
|
||||
|
|
Reference in New Issue