commit 6b0499bcbcfb1bb57d0b6b154e8abb03b8d2f967
parent dabee035482681dc0a66566fa1ccd6d799455ca3
Author: thomasv <thomasv@gitorious>
Date: Thu, 7 Jun 2012 18:52:29 +0200
allow user to change gap limit
Diffstat:
2 files changed, 76 insertions(+), 8 deletions(-)
diff --git a/lib/gui_qt.py b/lib/gui_qt.py
@@ -549,17 +549,11 @@ class ElectrumWindow(QMainWindow):
self.update_receive_tab()
- def create_new_address(self):
- if self.question( _("Warning:\nThis will create an address beyond your current gap limit.") + "\n" + _("Are you sure?")):
- self.wallet.create_new_address(False)
- self.update_receive_tab()
-
def add_receive_buttons(self):
-
l = self.receive_list
hbox = self.receive_buttons_hbox
- self.new_address_button = EnterButton(_("New"), self.create_new_address)
+ self.new_address_button = EnterButton(_("New"), self.change_gap_limit_dialog)
hbox.addWidget(self.new_address_button)
self.new_address_button.setHidden(not self.wallet.expert_mode)
@@ -632,7 +626,7 @@ class ElectrumWindow(QMainWindow):
self.receive_buttons_hbox = hbox
#self.add_receive_buttons()
- self.new_address_button = EnterButton(_("New"), self.create_new_address)
+ self.new_address_button = EnterButton(_("New"), self.change_gap_limit_dialog)
self.new_address_button.setHidden(not self.wallet.expert_mode)
hbox.addWidget(self.new_address_button)
hbox.addStretch(1)
@@ -974,6 +968,42 @@ class ElectrumWindow(QMainWindow):
if not d.exec_(): return
return unicode(pw.text())
+
+ def change_gap_limit_dialog(self):
+ d = QDialog(self)
+ d.setModal(1)
+
+ vbox = QVBoxLayout()
+
+ msg = _('In order to create more addresses, you need to raise your gap limit.') + '\n' \
+ + _('Your current gap limit is ') + '%d'%self.wallet.gap_limit + '\n' \
+ + _('The minimum for this wallet is: ') + '%d'%self.wallet.min_acceptable_gap() + '\n'
+
+ vbox.addWidget(QLabel(msg))
+
+ grid = QGridLayout()
+ grid.setSpacing(8)
+ grid.addWidget(QLabel(_('New gap limit: ')), 1, 0)
+
+ e = QLineEdit()
+ grid.addWidget(e, 1, 1)
+ vbox.addLayout(grid)
+
+ vbox.addLayout(ok_cancel_buttons(d))
+ d.setLayout(vbox)
+
+ if not d.exec_(): return
+ try:
+ n = int(e.text())
+ except:
+ return
+
+ self.wallet.change_gap_limit(n)
+ self.update_receive_tab()
+
+
+
+
@staticmethod
def change_password_dialog( wallet, parent=None ):
diff --git a/lib/wallet.py b/lib/wallet.py
@@ -494,6 +494,42 @@ class Wallet:
return address
+ def change_gap_limit(self, value):
+ if value >= self.gap_limit:
+ self.gap_limit = value
+ self.save()
+ return True
+
+ elif value >= self.min_acceptable_gap():
+ k = self.num_unused_trailing_addresses()
+ n = len(self.addresses) - k + value
+ self.addresses = self.addresses[0:n]
+ self.gap_limit = value
+ self.save()
+ return True
+ else:
+ return False
+
+ def num_unused_trailing_addresses(self):
+ k = 0
+ for a in self.addresses[::-1]:
+ if self.history.get(a):break
+ k = k + 1
+ return k
+
+ def min_acceptable_gap(self):
+ # fixme: this assumes wallet is synchronized
+ n = 0
+ nmax = 0
+ k = self.num_unused_trailing_addresses()
+ for a in self.addresses[0:-k]:
+ if self.history.get(a):
+ n = 0
+ else:
+ n += 1
+ if n > nmax: nmax = n
+ return nmax
+
def synchronize(self):
if not self.master_public_key:
@@ -574,6 +610,7 @@ class Wallet:
'frozen_addresses':self.frozen_addresses,
'prioritized_addresses':self.prioritized_addresses,
'expert_mode':self.expert_mode,
+ 'gap_limit':self.gap_limit,
}
f = open(self.path,"w")
f.write( repr(s) )
@@ -613,6 +650,7 @@ class Wallet:
self.frozen_addresses = d.get('frozen_addresses',[])
self.prioritized_addresses = d.get('prioritized_addresses',[])
self.expert_mode = d.get('expert_mode',False)
+ self.gap_limit = d.get('gap_limit',5)
except:
raise BaseException("cannot read wallet file")