Browse Source

txbump: remove superfluous output choice prompt with one-output bumps

The MMGen Project 5 years ago
parent
commit
d5da1e7ada
2 changed files with 24 additions and 10 deletions
  1. 20 7
      mmgen/tx.py
  2. 4 3
      test/test_py_d/ts_regtest.py

+ 20 - 7
mmgen/tx.py

@@ -1521,6 +1521,21 @@ class MMGenBumpTX(MMGenTX):
 	def choose_output(self):
 		chg_idx = self.get_chg_output_idx()
 		init_reply = opt.output_to_reduce
+
+		def check_sufficient_funds(o_amt):
+			if o_amt < self.min_fee:
+				msg('Minimum fee ({} {c}) is greater than output amount ({} {c})'.format(
+					self.min_fee,o_amt,c=g.coin))
+				return False
+			return True
+
+		if len(self.outputs) == 1:
+			if check_sufficient_funds(self.outputs[0].amt):
+				self.bump_output_idx = 0
+				return 0
+			else:
+				die(1,'Insufficient funds to bump transaction')
+
 		while True:
 			if init_reply == None:
 				m = 'Choose an output to deduct the fee from (Hit ENTER for the change output): '
@@ -1539,13 +1554,11 @@ class MMGenBumpTX(MMGenTX):
 					o_amt = self.outputs[idx].amt
 					cs = ('',' (change output)')[chg_idx == idx]
 					p = 'Fee will be deducted from output {}{} ({} {})'.format(idx+1,cs,o_amt,g.coin)
-					if o_amt < self.min_fee:
-						msg('Minimum fee ({} {c}) is greater than output amount ({} {c})'.format(
-							self.min_fee,o_amt,c=g.coin))
-					elif opt.yes or keypress_confirm(p+'.  OK?',default_yes=True):
-						if opt.yes: msg(p)
-						self.bump_output_idx = idx
-						return idx
+					if check_sufficient_funds(o_amt):
+						if opt.yes or keypress_confirm(p+'.  OK?',default_yes=True):
+							if opt.yes: msg(p)
+							self.bump_output_idx = idx
+							return idx
 
 	def set_min_fee(self):
 		self.min_fee = self.sum_inputs() - self.sum_outputs() + self.get_relay_fee()

+ 4 - 3
test/test_py_d/ts_regtest.py

@@ -569,7 +569,7 @@ class TestSuiteRegtest(TestSuiteBase,TestSuiteShared):
 		if g.coin != 'BTC': return 'skip'
 		ext = '9343,3]{x}.testnet.rawtx'.format(x='-α' if g.debug_utf8 else '')
 		txfile = get_file_with_ext(self.tr.trash_dir,ext,delete=False,no_dot=True)
-		return self.user_txbump('bob',self.tr.trash_dir,txfile,'8s',has_label=False,signed_tx=False)
+		return self.user_txbump('bob',self.tr.trash_dir,txfile,'8s',has_label=False,signed_tx=False,one_output=True)
 
 	def bob_send_maybe_rbf(self):
 		outputs_cl = self._create_tx_outputs('alice',(('L',1,',60'),('C',1,',40'))) # alice_sid:L:1, alice_sid:C:1
@@ -590,13 +590,14 @@ class TestSuiteRegtest(TestSuiteBase,TestSuiteShared):
 		outputs_cl = self._create_tx_outputs('bob',(('L',1,''),)) # bob_sid:L:1
 		return self.user_txdo('alice',None,outputs_cl,'1') # fee=None
 
-	def user_txbump(self,user,outdir,txfile,fee,add_args=[],has_label=True,signed_tx=True):
+	def user_txbump(self,user,outdir,txfile,fee,add_args=[],has_label=True,signed_tx=True,one_output=False):
 		if not g.proto.cap('rbf'): return 'skip'
 		os.environ['MMGEN_BOGUS_SEND'] = ''
 		t = self.spawn('mmgen-txbump',
 			['-d',outdir,'--'+user,'--tx-fee='+fee,'--output-to-reduce=c'] + add_args + [txfile])
 		os.environ['MMGEN_BOGUS_SEND'] = '1'
-		t.expect('OK? (Y/n): ','y') # output OK?
+		if not one_output:
+			t.expect('OK? (Y/n): ','y') # output OK?
 		t.expect('OK? (Y/n): ','y') # fee OK?
 		t.do_comment(False,has_label=has_label)
 		if signed_tx: