Skip to content

Commit 0aed0ae

Browse files
spivachukashcherbakov
authored andcommitted
INDY-925: Reworked wallet migration mechanism (hyperledger#437)
* INDY-925: Client migration for multi-network - Removed client migration actions which had become useless. Signed-off-by: Nikita Spivachuk <[email protected]> * INDY-925: Reworked wallet migration mechanism - Reworked the wallet migration mechanism to be able to process nested wallets. Signed-off-by: Nikita Spivachuk <[email protected]>
1 parent b434399 commit 0aed0ae

File tree

5 files changed

+7
-57
lines changed

5 files changed

+7
-57
lines changed

ledger/genesis_txn/genesis_txn_file_util.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,6 @@ def genesis_txn_path(base_dir, transaction_file):
1313
return os.path.join(base_dir, genesis_txn_file(transaction_file))
1414

1515

16-
def update_genesis_txn_file_name_if_outdated(base_dir, transaction_file):
17-
old_named_path = os.path.join(base_dir, transaction_file)
18-
new_named_path = os.path.join(base_dir, genesis_txn_file(transaction_file))
19-
if not os.path.exists(new_named_path) and os.path.isfile(old_named_path):
20-
os.rename(old_named_path, new_named_path)
21-
22-
2316
def create_genesis_txn_init_ledger(data_dir, txn_file):
2417
from ledger.genesis_txn.genesis_txn_initiator_from_file import GenesisTxnInitiatorFromFile
2518
initiator = GenesisTxnInitiatorFromFile(data_dir, txn_file)

plenum/cli/cli.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77

88
from jsonpickle import json
99
from ledger.compact_merkle_tree import CompactMerkleTree
10-
from ledger.genesis_txn.genesis_txn_file_util import create_genesis_txn_init_ledger, \
11-
update_genesis_txn_file_name_if_outdated
10+
from ledger.genesis_txn.genesis_txn_file_util import create_genesis_txn_init_ledger
1211
from ledger.genesis_txn.genesis_txn_initiator_from_file import GenesisTxnInitiatorFromFile
1312
from ledger.ledger import Ledger
1413
from plenum.cli.command import helpCmd, statusNodeCmd, statusClientCmd, \
@@ -69,7 +68,7 @@
6968
firstValue, randomString, bootstrapClientKeys, \
7069
getFriendlyIdentifier, \
7170
normalizedWalletFileName, getWalletFilePath, \
72-
getLastSavedWalletFileName, updateWalletsBaseDirNameIfOutdated
71+
getLastSavedWalletFileName
7372
from stp_core.common.log import \
7473
getlogger, Logger
7574
from plenum.server.node import Node
@@ -259,8 +258,6 @@ def __init__(self, looper, basedirpath: str, ledger_base_dir: str, nodeReg=None,
259258
tp = loadPlugins(self.basedirpath)
260259
self.logger.debug("total plugins loaded in cli: {}".format(tp))
261260

262-
updateWalletsBaseDirNameIfOutdated(self.config)
263-
264261
self.restoreLastActiveWallet()
265262

266263
self.checkIfCmdHandlerAndCmdMappingExists()

plenum/client/pool_manager.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import collections
22
import json
33

4-
from ledger.genesis_txn.genesis_txn_file_util import \
5-
update_genesis_txn_file_name_if_outdated
64
from ledger.util import F
75
from stp_core.network.exceptions import RemoteNotFound
86

@@ -25,8 +23,6 @@ def __init__(self):
2523
self._ledgerFile = None
2624
TxnStackManager.__init__(self, self.name, self.basedirpath,
2725
isNode=False)
28-
update_genesis_txn_file_name_if_outdated(self.basedirpath,
29-
self.ledgerFile)
3026
_, cliNodeReg, nodeKeys = self.parseLedgerForHaAndKeys(self.ledger)
3127
self.nodeReg = cliNodeReg
3228
self.addRemoteKeysFromLedger(nodeKeys)

plenum/client/wallet.py

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@
66

77
import jsonpickle
88
from jsonpickle import JSONBackend
9-
from jsonpickle import tags
10-
from jsonpickle.unpickler import loadclass
11-
from jsonpickle.util import importable_name
129
from libnacl import crypto_secretbox_open, randombytes, \
1310
crypto_secretbox_NONCEBYTES, crypto_secretbox
1411
from plenum.common.constants import CURRENT_PROTOCOL_VERSION
@@ -41,17 +38,6 @@ def decrypt(self, key) -> 'Wallet':
4138
("lastReqId", int)])
4239

4340

44-
def getClassVersionKey(cls):
45-
"""
46-
Gets the wallet class version key for use in a serialized representation
47-
of the wallet.
48-
49-
:param cls: the wallet class
50-
:return: the class version key
51-
"""
52-
return 'classver/{}'.format(importable_name(cls))
53-
54-
5541
class Wallet:
5642
def __init__(self,
5743
name: str=None,
@@ -418,28 +404,21 @@ def loadWallet(self, fpath):
418404
return wallet
419405

420406

407+
WALLET_RAW_MIGRATORS = []
408+
409+
421410
class WalletCompatibilityBackend(JSONBackend):
422411
"""
423412
Jsonpickle backend providing conversion of raw representations
424413
(nested dictionaries/lists structure) of wallets from previous versions
425414
to the current version.
426415
"""
427416

428-
def _getUpToDateClassName(self, pickledClassName):
429-
return pickledClassName.replace('sovrin_client', 'indy_client')
430-
431417
def decode(self, string):
432418
raw = super().decode(string)
433419
# Note that backend.decode may be called not only for the whole object
434420
# representation but also for representations of non-string keys of
435421
# dictionaries.
436-
# Here we assume that if the string represents a class instance and
437-
# this class contains makeRawCompatible method then this class is
438-
# a wallet class supporting backward compatibility
439-
if isinstance(raw, dict) and tags.OBJECT in raw:
440-
clsName = raw[tags.OBJECT]
441-
cls = loadclass(self._getUpToDateClassName(clsName))
442-
if hasattr(cls, 'makeRawCompatible') \
443-
and callable(getattr(cls, 'makeRawCompatible')):
444-
cls.makeRawCompatible(raw)
422+
for migrator in WALLET_RAW_MIGRATORS:
423+
migrator(raw)
445424
return raw

plenum/common/util.py

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -560,21 +560,6 @@ def getLastModifiedTime(file):
560560
return basename(newest)
561561

562562

563-
def updateWalletsBaseDirNameIfOutdated(config):
564-
"""
565-
Renames the wallets base directory if it has the outdated name.
566-
567-
:param config: the application configuration
568-
"""
569-
if config.walletsDir == 'wallets': # if the parameter is not overridden
570-
oldNamedPath = os.path.expanduser(os.path.join(config.baseDir,
571-
'keyrings'))
572-
newNamedPath = os.path.expanduser(os.path.join(config.baseDir,
573-
'wallets'))
574-
if not os.path.exists(newNamedPath) and os.path.isdir(oldNamedPath):
575-
os.rename(oldNamedPath, newNamedPath)
576-
577-
578563
def pop_keys(mapping: Dict, cond: Callable):
579564
rem = []
580565
for k in mapping:

0 commit comments

Comments
 (0)