commit 441c68fbcca691106e3172924136a19c7cee3dfc
parent bde0ca3ea1e82a50e7422db57617f879865c7f19
Author: ThomasV <thomasv@gitorious>
Date: Mon, 15 Sep 2014 09:44:59 +0200
cache xpub values in account in order to generate addresses faster
Diffstat:
1 file changed, 15 insertions(+), 13 deletions(-)
diff --git a/lib/account.py b/lib/account.py
@@ -164,7 +164,6 @@ class ImportedAccount(Account):
def get_name(self, k):
return _('Imported keys')
-
def update_password(self, old_password, new_password):
for k, v in self.keypairs.items():
pubkey, a = v
@@ -280,6 +279,8 @@ class BIP32_Account(Account):
def __init__(self, v):
Account.__init__(self, v)
self.xpub = v['xpub']
+ self.xpub_receive = None
+ self.xpub_change = None
def dump(self):
d = Account.dump(self)
@@ -308,7 +309,17 @@ class BIP32_Account(Account):
return pubkeys[i]
def derive_pubkeys(self, for_change, n):
- return self.derive_pubkey_from_xpub(self.xpub, for_change, n)
+ xpub = self.xpub_change if for_change else self.xpub_receive
+ if xpub is None:
+ xpub = bip32_public_derivation(self.xpub, "", "/%d"%for_change)
+ if for_change:
+ self.xpub_change = xpub
+ else:
+ self.xpub_receive = xpub
+ _, _, _, c, cK = deserialize_xkey(xpub)
+ cK, c = CKD_pub(cK, c, n)
+ result = cK.encode('hex')
+ return result
def get_private_key(self, sequence, wallet, password):
@@ -348,18 +359,9 @@ class BIP32_Account(Account):
assert len(s) == 2
return xkey, s
-
def get_name(self, k):
- name = "Unnamed account"
- m = re.match("m/(\d+)'", k)
- if m:
- num = m.group(1)
- if num == '0':
- name = "Main account"
- else:
- name = "Account %s"%num
-
- return name
+ return "Main account" if k == '0' else "Account " + k
+