X-Git-Url: https://git.novaco.in/?a=blobdiff_plain;f=lib%2Fwallet.py;h=169d008ef938981e4edde18da7234b84b801b922;hb=3cbe11a42473af52e7c5e002c36aaaf32646f627;hp=ff510eb91549b957ae0bc55f0a77995dca23e01e;hpb=b04256b474bc76961c6b9e550acb42567af5ed47;p=electrum-nvc.git diff --git a/lib/wallet.py b/lib/wallet.py index ff510eb..169d008 100644 --- a/lib/wallet.py +++ b/lib/wallet.py @@ -36,8 +36,8 @@ from plugins import run_hook import bitcoin from synchronizer import WalletSynchronizer -COINBASE_MATURITY = 100 -DUST_THRESHOLD = 5430 +COINBASE_MATURITY = 500 +DUST_THRESHOLD = 1000 # internal ID for imported account IMPORTED_ACCOUNT = '/x' @@ -76,7 +76,7 @@ class WalletStorage(object): new_path = os.path.join(config.path, "wallets", "default_wallet") # default path in pre 1.9 versions - old_path = os.path.join(config.path, "electrum.dat") + old_path = os.path.join(config.path, "electrum-nvc.dat") if os.path.exists(old_path) and not os.path.exists(new_path): os.rename(old_path, new_path) @@ -146,7 +146,7 @@ class Abstract_Wallet(object): self.history = storage.get('addr_history',{}) # address -> list(txid, height) - self.fee = int(storage.get('fee_per_kb', 10000)) + self.fee = int(storage.get('fee_per_kb', 1000)) self.next_addresses = storage.get('next_addresses',{}) @@ -181,7 +181,7 @@ class Abstract_Wallet(object): for k, raw in tx_list.items(): try: tx = Transaction.deserialize(raw) - except Exception: + except Exception, e: print_msg("Warning: Cannot deserialize transactions. skipping") continue self.add_pubkey_addresses(tx) @@ -352,7 +352,7 @@ class Abstract_Wallet(object): def get_public_keys(self, address): account_id, sequence = self.get_address_index(address) - return self.accounts[account_id].get_pubkeys(sequence) + return self.accounts[account_id].get_pubkeys(*sequence) def add_keypairs(self, tx, keypairs, password): # first check the provided password. This will raise if invalid. @@ -380,19 +380,15 @@ class Abstract_Wallet(object): def signrawtransaction(self, tx, private_keys, password): # check that the password is correct. This will raise if it's not. - self.get_seed(password) - + self.check_password(password) # build a list of public/private keys keypairs = {} - # add private keys from parameter for sec in private_keys: pubkey = public_key_from_private_key(sec) keypairs[ pubkey ] = sec - # add private_keys self.add_keypairs(tx, keypairs, password) - # sign the transaction self.sign_transaction(tx, keypairs, password) @@ -442,11 +438,6 @@ class Abstract_Wallet(object): if address in tx.get_output_addresses(): n += 1 return n - def get_address_flags(self, addr): - flags = "C" if self.is_change(addr) else "I" if addr in self.imported_keys.keys() else "-" - flags += "F" if addr in self.frozen_addresses else "-" - return flags - def get_tx_value(self, tx, account=None): domain = self.get_account_addresses(account) return tx.get_value(domain, self.prevout_values) @@ -454,7 +445,7 @@ class Abstract_Wallet(object): def update_tx_outputs(self, tx_hash): tx = self.transactions.get(tx_hash) - for i, (addr, value) in enumerate(tx.get_outputs()): + for i, (type, addr, value) in enumerate(tx.get_outputs()): key = tx_hash+ ':%d'%i self.prevout_values[key] = value @@ -474,7 +465,7 @@ class Abstract_Wallet(object): tx = self.transactions.get(tx_hash) if not tx: continue - for i, (addr, value) in enumerate(tx.get_outputs()): + for i, (type, addr, value) in enumerate(tx.get_outputs()): if addr == address: key = tx_hash + ':%d'%i received_coins.append(key) @@ -492,7 +483,7 @@ class Abstract_Wallet(object): if key in received_coins: v -= value - for i, (addr, value) in enumerate(tx.get_outputs()): + for i, (type, addr, value) in enumerate(tx.get_outputs()): key = tx_hash + ':%d'%i if addr == address: v += value @@ -545,8 +536,14 @@ class Abstract_Wallet(object): for tx_hash, tx_height in h: tx = self.transactions.get(tx_hash) if tx is None: raise Exception("Wallet not synchronized") + outputs = tx.get_outputs() + is_coinbase = tx.inputs[0].get('prevout_hash') == '0'*64 - for i, (address, value) in enumerate(tx.get_outputs()): + is_coinstake = outputs[0][2] == 0 + + #print is_coinstake + + for i, (type, address, value) in enumerate(outputs): output = {'address':address, 'value':value, 'prevout_n':i} if address != addr: continue key = tx_hash + ":%d"%i @@ -554,6 +551,8 @@ class Abstract_Wallet(object): output['prevout_hash'] = tx_hash output['height'] = tx_height output['coinbase'] = is_coinbase + output['coinstake'] = is_coinstake + output["type"] = type coins.append((tx_height, output)) # sort by age @@ -579,7 +578,7 @@ class Abstract_Wallet(object): inputs = [] for item in coins: - if item.get('coinbase') and item.get('height') + COINBASE_MATURITY > self.network.get_local_height(): + if (item.get('coinbase') or item.get('coinstake')) and item.get('height') + COINBASE_MATURITY < self.network.get_local_height(): continue v = item.get('value') total += v @@ -754,7 +753,7 @@ class Abstract_Wallet(object): for txin in inputs: self.add_input_info(txin) outputs = self.add_tx_change(inputs, outputs, amount, fee, total, change_addr) - return Transaction(inputs, outputs) + return Transaction(int(time.time()), inputs, outputs) def mktx(self, outputs, password, fee=None, change_addr=None, domain= None, coins = None ): tx = self.make_unsigned_transaction(outputs, fee, change_addr, domain, coins) @@ -825,11 +824,12 @@ class Abstract_Wallet(object): imported_account.update_password(old_password, new_password) self.save_accounts() - for k, v in self.master_private_keys.items(): - b = pw_decode(v, old_password) - c = pw_encode(b, new_password) - self.master_private_keys[k] = c - self.storage.put('master_private_keys', self.master_private_keys, True) + if hasattr(self, 'master_private_keys'): + for k, v in self.master_private_keys.items(): + b = pw_decode(v, old_password) + c = pw_encode(b, new_password) + self.master_private_keys[k] = c + self.storage.put('master_private_keys', self.master_private_keys, True) self.use_encryption = (new_password != None) self.storage.put('use_encryption', self.use_encryption,True) @@ -1336,12 +1336,6 @@ class NewWallet(Deterministic_Wallet): return True return False - def find_root_by_master_key(self, xpub): - for key, xpub2 in self.master_public_keys.items(): - if key == "m/":continue - if xpub == xpub2: - return key - def num_accounts(self): keys = [] for k, v in self.accounts.items():