Browse Source

replace wallet.all_addresses() with wallet.addresses(True)

283
thomasv 12 years ago
parent
commit
97e03cb738
  1. 6
      lib/commands.py
  2. 2
      lib/gui.py
  3. 2
      lib/gui_lite.py
  4. 4
      lib/gui_qt.py
  5. 2
      lib/receiving_widget.py
  6. 29
      lib/wallet.py

6
lib/commands.py

@ -148,7 +148,7 @@ class Commands:
def dumpprivkeys(self, addresses = None): def dumpprivkeys(self, addresses = None):
if addresses is None: if addresses is None:
addresses = self.wallet.all_addresses() addresses = self.wallet.addresses(True)
return self.wallet.get_private_keys(addresses, self.password) return self.wallet.get_private_keys(addresses, self.password)
def validateaddress(self,addr): def validateaddress(self,addr):
@ -220,7 +220,7 @@ class Commands:
if not is_valid(from_addr): if not is_valid(from_addr):
raise BaseException("invalid Bitcoin address", from_addr) raise BaseException("invalid Bitcoin address", from_addr)
if from_addr not in self.wallet.all_addresses(): if not self.wallet.is_mine(from_addr):
raise BaseException("address not in wallet") raise BaseException("address not in wallet")
for k, v in self.wallet.labels.items(): for k, v in self.wallet.labels.items():
@ -281,7 +281,7 @@ class Commands:
def listaddresses(self, show_all = False, show_balance = False, show_label = False): def listaddresses(self, show_all = False, show_balance = False, show_label = False):
out = [] out = []
for addr in self.wallet.all_addresses(): for addr in self.wallet.addresses(True):
if show_all or not self.wallet.is_change(addr): if show_all or not self.wallet.is_change(addr):
if show_balance or show_label: if show_balance or show_label:
item = { 'address': addr } item = { 'address': addr }

2
lib/gui.py

@ -1134,7 +1134,7 @@ class ElectrumWindow:
def update_receiving_tab(self): def update_receiving_tab(self):
self.recv_list.clear() self.recv_list.clear()
for address in self.wallet.all_addresses(): for address in self.wallet.addresses(True):
if self.wallet.is_change(address):continue if self.wallet.is_change(address):continue
label = self.wallet.labels.get(address) label = self.wallet.labels.get(address)
h = self.wallet.history.get(address,[]) h = self.wallet.history.get(address,[])

2
lib/gui_lite.py

@ -795,7 +795,7 @@ class MiniActuator:
def copy_address(self, receive_popup): def copy_address(self, receive_popup):
"""Copy the wallet addresses into the client.""" """Copy the wallet addresses into the client."""
addrs = [addr for addr in self.wallet.all_addresses() addrs = [addr for addr in self.wallet.addresses(True)
if not self.wallet.is_change(addr)] if not self.wallet.is_change(addr)]
# Select most recent addresses from gap limit # Select most recent addresses from gap limit
addrs = addrs[-self.wallet.gap_limit:] addrs = addrs[-self.wallet.gap_limit:]

4
lib/gui_qt.py

@ -1987,7 +1987,7 @@ class ElectrumWindow(QMainWindow):
transaction.writerow(["address", "private_key"]) transaction.writerow(["address", "private_key"])
for addr, pk in self.wallet.get_private_keys(self.wallet.all_addresses(), password).items(): for addr, pk in self.wallet.get_private_keys(self.wallet.addresses(True), password).items():
transaction.writerow(["%34s"%addr,pk]) transaction.writerow(["%34s"%addr,pk])
self.show_message(_("Private keys exported.")) self.show_message(_("Private keys exported."))
@ -2510,7 +2510,7 @@ class ElectrumGui:
waiting_dialog(waiting) waiting_dialog(waiting)
waiting = lambda: False if wallet.is_up_to_date() else "%s\n%s %d\n%s %.1f"\ waiting = lambda: False if wallet.is_up_to_date() else "%s\n%s %d\n%s %.1f"\
%(_("Please wait..."),_("Addresses generated:"),len(wallet.all_addresses()),_("Kilobytes received:"), wallet.interface.bytes_received/1024.) %(_("Please wait..."),_("Addresses generated:"),len(wallet.addresses(True)),_("Kilobytes received:"), wallet.interface.bytes_received/1024.)
wallet.set_up_to_date(False) wallet.set_up_to_date(False)
wallet.interface.poke('synchronizer') wallet.interface.poke('synchronizer')

2
lib/receiving_widget.py

@ -36,7 +36,7 @@ class ReceivingWidget(QTreeWidget):
def update_list(self): def update_list(self):
self.clear() self.clear()
addresses = [addr for addr in self.owner.actuator.wallet.all_addresses() if not self.owner.actuator.wallet.is_change(addr)] addresses = self.owner.actuator.wallet.addresses()
for address in addresses: for address in addresses:
history = self.owner.actuator.wallet.history.get(address,[]) history = self.owner.actuator.wallet.history.get(address,[])

29
lib/wallet.py

