mirror of
https://github.com/LBRYFoundation/LBRY-Vault.git
synced 2025-08-30 17:01:34 +00:00
get_spendable_coins and frozen addrs
Two callers of get_spendable_coins were removing frozen addrs before calling. Put that functionality in the function. We shouldn't be able to send_from a frozen address. This was possible in the current release because logic assumed a two-element tuple was returned when it is now three-element. Fix that too. Command line options listunspent and createrawtransaction currently ignore frozen addresses. I'm not sure that's right but I've preserved that behaviour. With this patch only the wallet class refers to self.frozen_addresses; other clients use is_frozen() now.
This commit is contained in:
parent
0f29984f07
commit
320f9a3790
3 changed files with 10 additions and 15 deletions
|
@ -1410,13 +1410,13 @@ class ElectrumWindow(QMainWindow):
|
||||||
if addr_URL:
|
if addr_URL:
|
||||||
menu.addAction(_("View on block explorer"), lambda: webbrowser.open(addr_URL))
|
menu.addAction(_("View on block explorer"), lambda: webbrowser.open(addr_URL))
|
||||||
|
|
||||||
if any(addr not in self.wallet.frozen_addresses for addr in addrs):
|
if any(not self.wallet.is_frozen(addr) for addr in addrs):
|
||||||
menu.addAction(_("Freeze"), lambda: self.set_frozen_state(addrs, True))
|
menu.addAction(_("Freeze"), lambda: self.set_frozen_state(addrs, True))
|
||||||
if any(addr in self.wallet.frozen_addresses for addr in addrs):
|
if any(self.wallet.is_frozen(addr) for addr in addrs):
|
||||||
menu.addAction(_("Unfreeze"), lambda: self.set_frozen_state(addrs, False))
|
menu.addAction(_("Unfreeze"), lambda: self.set_frozen_state(addrs, False))
|
||||||
|
|
||||||
def can_send(addr):
|
def can_send(addr):
|
||||||
return addr not in self.wallet.frozen_addresses and self.wallet.get_addr_balance(addr) != (0, 0)
|
return not self.wallet.is_frozen(addr) and sum(self.wallet.get_addr_balance(addr)[:2])
|
||||||
if any(can_send(addr) for addr in addrs):
|
if any(can_send(addr) for addr in addrs):
|
||||||
menu.addAction(_("Send From"), lambda: self.send_from_addresses(addrs))
|
menu.addAction(_("Send From"), lambda: self.send_from_addresses(addrs))
|
||||||
|
|
||||||
|
@ -1433,13 +1433,11 @@ class ElectrumWindow(QMainWindow):
|
||||||
return self.pay_from
|
return self.pay_from
|
||||||
else:
|
else:
|
||||||
domain = self.wallet.get_account_addresses(self.current_account)
|
domain = self.wallet.get_account_addresses(self.current_account)
|
||||||
for i in self.wallet.frozen_addresses:
|
|
||||||
if i in domain: domain.remove(i)
|
|
||||||
return self.wallet.get_spendable_coins(domain)
|
return self.wallet.get_spendable_coins(domain)
|
||||||
|
|
||||||
|
|
||||||
def send_from_addresses(self, addrs):
|
def send_from_addresses(self, addrs):
|
||||||
self.set_pay_from( addrs )
|
self.set_pay_from(addrs)
|
||||||
self.tabs.setCurrentIndex(1)
|
self.tabs.setCurrentIndex(1)
|
||||||
self.update_fee(False)
|
self.update_fee(False)
|
||||||
|
|
||||||
|
@ -1581,7 +1579,7 @@ class ElectrumWindow(QMainWindow):
|
||||||
item.setFont(0, QFont(MONOSPACE_FONT))
|
item.setFont(0, QFont(MONOSPACE_FONT))
|
||||||
item.setData(0, Qt.UserRole, address)
|
item.setData(0, Qt.UserRole, address)
|
||||||
item.setData(0, Qt.UserRole+1, True) # label can be edited
|
item.setData(0, Qt.UserRole+1, True) # label can be edited
|
||||||
if address in self.wallet.frozen_addresses:
|
if self.wallet.is_frozen(address):
|
||||||
item.setBackgroundColor(0, QColor('lightblue'))
|
item.setBackgroundColor(0, QColor('lightblue'))
|
||||||
if self.wallet.is_beyond_limit(address, account, is_change):
|
if self.wallet.is_beyond_limit(address, account, is_change):
|
||||||
item.setBackgroundColor(0, QColor('red'))
|
item.setBackgroundColor(0, QColor('red'))
|
||||||
|
|
|
@ -265,7 +265,7 @@ class Commands:
|
||||||
return self.network.synchronous_get([ ('blockchain.address.get_history',[addr]) ])[0]
|
return self.network.synchronous_get([ ('blockchain.address.get_history',[addr]) ])[0]
|
||||||
|
|
||||||
def listunspent(self):
|
def listunspent(self):
|
||||||
l = copy.deepcopy(self.wallet.get_spendable_coins())
|
l = copy.deepcopy(self.wallet.get_spendable_coins(exclude_frozen = False))
|
||||||
for i in l: i["value"] = str(Decimal(i["value"])/100000000)
|
for i in l: i["value"] = str(Decimal(i["value"])/100000000)
|
||||||
return l
|
return l
|
||||||
|
|
||||||
|
@ -278,7 +278,7 @@ class Commands:
|
||||||
return {'address':r[0] }
|
return {'address':r[0] }
|
||||||
|
|
||||||
def createrawtransaction(self, inputs, outputs):
|
def createrawtransaction(self, inputs, outputs):
|
||||||
coins = self.wallet.get_spendable_coins(None)
|
coins = self.wallet.get_spendable_coins(exclude_frozen = False)
|
||||||
tx_inputs = []
|
tx_inputs = []
|
||||||
for i in inputs:
|
for i in inputs:
|
||||||
prevout_hash = i['txid']
|
prevout_hash = i['txid']
|
||||||
|
|
|
@ -562,10 +562,12 @@ class Abstract_Wallet(object):
|
||||||
return c, u, x
|
return c, u, x
|
||||||
|
|
||||||
|
|
||||||
def get_spendable_coins(self, domain=None):
|
def get_spendable_coins(self, domain = None, exclude_frozen = True):
|
||||||
coins = []
|
coins = []
|
||||||
if domain is None:
|
if domain is None:
|
||||||
domain = self.addresses(True)
|
domain = self.addresses(True)
|
||||||
|
if exclude_frozen:
|
||||||
|
domain = set(domain) - self.frozen_addresses
|
||||||
for addr in domain:
|
for addr in domain:
|
||||||
c = self.get_addr_utxo(addr)
|
c = self.get_addr_utxo(addr)
|
||||||
for txo, v in c.items():
|
for txo, v in c.items():
|
||||||
|
@ -846,11 +848,6 @@ class Abstract_Wallet(object):
|
||||||
|
|
||||||
# get coins
|
# get coins
|
||||||
if not coins:
|
if not coins:
|
||||||
if domain is None:
|
|
||||||
domain = self.addresses(True)
|
|
||||||
for i in self.frozen_addresses:
|
|
||||||
if i in domain:
|
|
||||||
domain.remove(i)
|
|
||||||
coins = self.get_spendable_coins(domain)
|
coins = self.get_spendable_coins(domain)
|
||||||
|
|
||||||
amount = sum(map(lambda x:x[2], outputs))
|
amount = sum(map(lambda x:x[2], outputs))
|
||||||
|
|
Loading…
Add table
Reference in a new issue