Add useMempool option
This commit is contained in:
parent
adfaa5913f
commit
6126dad72b
|
@ -6,19 +6,19 @@ from natools import fmt, sign, get_privkey
|
|||
from gql import gql, Client
|
||||
from gql.transport.aiohttp import AIOHTTPTransport
|
||||
|
||||
VERSION = "0.1.0"
|
||||
PUBKEY_REGEX = "(?![OIl])[1-9A-Za-z]{42,45}"
|
||||
|
||||
class Transaction:
|
||||
|
||||
def __init__(self, dunikey, node, recipient, amount, comment='', verbose=False):
|
||||
def __init__(self, dunikey, node, recipient, amount, comment='', useMempool=False, verbose=False):
|
||||
self.dunikey = dunikey
|
||||
self.recipient = recipient
|
||||
self.amount = amount
|
||||
self.comment = comment
|
||||
self.issuer = get_privkey(dunikey, "pubsec").pubkey
|
||||
self.useMempool = useMempool
|
||||
self.verbose = verbose
|
||||
self.isChange = False
|
||||
self._isChange = False
|
||||
|
||||
if not re.match(PUBKEY_REGEX, recipient) or len(recipient) > 45:
|
||||
sys.stderr.write("La clé publique n'est pas au bon format.\n")
|
||||
|
@ -34,14 +34,15 @@ class Transaction:
|
|||
|
||||
def genDoc(self):
|
||||
# Build TX generation document
|
||||
print(self.useMempool)
|
||||
queryBuild = gql(
|
||||
"""
|
||||
query ($recipient: String!, $issuer: String!, $amount: Int!, $comment: String!, $isChange: Boolean!){ genTxs(
|
||||
query ($recipient: String!, $issuer: String!, $amount: Int!, $comment: String!, $useMempool: Boolean!){ genTxs(
|
||||
amount: $amount
|
||||
comment: $comment
|
||||
issuer: $issuer
|
||||
recipient: $recipient
|
||||
useMempoolSources: $isChange
|
||||
useMempoolSources: $useMempool
|
||||
)
|
||||
}
|
||||
"""
|
||||
|
@ -51,7 +52,7 @@ class Transaction:
|
|||
"issuer": self.issuer,
|
||||
"amount": self.amount,
|
||||
"comment": self.comment,
|
||||
"isChange": self.isChange
|
||||
"useMempool": self.useMempool
|
||||
}
|
||||
|
||||
# Send TX document
|
||||
|
@ -144,6 +145,13 @@ class Transaction:
|
|||
|
||||
return txResult
|
||||
|
||||
def _getIsChange(self):
|
||||
return self._isChange
|
||||
def _setIsChange(self, newChange):
|
||||
self._isChange = newChange
|
||||
if newChange: self.useMempool == True
|
||||
isChange = property(_getIsChange, _setIsChange)
|
||||
|
||||
def send(self):
|
||||
result = self.genDoc()
|
||||
result = self.checkTXDoc()
|
||||
|
|
7
pay.py
7
pay.py
|
@ -4,7 +4,9 @@ import sys, argparse, os
|
|||
from os.path import join, dirname
|
||||
from shutil import copyfile
|
||||
from dotenv import load_dotenv
|
||||
from libs.paylib import Transaction, VERSION
|
||||
from libs.paylib import Transaction
|
||||
|
||||
VERSION = "0.1.1"
|
||||
|
||||
# Get variables environment
|
||||
if not os.path.isfile('.env'):
|
||||
|
@ -23,6 +25,7 @@ parser = argparse.ArgumentParser()
|
|||
parser.add_argument('-d', '--destinataire', help="Destinataire du paiement")
|
||||
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('--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('--version', action='store_true', help="Affiche la version actuelle du programme")
|
||||
args = parser.parse_args()
|
||||
|
@ -37,7 +40,7 @@ if not args.destinataire or not args.montant:
|
|||
sys.exit(1)
|
||||
|
||||
# Create transaction and send it
|
||||
trans = Transaction(dunikey, node, args.destinataire, args.montant, args.commentaire, args.verbose)
|
||||
trans = Transaction(dunikey, node, args.destinataire, args.montant, args.commentaire, args.mempool, args.verbose)
|
||||
result = trans.send()
|
||||
|
||||
if args.verbose:
|
||||
|
|
Reference in New Issue