Option to send only confirmed coins (fix #2395)
This commit is contained in:
parent
255458da0a
commit
faa17f9818
|
@ -578,7 +578,7 @@ class ElectrumWindow(App):
|
||||||
self.status = '[size=15dp]%s[/size]\n%s' %(n, status)
|
self.status = '[size=15dp]%s[/size]\n%s' %(n, status)
|
||||||
|
|
||||||
def get_max_amount(self):
|
def get_max_amount(self):
|
||||||
inputs = self.wallet.get_spendable_coins(None)
|
inputs = self.wallet.get_spendable_coins(None, self.electrum_config)
|
||||||
addr = str(self.send_screen.screen.address) or self.wallet.dummy_address()
|
addr = str(self.send_screen.screen.address) or self.wallet.dummy_address()
|
||||||
outputs = [(TYPE_ADDRESS, addr, '!')]
|
outputs = [(TYPE_ADDRESS, addr, '!')]
|
||||||
tx = self.wallet.make_unsigned_transaction(inputs, outputs, self.electrum_config)
|
tx = self.wallet.make_unsigned_transaction(inputs, outputs, self.electrum_config)
|
||||||
|
|
|
@ -1165,8 +1165,12 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, PrintError):
|
||||||
self.not_enough_funds = False
|
self.not_enough_funds = False
|
||||||
except NotEnoughFunds:
|
except NotEnoughFunds:
|
||||||
self.not_enough_funds = True
|
self.not_enough_funds = True
|
||||||
|
if not freeze_fee:
|
||||||
|
self.fee_e.setAmount(None)
|
||||||
|
return
|
||||||
except BaseException:
|
except BaseException:
|
||||||
return
|
return
|
||||||
|
|
||||||
if not freeze_fee:
|
if not freeze_fee:
|
||||||
fee = None if self.not_enough_funds else tx.get_fee()
|
fee = None if self.not_enough_funds else tx.get_fee()
|
||||||
self.fee_e.setAmount(fee)
|
self.fee_e.setAmount(fee)
|
||||||
|
@ -1572,8 +1576,7 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, PrintError):
|
||||||
if self.pay_from:
|
if self.pay_from:
|
||||||
return self.pay_from
|
return self.pay_from
|
||||||
else:
|
else:
|
||||||
domain = self.wallet.get_addresses()
|
return self.wallet.get_spendable_coins(None, self.config)
|
||||||
return self.wallet.get_spendable_coins(domain)
|
|
||||||
|
|
||||||
def spend_coins(self, coins):
|
def spend_coins(self, coins):
|
||||||
self.set_pay_from(coins)
|
self.set_pay_from(coins)
|
||||||
|
@ -2625,6 +2628,15 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, PrintError):
|
||||||
chooser_combo.currentIndexChanged.connect(on_chooser)
|
chooser_combo.currentIndexChanged.connect(on_chooser)
|
||||||
tx_widgets.append((chooser_label, chooser_combo))
|
tx_widgets.append((chooser_label, chooser_combo))
|
||||||
|
|
||||||
|
def on_unconf(x):
|
||||||
|
self.config.set_key('confirmed_only', bool(x))
|
||||||
|
conf_only = self.config.get('confirmed_only', True)
|
||||||
|
unconf_cb = QCheckBox(_('Spend only confirmed coins'))
|
||||||
|
unconf_cb.setToolTip(_('Spend only confirmed inputs.'))
|
||||||
|
unconf_cb.setChecked(conf_only)
|
||||||
|
unconf_cb.stateChanged.connect(on_unconf)
|
||||||
|
tx_widgets.append((unconf_cb, None))
|
||||||
|
|
||||||
# Fiat Currency
|
# Fiat Currency
|
||||||
hist_checkbox = QCheckBox()
|
hist_checkbox = QCheckBox()
|
||||||
ccy_combo = QComboBox()
|
ccy_combo = QComboBox()
|
||||||
|
|
|
@ -411,7 +411,7 @@ class Commands:
|
||||||
amount = satoshis(amount)
|
amount = satoshis(amount)
|
||||||
final_outputs.append((TYPE_ADDRESS, address, amount))
|
final_outputs.append((TYPE_ADDRESS, address, amount))
|
||||||
|
|
||||||
coins = self.wallet.get_spendable_coins(domain)
|
coins = self.wallet.get_spendable_coins(domain, self.config)
|
||||||
tx = self.wallet.make_unsigned_transaction(coins, final_outputs, self.config, fee, change_addr)
|
tx = self.wallet.make_unsigned_transaction(coins, final_outputs, self.config, fee, change_addr)
|
||||||
if rbf:
|
if rbf:
|
||||||
tx.set_rbf(True)
|
tx.set_rbf(True)
|
||||||
|
|
|
@ -528,10 +528,11 @@ class Abstract_Wallet(PrintError):
|
||||||
u -= v
|
u -= v
|
||||||
return c, u, x
|
return c, u, x
|
||||||
|
|
||||||
def get_spendable_coins(self, domain = None):
|
def get_spendable_coins(self, domain, config):
|
||||||
return self.get_utxos(domain, exclude_frozen=True, mature=True)
|
confirmed_only = config.get('confirmed_only', True)
|
||||||
|
return self.get_utxos(domain, exclude_frozen=True, mature=True, confirmed_only=confirmed_only)
|
||||||
|
|
||||||
def get_utxos(self, domain = None, exclude_frozen = False, mature = False):
|
def get_utxos(self, domain = None, exclude_frozen = False, mature = False, confirmed_only = False):
|
||||||
coins = []
|
coins = []
|
||||||
if domain is None:
|
if domain is None:
|
||||||
domain = self.get_addresses()
|
domain = self.get_addresses()
|
||||||
|
@ -540,6 +541,8 @@ class Abstract_Wallet(PrintError):
|
||||||
for addr in domain:
|
for addr in domain:
|
||||||
utxos = self.get_addr_utxo(addr)
|
utxos = self.get_addr_utxo(addr)
|
||||||
for x in utxos:
|
for x in utxos:
|
||||||
|
if confirmed_only and x['height'] <= 0:
|
||||||
|
continue
|
||||||
if mature and x['coinbase'] and x['height'] + COINBASE_MATURITY > self.get_local_height():
|
if mature and x['coinbase'] and x['height'] + COINBASE_MATURITY > self.get_local_height():
|
||||||
continue
|
continue
|
||||||
coins.append(x)
|
coins.append(x)
|
||||||
|
@ -863,7 +866,7 @@ class Abstract_Wallet(PrintError):
|
||||||
return fee
|
return fee
|
||||||
|
|
||||||
def mktx(self, outputs, password, config, fee=None, change_addr=None, domain=None):
|
def mktx(self, outputs, password, config, fee=None, change_addr=None, domain=None):
|
||||||
coins = self.get_spendable_coins(domain)
|
coins = self.get_spendable_coins(domain, config)
|
||||||
tx = self.make_unsigned_transaction(coins, outputs, config, fee, change_addr)
|
tx = self.make_unsigned_transaction(coins, outputs, config, fee, change_addr)
|
||||||
self.sign_transaction(tx, password)
|
self.sign_transaction(tx, password)
|
||||||
return tx
|
return tx
|
||||||
|
@ -1068,7 +1071,7 @@ class Abstract_Wallet(PrintError):
|
||||||
txin['type'] = self.txin_type
|
txin['type'] = self.txin_type
|
||||||
# Add address for utxo that are in wallet
|
# Add address for utxo that are in wallet
|
||||||
if txin.get('scriptSig') == '':
|
if txin.get('scriptSig') == '':
|
||||||
coins = self.get_spendable_coins()
|
coins = self.get_utxos()
|
||||||
for item in coins:
|
for item in coins:
|
||||||
if txin.get('prevout_hash') == item.get('prevout_hash') and txin.get('prevout_n') == item.get('prevout_n'):
|
if txin.get('prevout_hash') == item.get('prevout_hash') and txin.get('prevout_n') == item.get('prevout_n'):
|
||||||
txin['address'] = item.get('address')
|
txin['address'] = item.get('address')
|
||||||
|
|
Loading…
Reference in New Issue