Browse Source

Qt: fix async JMQtMessageBox usage part2

add_frost_channel_encryption
zebra-lucky 2 months ago
parent
commit
62d94a9479
  1. 100
      scripts/joinmarket-qt.py

100
scripts/joinmarket-qt.py

@ -772,7 +772,7 @@ class SpendTab(QWidget):
self.updateSchedView() self.updateSchedView()
self.startJoin() self.startJoin()
def checkDirectSend(self, dtx, destaddr, amount, fee, custom_change_addr): async def checkDirectSend(self, dtx, destaddr, amount, fee, custom_change_addr):
"""Give user info to decide whether to accept a direct send; """Give user info to decide whether to accept a direct send;
note the callback includes the full prettified transaction, note the callback includes the full prettified transaction,
but currently not printing it for space reasons. but currently not printing it for space reasons.
@ -785,7 +785,8 @@ class SpendTab(QWidget):
mbinfo += ["fee: " + btc.amount_to_str(fee) + ".", mbinfo += ["fee: " + btc.amount_to_str(fee) + ".",
"Accept?"] "Accept?"]
reply = JMQtMessageBox(self, '\n'.join([m + '<p>' for m in mbinfo]), reply = await JMQtMessageBox(
self, '\n'.join([m + '<p>' for m in mbinfo]),
mbtype='question', title="Direct send") mbtype='question', title="Direct send")
if reply == QMessageBox.Yes: if reply == QMessageBox.Yes:
self.direct_send_amount = amount self.direct_send_amount = amount
@ -793,24 +794,24 @@ class SpendTab(QWidget):
else: else:
return False return False
def infoDirectSend(self, msg): async def infoDirectSend(self, msg):
self.clearFields(None) self.clearFields(None)
JMQtMessageBox(self, msg, title="Success") await JMQtMessageBox(self, msg, title="Success")
def errorDirectSend(self, msg): async def errorDirectSend(self, msg):
JMQtMessageBox(self, msg, mbtype="warn", title="Error") await JMQtMessageBox(self, msg, mbtype="warn", title="Error")
async def startSingle(self): async def startSingle(self):
if not self.spendstate.runstate == 'ready': if not self.spendstate.runstate == 'ready':
log.info("Cannot start join, already running.") log.info("Cannot start join, already running.")
if not self.validateSingleSend(): if not await self.validateSingleSend():
return return
destaddr = str(self.addressInput.text().strip()) destaddr = str(self.addressInput.text().strip())
try: try:
amount = btc.amount_to_sat(self.amountInput.text()) amount = btc.amount_to_sat(self.amountInput.text())
except ValueError as e: except ValueError as e:
JMQtMessageBox(self, e.args[0], title="Error", mbtype="warn") await JMQtMessageBox(self, e.args[0], title="Error", mbtype="warn")
return return
makercount = int(self.numCPInput.text()) makercount = int(self.numCPInput.text())
mixdepth = int(self.mixdepthInput.text()) mixdepth = int(self.mixdepthInput.text())
@ -831,7 +832,8 @@ class SpendTab(QWidget):
custom_change_addr=custom_change) custom_change_addr=custom_change)
txid = bintohex(tx.GetTxid()[::-1]) txid = bintohex(tx.GetTxid()[::-1])
except Exception as e: except Exception as e:
JMQtMessageBox(self, e.args[0], title="Error", mbtype="warn") await JMQtMessageBox(
self, e.args[0], title="Error", mbtype="warn")
return return
if not txid: if not txid:
self.giveUp() self.giveUp()
@ -918,13 +920,16 @@ class SpendTab(QWidget):
"max_cj_fee_rel = your-value-as-decimal\n" "max_cj_fee_rel = your-value-as-decimal\n"
"in the [POLICY] section.\n" "in the [POLICY] section.\n"
"Note: If you don't do this, this dialog will interrupt the tumbler.") "Note: If you don't do this, this dialog will interrupt the tumbler.")
JMQtMessageBox(self, msg, mbtype="info", title="Setting fee limits.") asyncio.ensure_future(
JMQtMessageBox(
self, msg, mbtype="info", title="Setting fee limits."))
return relfee, absfee return relfee, absfee
def startJoin(self): def startJoin(self):
if not mainWindow.wallet_service: if not mainWindow.wallet_service:
asyncio.ensure_future(
JMQtMessageBox(self, "Cannot start without a loaded wallet.", JMQtMessageBox(self, "Cannot start without a loaded wallet.",
mbtype="crit", title="Error") mbtype="crit", title="Error"))
return return
log.debug('starting coinjoin ..') log.debug('starting coinjoin ..')
#Decide whether to interrupt processing to sanity check the fees #Decide whether to interrupt processing to sanity check the fees
@ -980,8 +985,8 @@ class SpendTab(QWidget):
else: else:
mainWindow.statusBar().showMessage(infomsg) mainWindow.statusBar().showMessage(infomsg)
elif infotype == "ABORT": elif infotype == "ABORT":
JMQtMessageBox(self, infomsg, asyncio.ensure_future(
mbtype='warn') JMQtMessageBox(self, infomsg, mbtype='warn'))
#Abort signal explicitly means this transaction will not continue. #Abort signal explicitly means this transaction will not continue.
self.abortTransactions() self.abortTransactions()
else: else:
@ -991,7 +996,7 @@ class SpendTab(QWidget):
return tumbler_filter_orders_callback(offers_fees, cjamount, return tumbler_filter_orders_callback(offers_fees, cjamount,
self.taker) self.taker)
def checkOffers(self, offers_fee, cjamount): async def checkOffers(self, offers_fee, cjamount):
"""Parse offers and total fee from client protocol, """Parse offers and total fee from client protocol,
allow the user to agree or decide. allow the user to agree or decide.
""" """
@ -1000,7 +1005,7 @@ class SpendTab(QWidget):
return False return False
if not offers_fee: if not offers_fee:
JMQtMessageBox(self, await JMQtMessageBox(self,
"Not enough matching offers found.", "Not enough matching offers found.",
mbtype='warn', mbtype='warn',
title="Error") title="Error")
@ -1037,10 +1042,9 @@ class SpendTab(QWidget):
if total_fee_pc * 100 > jm_single().config.getint("GUI", if total_fee_pc * 100 > jm_single().config.getint("GUI",
"check_high_fee"): "check_high_fee"):
title += ': WARNING: Fee is HIGH!!' title += ': WARNING: Fee is HIGH!!'
reply = JMQtMessageBox(self, reply = await JMQtMessageBox(self,
'\n'.join([m + '<p>' for m in mbinfo]), '\n'.join([m + '<p>' for m in mbinfo]),
mbtype='question', mbtype='question', title=title)
title=title)
if reply == QMessageBox.Yes: if reply == QMessageBox.Yes:
#amount is now accepted; #amount is now accepted;
#The user is now committed to the transaction #The user is now committed to the transaction
@ -1054,7 +1058,8 @@ class SpendTab(QWidget):
def startNextTransaction(self): def startNextTransaction(self):
self.clientfactory.getClient().clientStart() self.clientfactory.getClient().clientStart()
def takerFinished(self, res, fromtx=False, waittime=0.0, txdetails=None): async def takerFinished(self, res, fromtx=False,
waittime=0.0, txdetails=None):
"""Callback (after pass-through signal) for jmclient.Taker """Callback (after pass-through signal) for jmclient.Taker
on completion of each join transaction. on completion of each join transaction.
""" """
@ -1079,7 +1084,9 @@ class SpendTab(QWidget):
"Transaction seen on network: " + self.taker.txid) "Transaction seen on network: " + self.taker.txid)
if self.spendstate.typestate == 'single': if self.spendstate.typestate == 'single':
self.clearFields(None) self.clearFields(None)
JMQtMessageBox(self, "Transaction broadcast OK. You can safely \n" await JMQtMessageBox(
self,
"Transaction broadcast OK. You can safely \n"
"shut down if you don't want to wait.", "shut down if you don't want to wait.",
title="Success") title="Success")
#TODO: theoretically possible to miss this if confirmed event #TODO: theoretically possible to miss this if confirmed event
@ -1119,7 +1126,7 @@ class SpendTab(QWidget):
str(self.taker.txid) str(self.taker.txid)
else: else:
msg = "All transactions have been confirmed." msg = "All transactions have been confirmed."
JMQtMessageBox(self, msg, title="Success") await JMQtMessageBox(self, msg, title="Success")
self.cleanUp() self.cleanUp()
else: else:
self.giveUp() self.giveUp()
@ -1174,10 +1181,12 @@ class SpendTab(QWidget):
log.debug("Transaction aborted.") log.debug("Transaction aborted.")
mainWindow.statusBar().showMessage("Transaction aborted.") mainWindow.statusBar().showMessage("Transaction aborted.")
if self.taker and len(self.taker.ignored_makers) > 0: if self.taker and len(self.taker.ignored_makers) > 0:
JMQtMessageBox(self, "These Makers did not respond, and will be \n" asyncio.ensure_future(
"ignored in future: \n" + str( JMQtMessageBox(self,
','.join(self.taker.ignored_makers)), "These Makers did not respond, and will be \n"
title="Transaction aborted") "ignored in future: \n" +
str(','.join(self.taker.ignored_makers)),
title="Transaction aborted"))
ignored_makers.extend(self.taker.ignored_makers) ignored_makers.extend(self.taker.ignored_makers)
self.cleanUp() self.cleanUp()
@ -1193,44 +1202,46 @@ class SpendTab(QWidget):
self.tumbler_options = None self.tumbler_options = None
self.tumbler_destaddrs = None self.tumbler_destaddrs = None
def validateSingleSend(self): async def validateSingleSend(self):
if not mainWindow.wallet_service: if not mainWindow.wallet_service:
JMQtMessageBox(self, await JMQtMessageBox(self,
"There is no wallet loaded.", "There is no wallet loaded.",
mbtype='warn', mbtype='warn',
title="Error") title="Error")
return False return False
if jm_single().bc_interface is None: if jm_single().bc_interface is None:
JMQtMessageBox( await JMQtMessageBox(
self, self,
"Sending coins not possible without blockchain source.", "Sending coins not possible without blockchain source.",
mbtype='warn', title="Error") mbtype='warn', title="Error")
return False return False
if len(self.addressInput.text()) == 0: if len(self.addressInput.text()) == 0:
JMQtMessageBox( await JMQtMessageBox(
self, self,
"Recipient address or BIP21 bitcoin: payment URI must be provided.", "Recipient address or BIP21 bitcoin: "
"payment URI must be provided.",
mbtype='warn', title="Error") mbtype='warn', title="Error")
return False return False
valid, errmsg = validate_address( valid, errmsg = validate_address(
str(self.addressInput.text().strip())) str(self.addressInput.text().strip()))
if not valid: if not valid:
JMQtMessageBox(self, errmsg, mbtype='warn', title="Error") await JMQtMessageBox(self, errmsg, mbtype='warn', title="Error")
return False return False
if len(self.numCPInput.text()) == 0: if len(self.numCPInput.text()) == 0:
JMQtMessageBox( await JMQtMessageBox(
self, self,
"Number of counterparties must be provided. Enter '0' to do a direct send instead of a CoinJoin.", "Number of counterparties must be provided. "
"Enter '0' to do a direct send instead of a CoinJoin.",
mbtype='warn', title="Error") mbtype='warn', title="Error")
return False return False
if len(self.mixdepthInput.text()) == 0: if len(self.mixdepthInput.text()) == 0:
JMQtMessageBox( await JMQtMessageBox(
self, self,
"Mixdepth must be chosen.", "Mixdepth must be chosen.",
mbtype='warn', title="Error") mbtype='warn', title="Error")
return False return False
if len(self.amountInput.text()) == 0: if len(self.amountInput.text()) == 0:
JMQtMessageBox( await JMQtMessageBox(
self, self,
"Amount must be provided.", "Amount must be provided.",
mbtype='warn', title="Error") mbtype='warn', title="Error")
@ -1242,11 +1253,12 @@ class SpendTab(QWidget):
try: try:
amount = btc.amount_to_sat(self.amountInput.text()) amount = btc.amount_to_sat(self.amountInput.text())
except ValueError as e: except ValueError as e:
JMQtMessageBox(self, e.args[0], title="Error", mbtype="warn") await JMQtMessageBox(
self, e.args[0], title="Error", mbtype="warn")
return False return False
valid, errmsg = validate_address(change_addr) valid, errmsg = validate_address(change_addr)
if not valid: if not valid:
JMQtMessageBox(self, await JMQtMessageBox(self,
"Custom change address is invalid: \"%s\"" % errmsg, "Custom change address is invalid: \"%s\"" % errmsg,
mbtype='warn', title="Error") mbtype='warn', title="Error")
return False return False
@ -1254,16 +1266,17 @@ class SpendTab(QWidget):
if change_addr == dest_addr: if change_addr == dest_addr:
msg = ''.join(["Custom change address cannot be the ", msg = ''.join(["Custom change address cannot be the ",
"same as the recipient address."]) "same as the recipient address."])
JMQtMessageBox(self, await JMQtMessageBox(self,
msg, msg,
mbtype='warn', title="Error") mbtype='warn', title="Error")
return False return False
if amount == 0: if amount == 0:
JMQtMessageBox(self, sweep_custom_change_warning, await JMQtMessageBox(self, sweep_custom_change_warning,
mbtype='warn', title="Error") mbtype='warn', title="Error")
return False return False
if makercount > 0: if makercount > 0:
reply = JMQtMessageBox(self, general_custom_change_warning, reply = await JMQtMessageBox(
self, general_custom_change_warning,
mbtype='question', title="Warning") mbtype='question', title="Warning")
if reply == QMessageBox.No: if reply == QMessageBox.No:
return False return False
@ -1277,10 +1290,9 @@ class SpendTab(QWidget):
engine_recognized = False engine_recognized = False
wallet_type = mainWindow.wallet_service.get_txtype() wallet_type = mainWindow.wallet_service.get_txtype()
if not engine_recognized or change_addr_type != wallet_type: if not engine_recognized or change_addr_type != wallet_type:
reply = JMQtMessageBox(self, reply = await JMQtMessageBox(
nonwallet_custom_change_warning, self, nonwallet_custom_change_warning,
mbtype='question', mbtype='question', title="Warning")
title="Warning")
if reply == QMessageBox.No: if reply == QMessageBox.No:
return False return False

Loading…
Cancel
Save