@ -150,7 +150,7 @@ class Wallet:
seed = self.decode_seed(password) seed = self.decode_seed(password)
address = address_from_private_key(sec) address = address_from_private_key(sec)
if address in self.all_addresses(): if self.is_mine(address):
raise BaseException('Address already in wallet') raise BaseException('Address already in wallet')
# store the originally requested keypair into the imported keys table # store the originally requested keypair into the imported keys table
@ -178,16 +178,16 @@ class Wallet:
def all_addresses(self): def addresses(self, include_change = False):
o = self.imported_keys.keys() o = self.imported_keys.keys()
for a in self.accounts.values(): for a in self.accounts.values():
o += a[0] o += a[0]
o += a[1] if include_change: o += a[1]
return o return o
def is_mine(self, address): def is_mine(self, address):
return address in self.all_addresses() return address in self.addresses(True)
def is_change(self, address): def is_change(self, address):
#return address in self.change_addresses #return address in self.change_addresses
@ -419,7 +419,7 @@ class Wallet:
def get_tx_value(self, tx, addresses=None): def get_tx_value(self, tx, addresses=None):
if addresses is None: addresses = self.all_addresses() if addresses is None: addresses = self.addresses(True)
return tx.get_value(addresses, self.prevout_values) return tx.get_value(addresses, self.prevout_values)
@ -549,7 +549,7 @@ class Wallet:
def get_unspent_coins(self, domain=None): def get_unspent_coins(self, domain=None):
coins = [] coins = []
if domain is None: domain = self.all_addresses() if domain is None: domain = self.addresses(True)
for addr in domain: for addr in domain:
h = self.history.get(addr, []) h = self.history.get(addr, [])
if h == ['*']: continue if h == ['*']: continue
@ -572,7 +572,7 @@ class Wallet:
coins = [] coins = []
prioritized_coins = [] prioritized_coins = []
domain = [from_addr] if from_addr else self.all_addresses() domain = [from_addr] if from_addr else self.addresses(True)
for i in self.frozen_addresses: for i in self.frozen_addresses:
if i in domain: domain.remove(i) if i in domain: domain.remove(i)
@ -603,7 +603,8 @@ class Wallet:
if change_amount != 0: if change_amount != 0:
# normally, the update thread should ensure that the last change address is unused # normally, the update thread should ensure that the last change address is unused
if not change_addr: if not change_addr:
change_addr = self.change_addresses[-self.gap_limit_for_change] change_addresses = self.accounts[0][1]
change_addr = change_addresses[-self.gap_limit_for_change]
# Insert the change output at a random position in the outputs # Insert the change output at a random position in the outputs
posn = random.randint(0, len(outputs)) posn = random.randint(0, len(outputs))
outputs[posn:posn] = [( change_addr, change_amount)] outputs[posn:posn] = [( change_addr, change_amount)]
@ -911,7 +912,7 @@ class Wallet:
if label and self.labels.get(address) != label: if label and self.labels.get(address) != label:
if question('Give label "%s" to address %s ?'%(label,address)): if question('Give label "%s" to address %s ?'%(label,address)):
if address not in self.addressbook and address not in self.all_addresses(): if address not in self.addressbook and not self.is_mine(address):
self.addressbook.append(address) self.addressbook.append(address)
self.labels[address] = label self.labels[address] = label
@ -941,7 +942,7 @@ class Wallet:
def freeze(self,addr): def freeze(self,addr):
if addr in self.all_addresses() and addr not in self.frozen_addresses: if self.is_mine(addr) and addr not in self.frozen_addresses:
self.unprioritize(addr) self.unprioritize(addr)
self.frozen_addresses.append(addr) self.frozen_addresses.append(addr)
self.config.set_key('frozen_addresses', self.frozen_addresses, True) self.config.set_key('frozen_addresses', self.frozen_addresses, True)
@ -950,7 +951,7 @@ class Wallet:
return False return False
def unfreeze(self,addr): def unfreeze(self,addr):
if addr in self.all_addresses() and addr in self.frozen_addresses: if self.is_mine(addr) and addr in self.frozen_addresses:
self.frozen_addresses.remove(addr) self.frozen_addresses.remove(addr)
self.config.set_key('frozen_addresses', self.frozen_addresses, True) self.config.set_key('frozen_addresses', self.frozen_addresses, True)
return True return True
@ -958,7 +959,7 @@ class Wallet:
return False return False
def prioritize(self,addr): def prioritize(self,addr):
if addr in self.all_addresses() and addr not in self.prioritized_addresses: if is_mine(addr) and addr not in self.prioritized_addresses:
self.unfreeze(addr) self.unfreeze(addr)
self.prioritized_addresses.append(addr) self.prioritized_addresses.append(addr)
self.config.set_key('prioritized_addresses', self.prioritized_addresses, True) self.config.set_key('prioritized_addresses', self.prioritized_addresses, True)
@ -967,7 +968,7 @@ class Wallet:
return False return False
def unprioritize(self,addr): def unprioritize(self,addr):
if addr in self.all_addresses() and addr in self.prioritized_addresses: if is_mine(addr) and addr in self.prioritized_addresses:
self.prioritized_addresses.remove(addr) self.prioritized_addresses.remove(addr)
self.config.set_key('prioritized_addresses', self.prioritized_addresses, True) self.config.set_key('prioritized_addresses', self.prioritized_addresses, True)
return True return True
@ -1185,7 +1186,7 @@ class WalletSynchronizer(threading.Thread):
self.interface.send([('server.banner',[])],'synchronizer') self.interface.send([('server.banner',[])],'synchronizer')
# subscriptions # subscriptions
self.subscribe_to_addresses(self.wallet.all_addresses()) self.subscribe_to_addresses(self.wallet.addresses(True))
while self.is_running(): while self.is_running():
# 1. send new requests # 1. send new requests

Loading…
Cancel
Save