Changes transactions supported
This commit is contained in:
parent
98ccc9b6ae
commit
550a0a68ef
|
@ -19,12 +19,13 @@ transport = AIOHTTPTransport(url=node)
|
||||||
client = Client(transport=transport, fetch_schema_from_transport=True)
|
client = Client(transport=transport, fetch_schema_from_transport=True)
|
||||||
|
|
||||||
|
|
||||||
class Transaction():
|
class Transaction:
|
||||||
def __init__(self, recipient, amount, comment=''):
|
def __init__(self, recipient, amount, comment=''):
|
||||||
self.recipient = recipient
|
self.recipient = recipient
|
||||||
self.amount = amount
|
self.amount = amount
|
||||||
self.comment = comment
|
self.comment = comment
|
||||||
self.issuer = get_privkey(dunikey, "pubsec").pubkey
|
self.issuer = get_privkey(dunikey, "pubsec").pubkey
|
||||||
|
self.isChange = False
|
||||||
|
|
||||||
if not re.match(r"(?![OIl])[1-9A-Za-z]{42,45}", self.recipient):
|
if not re.match(r"(?![OIl])[1-9A-Za-z]{42,45}", self.recipient):
|
||||||
sys.stderr.write("Issuer pubkey is not to good format.\n")
|
sys.stderr.write("Issuer pubkey is not to good format.\n")
|
||||||
|
@ -34,11 +35,12 @@ class Transaction():
|
||||||
# Build TX generation document
|
# 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!, $isChange: Boolean!){ genTxs(
|
||||||
amount: $amount
|
amount: $amount
|
||||||
comment: $comment
|
comment: $comment
|
||||||
issuer: $issuer
|
issuer: $issuer
|
||||||
recipient: $recipient
|
recipient: $recipient
|
||||||
|
useMempoolSources: $isChange
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
|
@ -47,7 +49,8 @@ class Transaction():
|
||||||
"recipient": self.recipient,
|
"recipient": self.recipient,
|
||||||
"issuer": self.issuer,
|
"issuer": self.issuer,
|
||||||
"amount": self.amount,
|
"amount": self.amount,
|
||||||
"comment": self.comment
|
"comment": self.comment,
|
||||||
|
"isChange": self.isChange
|
||||||
}
|
}
|
||||||
|
|
||||||
# Send TX document
|
# Send TX document
|
||||||
|
@ -73,12 +76,19 @@ class Transaction():
|
||||||
if re.search("Comment:", line):
|
if re.search("Comment:", line):
|
||||||
commentRaw = line.split(': ', 1)[1]
|
commentRaw = line.split(': ', 1)[1]
|
||||||
|
|
||||||
if issuerRaw != self.issuer or int(outAmount) != self.amount or outPubkey != self.recipient or commentRaw != self.comment:
|
# Check if is change transaction
|
||||||
|
if issuerRaw == outPubkey:
|
||||||
|
print("Ce document contient une transaction de change")
|
||||||
|
self.isChange = True
|
||||||
|
|
||||||
|
# Check validity of the document
|
||||||
|
elif issuerRaw != self.issuer or int(outAmount) != self.amount or outPubkey != self.recipient or commentRaw != self.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("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.stderr.write(colored(issuerRaw + " envoi " + outAmount + " vers " + outPubkey + " with comment: " + commentRaw + "\n", "yellow"))
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
else:
|
else:
|
||||||
print("Le document généré est conforme.")
|
print("Le document généré est conforme.")
|
||||||
|
self.isChange = False
|
||||||
return self.txDoc
|
return self.txDoc
|
||||||
|
|
||||||
|
|
||||||
|
@ -109,12 +119,18 @@ class Transaction():
|
||||||
|
|
||||||
# Send TX Signed document
|
# Send TX Signed document
|
||||||
try:
|
try:
|
||||||
client.execute(querySign, variable_values=paramsSign)
|
txResult = str(client.execute(querySign, variable_values=paramsSign))
|
||||||
print(colored("Transaction effectué avec succès !", "green"))
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
message = ast.literal_eval(str(e))["message"]
|
message = ast.literal_eval(str(e))["message"]
|
||||||
sys.stderr.write("Echec de la transaction:\n" + message + "\n")
|
sys.stderr.write("Echec de la transaction:\n" + message + "\n")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
else:
|
||||||
|
# print(txResult)
|
||||||
|
if self.isChange:
|
||||||
|
self.send()
|
||||||
|
else:
|
||||||
|
print(colored("Transaction effectué avec succès !", "green"))
|
||||||
|
return txResult
|
||||||
|
|
||||||
def send(self):
|
def send(self):
|
||||||
self.genDoc()
|
self.genDoc()
|
||||||
|
|
Reference in New Issue