remove "from addresses" from wallet logic
This commit is contained in:
@@ -32,7 +32,9 @@ import stat
|
||||
import pbkdf2, hmac, hashlib
|
||||
import base64
|
||||
import zlib
|
||||
from collections import defaultdict
|
||||
|
||||
from . import util
|
||||
from .util import PrintError, profiler, InvalidPassword, WalletFileException, bfh
|
||||
from .plugins import run_hook, plugin_loaders
|
||||
from .keystore import bip44_derivation
|
||||
@@ -44,7 +46,7 @@ from . import ecc
|
||||
|
||||
OLD_SEED_VERSION = 4 # electrum versions < 2.0
|
||||
NEW_SEED_VERSION = 11 # electrum versions >= 2.0
|
||||
FINAL_SEED_VERSION = 16 # electrum >= 2.7 will set this to prevent
|
||||
FINAL_SEED_VERSION = 17 # electrum >= 2.7 will set this to prevent
|
||||
# old versions from overwriting new format
|
||||
|
||||
|
||||
@@ -225,8 +227,8 @@ class WalletStorage(PrintError):
|
||||
|
||||
def put(self, key, value):
|
||||
try:
|
||||
json.dumps(key)
|
||||
json.dumps(value)
|
||||
json.dumps(key, cls=util.MyEncoder)
|
||||
json.dumps(value, cls=util.MyEncoder)
|
||||
except:
|
||||
self.print_error("json error: cannot save", key)
|
||||
return
|
||||
@@ -250,7 +252,7 @@ class WalletStorage(PrintError):
|
||||
return
|
||||
if not self.modified:
|
||||
return
|
||||
s = json.dumps(self.data, indent=4, sort_keys=True)
|
||||
s = json.dumps(self.data, indent=4, sort_keys=True, cls=util.MyEncoder)
|
||||
if self.pubkey:
|
||||
s = bytes(s, 'utf8')
|
||||
c = zlib.compress(s)
|
||||
@@ -329,6 +331,7 @@ class WalletStorage(PrintError):
|
||||
def requires_upgrade(self):
|
||||
return self.file_exists() and self.get_seed_version() < FINAL_SEED_VERSION
|
||||
|
||||
@profiler
|
||||
def upgrade(self):
|
||||
self.print_error('upgrading wallet format')
|
||||
|
||||
@@ -339,6 +342,7 @@ class WalletStorage(PrintError):
|
||||
self.convert_version_14()
|
||||
self.convert_version_15()
|
||||
self.convert_version_16()
|
||||
self.convert_version_17()
|
||||
|
||||
self.put('seed_version', FINAL_SEED_VERSION) # just to be sure
|
||||
self.write()
|
||||
@@ -531,6 +535,28 @@ class WalletStorage(PrintError):
|
||||
|
||||
self.put('seed_version', 16)
|
||||
|
||||
def convert_version_17(self):
|
||||
# delete pruned_txo; construct spent_outpoints
|
||||
if not self._is_upgrade_method_needed(16, 16):
|
||||
return
|
||||
|
||||
self.put('pruned_txo', None)
|
||||
|
||||
from .transaction import Transaction
|
||||
transactions = self.get('transactions', {}) # txid -> raw_tx
|
||||
spent_outpoints = defaultdict(dict)
|
||||
for txid, raw_tx in transactions.items():
|
||||
tx = Transaction(raw_tx)
|
||||
for txin in tx.inputs():
|
||||
if txin['type'] == 'coinbase':
|
||||
continue
|
||||
prevout_hash = txin['prevout_hash']
|
||||
prevout_n = txin['prevout_n']
|
||||
spent_outpoints[prevout_hash][prevout_n] = txid
|
||||
self.put('spent_outpoints', spent_outpoints)
|
||||
|
||||
self.put('seed_version', 17)
|
||||
|
||||
def convert_imported(self):
|
||||
if not self._is_upgrade_method_needed(0, 13):
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user