From 1d592d9a23d34bc5cd2c26e268775ed88b0769d4 Mon Sep 17 00:00:00 2001 From: Kristaps Kaupe Date: Tue, 16 Jun 2020 01:05:47 +0300 Subject: [PATCH] Check for pushtx() success in direct_send() --- jmclient/jmclient/taker_utils.py | 25 +++++++++++++++---------- scripts/joinmarket-qt.py | 10 +++++++--- 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/jmclient/jmclient/taker_utils.py b/jmclient/jmclient/taker_utils.py index 1752385..7ee1e05 100644 --- a/jmclient/jmclient/taker_utils.py +++ b/jmclient/jmclient/taker_utils.py @@ -22,7 +22,7 @@ Currently re-used by CLI script tumbler.py and joinmarket-qt """ def direct_send(wallet_service, amount, mixdepth, destination, answeryes=False, - accept_callback=None, info_callback=None, + accept_callback=None, info_callback=None, error_callback=None, return_transaction=False, with_final_psbt=False, optin_rbf=False): """Send coins directly from one mixdepth to one destination address; @@ -38,8 +38,8 @@ def direct_send(wallet_service, amount, mixdepth, destination, answeryes=False, returns: True if accepted, False if not ==== - The info_callback takes one parameter, the information message (when tx is - pushed), and returns nothing. + info_callback and error_callback takes one parameter, the information + message (when tx is pushed or error occured), and returns nothing. This function returns: 1. False if there is any failure. @@ -187,13 +187,18 @@ def direct_send(wallet_service, amount, mixdepth, destination, answeryes=False, destination, actual_amount, fee_est) if not accepted: return False - jm_single().bc_interface.pushtx(tx.serialize()) - txid = bintohex(tx.GetTxid()[::-1]) - successmsg = "Transaction sent: " + txid - cb = log.info if not info_callback else info_callback - cb(successmsg) - txinfo = txid if not return_transaction else tx - return txinfo + if jm_single().bc_interface.pushtx(tx.serialize()): + txid = bintohex(tx.GetTxid()[::-1]) + successmsg = "Transaction sent: " + txid + cb = log.info if not info_callback else info_callback + cb(successmsg) + txinfo = txid if not return_transaction else tx + return txinfo + else: + errormsg = "Transaction broadcast failed!" + cb = log.error if not error_callback else error_callback + cb(errormsg) + return False def get_tumble_log(logsdir): tumble_log = logging.getLogger('tumbler') diff --git a/scripts/joinmarket-qt.py b/scripts/joinmarket-qt.py index cbfa6d5..667bd26 100755 --- a/scripts/joinmarket-qt.py +++ b/scripts/joinmarket-qt.py @@ -650,8 +650,11 @@ class SpendTab(QWidget): else: return False - def infoDirectSend(self, txid): - JMQtMessageBox(self, "Tx sent: " + str(txid), title="Success") + def infoDirectSend(self, msg): + JMQtMessageBox(self, msg, title="Success") + + def errorDirectSend(self, msg): + JMQtMessageBox(self, msg, mbtype="warn", title="Error") def startSingle(self): if not self.spendstate.runstate == 'ready': @@ -672,7 +675,8 @@ class SpendTab(QWidget): try: txid = direct_send(mainWindow.wallet_service, amount, mixdepth, destaddr, accept_callback=self.checkDirectSend, - info_callback=self.infoDirectSend) + info_callback=self.infoDirectSend, + error_callback=self.errorDirectSend) except Exception as e: JMQtMessageBox(self, e.args[0], title="Error", mbtype="warn") return