Skip to content

Commit

Permalink
wallet db upgrade: AddrSync to use scriptPubKeys instead of addresses
Browse files Browse the repository at this point in the history
  • Loading branch information
SomberNight committed Feb 14, 2023
1 parent 957a505 commit af8148f
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion electrum/wallet_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@

OLD_SEED_VERSION = 4 # electrum versions < 2.0
NEW_SEED_VERSION = 11 # electrum versions >= 2.0
FINAL_SEED_VERSION = 50 # electrum >= 2.7 will set this to prevent
FINAL_SEED_VERSION = 51 # electrum >= 2.7 will set this to prevent
# old versions from overwriting new format


Expand Down Expand Up @@ -199,6 +199,7 @@ def upgrade(self):
self._convert_version_48()
self._convert_version_49()
self._convert_version_50()
self._convert_version_51()
self.put('seed_version', FINAL_SEED_VERSION) # just to be sure

self._after_upgrade_tasks()
Expand Down Expand Up @@ -980,6 +981,26 @@ def _convert_version_50(self):
self._convert_invoices_keys(requests)
self.data['seed_version'] = 50

def _convert_version_51(self):
# convert addr->spk in txi/txo/addr_history
if not self._is_upgrade_method_needed(50, 50):
return
from .bitcoin import address_to_script
# txid -> addr -> prev_outpoint -> value
txi = self.get('txi', {})
for tx_hash, d in list(txi.items()):
txi[tx_hash] = {address_to_script(addr): x for addr, x in d.items()}
self.data['txi'] = txi
# txid -> addr -> output_index -> (value, is_coinbase)
txo = self.get('txo', {})
for tx_hash, d in list(txo.items()):
txo[tx_hash] = {address_to_script(addr): x for addr, x in d.items()}
self.data['txo'] = txo
# addr -> list of (txid, height)
history = self.get('addr_history', {})
self.data['addr_history'] = {address_to_script(addr): x for addr, x in history.items()}
self.data['seed_version'] = 51

def _convert_imported(self):
if not self._is_upgrade_method_needed(0, 13):
return
Expand Down

0 comments on commit af8148f

Please sign in to comment.