Browse Source

Merge #600: Check for pushtx() success in direct_send()

1d592d9 Check for pushtx() success in direct_send() (Kristaps Kaupe)
master
Adam Gibson 6 years ago
parent
commit
1078a88788
No known key found for this signature in database
GPG Key ID: 141001A1AF77F20B
  1. 25
      jmclient/jmclient/taker_utils.py
  2. 10
      scripts/joinmarket-qt.py

25
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, 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, return_transaction=False, with_final_psbt=False,
optin_rbf=False): optin_rbf=False):
"""Send coins directly from one mixdepth to one destination address; """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: returns:
True if accepted, False if not True if accepted, False if not
==== ====
The info_callback takes one parameter, the information message (when tx is info_callback and error_callback takes one parameter, the information
pushed), and returns nothing. message (when tx is pushed or error occured), and returns nothing.
This function returns: This function returns:
1. False if there is any failure. 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) destination, actual_amount, fee_est)
if not accepted: if not accepted:
return False return False
jm_single().bc_interface.pushtx(tx.serialize()) if jm_single().bc_interface.pushtx(tx.serialize()):
txid = bintohex(tx.GetTxid()[::-1]) txid = bintohex(tx.GetTxid()[::-1])
successmsg = "Transaction sent: " + txid successmsg = "Transaction sent: " + txid
cb = log.info if not info_callback else info_callback cb = log.info if not info_callback else info_callback
cb(successmsg) cb(successmsg)
txinfo = txid if not return_transaction else tx txinfo = txid if not return_transaction else tx
return txinfo 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): def get_tumble_log(logsdir):
tumble_log = logging.getLogger('tumbler') tumble_log = logging.getLogger('tumbler')

10
scripts/joinmarket-qt.py

@ -650,8 +650,11 @@ class SpendTab(QWidget):
else: else:
return False return False
def infoDirectSend(self, txid): def infoDirectSend(self, msg):
JMQtMessageBox(self, "Tx sent: " + str(txid), title="Success") JMQtMessageBox(self, msg, title="Success")
def errorDirectSend(self, msg):
JMQtMessageBox(self, msg, mbtype="warn", title="Error")
def startSingle(self): def startSingle(self):
if not self.spendstate.runstate == 'ready': if not self.spendstate.runstate == 'ready':
@ -672,7 +675,8 @@ class SpendTab(QWidget):
try: try:
txid = direct_send(mainWindow.wallet_service, amount, mixdepth, txid = direct_send(mainWindow.wallet_service, amount, mixdepth,
destaddr, accept_callback=self.checkDirectSend, destaddr, accept_callback=self.checkDirectSend,
info_callback=self.infoDirectSend) info_callback=self.infoDirectSend,
error_callback=self.errorDirectSend)
except Exception as e: except Exception as e:
JMQtMessageBox(self, e.args[0], title="Error", mbtype="warn") JMQtMessageBox(self, e.args[0], title="Error", mbtype="warn")
return return

Loading…
Cancel
Save