f.write( s )
f.close()
if 'ANDROID_DATA' not in os.environ:
- import stat #XXX: IS this really android only?
+ import stat
os.chmod(self.path,stat.S_IREAD | stat.S_IWRITE)
def add_keypairs(self, tx, keypairs, password):
# first check the provided password. This will raise if invalid.
- self.get_seed(password)
+ self.check_password(password)
+
addr_list, xpub_list = tx.inputs_to_sign()
for addr in addr_list:
if self.is_mine(addr):
- private_keys = self.get_private_key(address, password)
+ private_keys = self.get_private_key(addr, password)
for sec in private_keys:
pubkey = public_key_from_private_key(sec)
keypairs[ pubkey ] = sec
c, u = self.get_addr_balance(address)
return len(h), len(h) > 0 and c == -u
+ def address_is_old(self, address, age_limit=2):
+ age = -1
+ h = self.history.get(address, [])
+ if h == ['*']:
+ return True
+ for tx_hash, tx_height in h:
+ if tx_height == 0:
+ tx_age = 0
+ else:
+ tx_age = self.network.get_local_height() - tx_height + 1
+ if tx_age > age:
+ age = tx_age
+ return age > age_limit
+
class Imported_Wallet(Abstract_Wallet):
h = self.history.get(address,[])
return len(h), False
+ def get_master_public_keys(self):
+ return {}
+
+ def is_beyond_limit(self, address, account, is_change):
+ return False
class Deterministic_Wallet(Abstract_Wallet):
if n > nmax: nmax = n
return nmax + 1
- def address_is_old(self, address):
- age = -1
- h = self.history.get(address, [])
- if h == ['*']:
- return True
- for tx_hash, tx_height in h:
- if tx_height == 0:
- tx_age = 0
- else:
- tx_age = self.network.get_local_height() - tx_height + 1
- if tx_age > age:
- age = tx_age
- return age > 2
-
def synchronize_sequence(self, account, for_change):
limit = self.gap_limit_for_change if for_change else self.gap_limit
new_addresses = []
self.accounts[account_id] = PendingAccount({'pending':addr})
self.save_accounts()
+ def is_beyond_limit(self, address, account, is_change):
+ if type(account) == ImportedAccount:
+ return False
+ addr_list = account.get_addresses(is_change)
+ i = addr_list.index(address)
+ prev_addresses = addr_list[:max(0, i)]
+ limit = self.gap_limit_for_change if is_change else self.gap_limit
+ if len(prev_addresses) < limit:
+ return False
+ prev_addresses = prev_addresses[max(0, i - limit):]
+ for addr in prev_addresses:
+ num, is_used = self.is_used(addr)
+ if num > 0:
+ return False
+ return True
+
class NewWallet(Deterministic_Wallet):
def create_accounts(self, password):
# First check the password is valid (this raises if it isn't).
- pw_decode(self.seed, password)
+ self.check_password(password)
self.create_account('Main account', password)
def add_master_public_key(self, name, mpk):