diff --git a/scripts/joinmarket-qt.py b/scripts/joinmarket-qt.py index c76c622..9ac0239 100644 --- a/scripts/joinmarket-qt.py +++ b/scripts/joinmarket-qt.py @@ -66,6 +66,7 @@ JM_CORE_VERSION = '0.6.1' JM_GUI_VERSION = '11' from jmbase import get_log +from jmbase.support import DUST_THRESHOLD from jmclient import load_program_config, get_network, update_persist_config,\ open_test_wallet_maybe, get_wallet_path, get_p2sh_vbyte, get_p2pk_vbyte,\ jm_single, validate_address, weighted_order_choose, Taker,\ @@ -109,6 +110,22 @@ def checkAddress(parent, addr): mbtype='warn', title="Error") + +def checkAmount(parent, amount_str): + if not amount_str: + return False + amount_sat = btc.amount_to_sat(amount_str) + if amount_sat < DUST_THRESHOLD: + JMQtMessageBox(parent, + "Amount " + btc.amount_to_str(amount_sat) + + " is below dust threshold " + + btc.amount_to_str(DUST_THRESHOLD) + ".", + mbtype='warn', + title="Error") + return False + return True + + def getSettingsWidgets(): results = [] sN = ['Recipient address', 'Number of counterparties', 'Mixdepth', @@ -609,11 +626,14 @@ class SpendTab(QWidget): if not self.validateSettings(): return destaddr = str(self.widgets[0][1].text()) - #convert from bitcoins (enforced by QDoubleValidator) to satoshis - btc_amount_str = self.widgets[3][1].text() - amount = btc.amount_to_sat(btc_amount_str) makercount = int(self.widgets[1][1].text()) mixdepth = int(self.widgets[2][1].text()) + btc_amount_str = self.widgets[3][1].text() + # for coinjoin sends no point to send below dust threshold, likely + # there will be no makers for such amount. + if makercount != 0 and not checkAmount(self, btc_amount_str): + return + amount = btc.amount_to_sat(btc_amount_str) if makercount == 0: try: txid = direct_send(mainWindow.wallet_service, amount, mixdepth, diff --git a/scripts/sendpayment.py b/scripts/sendpayment.py index 7d7590e..823b1bb 100644 --- a/scripts/sendpayment.py +++ b/scripts/sendpayment.py @@ -18,7 +18,7 @@ from jmclient import Taker, P2EPTaker, load_program_config, get_schedule,\ get_sendpayment_parser, get_max_cj_fee_values, check_regtest from twisted.python.log import startLogging from jmbase.support import get_log, set_logging_level, jmprint, \ - EXIT_FAILURE, EXIT_ARGERROR + EXIT_FAILURE, EXIT_ARGERROR, DUST_THRESHOLD import jmbitcoin as btc @@ -72,6 +72,11 @@ def main(): if not addr_valid: jmprint('ERROR: Address invalid. ' + errormsg, "error") sys.exit(EXIT_ARGERROR) + if amount < DUST_THRESHOLD: + jmprint('ERROR: Amount ' + btc.amount_to_str(amount) + + ' is below dust threshold ' + + btc.amount_to_str(DUST_THRESHOLD) + '.', "error") + sys.exit(EXIT_ARGERROR) schedule = [[options.mixdepth, amount, options.makercount, destaddr, 0.0, NO_ROUNDING, 0]] else: