From 70445da9408269fb4021137cac85363d6575972a Mon Sep 17 00:00:00 2001 From: ThomasV Date: Fri, 16 Aug 2013 13:26:48 +0200 Subject: [PATCH] wallet.num_accounts and account_id method --- gui/plugins.py | 1 + lib/bitcoin.py | 4 ++-- lib/wallet.py | 20 +++++++++++++------- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/gui/plugins.py b/gui/plugins.py index e9e99160f..1a758a996 100644 --- a/gui/plugins.py +++ b/gui/plugins.py @@ -4,6 +4,7 @@ class BasePlugin: def __init__(self, gui, name): self.gui = gui + self.wallet = self.gui.wallet self.name = name self.config = gui.config diff --git a/lib/bitcoin.py b/lib/bitcoin.py index bd1625e89..8281bb1cb 100644 --- a/lib/bitcoin.py +++ b/lib/bitcoin.py @@ -614,7 +614,7 @@ class Transaction: signatures = txin.get("signatures",[]) # continue if this txin is complete - if len(signatures == num): + if len(signatures) == num: continue # build list of public/private keys @@ -643,7 +643,7 @@ class Transaction: # for p2sh, pubkeysig is a tuple (may be incomplete) txin["signatures"] = signatures print_error("signatures", signatures) - is_complete = is_complete and len(signatures == num) + is_complete = is_complete and len(signatures) == num else: diff --git a/lib/wallet.py b/lib/wallet.py index b180aecc1..685a929a3 100644 --- a/lib/wallet.py +++ b/lib/wallet.py @@ -207,24 +207,30 @@ class Wallet: self.create_account('Main account') - - def create_account(self, name, account_type = None): - + def account_id(self, account_type, i): if account_type is None: - derivation = lambda i: "m/0'/%d'"%i + return "m/0'/%d'"%i elif account_type == '2of2': - derivation = lambda i: "m/1'/%d & m/2'/%d"%(i,i) + return "m/1'/%d & m/2'/%d"%(i,i) elif account_type == '2of3': - derivation = lambda i: "m/3'/%d & m/4'/%d & m/5'/%d"%(i,i,i) + return "m/3'/%d & m/4'/%d & m/5'/%d"%(i,i,i) else: raise BaseException('unknown account type') + + def num_accounts(self, account_type): keys = self.accounts.keys() i = 0 while True: - account_id = derivation(i) + account_id = self.account_id(account_type, i) if account_id not in keys: break i += 1 + return i + + + def create_account(self, name, account_type = None): + i = self.num_accounts(account_type) + acount_id = self.account_id(account_type,i) if account_type is None: master_c0, master_K0, _ = self.master_public_keys["m/0'/"]