Skip to content

Commit

Permalink
Agent issuer wallet restoration (#117)
Browse files Browse the repository at this point in the history
* supplied keys parameter as True to wallet encoding and decoding functions so that dictionary keys which are custom objects restore properly, otherwise it used to be restored as string oppossed to actual object it was before persistence

* minor changes in list keyrings to show issuer wallet for agent as well

* minor change to print base wallet first and then any other related wallets
  • Loading branch information
rajeshkalaria80 authored and ashcherbakov committed Apr 11, 2017
1 parent c7b656c commit 9c33ebd
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
32 changes: 16 additions & 16 deletions plenum/cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -1354,18 +1354,17 @@ def _newWallet(self, walletName=None):

def _listKeyringsAction(self, matchedVars):
if matchedVars.get('list_krs') == 'list keyrings':
envs = self.getAllEnvDirNamesForKeyrings()
contextDirPath = self.getContextBasedKeyringsBaseDir()
keyringBaseDir = self.getKeyringsBaseDir()
envPaths = [os.path.join(keyringBaseDir, e) for e in envs]
if len(envPaths) == 0:
envPaths = [keyringBaseDir]

contextDirPath = self.getContextBasedKeyringsBaseDir()
dirs_to_scan = self.getAllSubDirNamesForKeyrings()
if contextDirPath not in dirs_to_scan:
dirs_to_scan.insert(0, contextDirPath)
dirs_to_scan = [os.path.join(keyringBaseDir, e) for e in dirs_to_scan]
anyWalletFound = False
for e in envPaths:
fe = e.rstrip(os.sep)
envName = basename(fe)
files = glob.glob("{}/*.{}".format(fe, WALLET_FILE_EXTENSION))
for dir in dirs_to_scan:
cleaned_dir_name = dir.rstrip(os.sep) # removed os path separator at the end
dir_name = basename(cleaned_dir_name)
files = glob.glob("{}/*.{}".format(cleaned_dir_name, WALLET_FILE_EXTENSION))
persistedWalletNames = []
unpersistedWalletNames = []

Expand All @@ -1374,22 +1373,23 @@ def _listKeyringsAction(self, matchedVars):
walletName = Cli.getWalletKeyName(basename(f))
persistedWalletNames.append(walletName)

if contextDirPath == fe:
if contextDirPath == cleaned_dir_name:
unpersistedWalletNames = [
n for n in self.wallets.keys()
if n.lower() not in persistedWalletNames]

if len(persistedWalletNames) > 0 or \
len(unpersistedWalletNames) > 0:
anyWalletFound = True
self.print("\nEnvironment: {}".format(envName))
self.print("\nContext Name: {}".format(dir_name), newline=False)
self.print(" (path:{})".format(dir), Token.Gray)

if len(persistedWalletNames) > 0:
self.print(" Persisted wallets:")
for pwn in persistedWalletNames:
f = os.path.join(fe, normalizedWalletFileName(pwn))
f = os.path.join(cleaned_dir_name, normalizedWalletFileName(pwn))
lastModifiedTime = time.ctime(os.path.getmtime(f))
isThisActiveWallet = True if contextDirPath == fe and \
isThisActiveWallet = True if contextDirPath == cleaned_dir_name and \
self._activeWallet is not None and \
self._activeWallet.name.lower() == pwn.lower() \
else False
Expand Down Expand Up @@ -1538,7 +1538,7 @@ def _isWalletFilePathBelongsToCurrentContext(self, filePath):

return True

def getAllEnvDirNamesForKeyrings(self):
def getAllSubDirNamesForKeyrings(self):
return [NO_ENV]

def checkIfWalletPathBelongsToCurrentContext(self, filePath):
Expand All @@ -1552,7 +1552,7 @@ def checkIfWalletPathBelongsToCurrentContext(self, filePath):
"according to the environment it belongs to."
"\nPossible sub directory names are: {}".
format(keyringsBaseDir, filePath,
self.getAllEnvDirNamesForKeyrings()))
self.getAllSubDirNamesForKeyrings()))
return False

curContextDirName = self.getContextBasedKeyringsBaseDir()
Expand Down
4 changes: 2 additions & 2 deletions plenum/common/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -489,14 +489,14 @@ def saveGivenWallet(wallet, fileName, contextDir):
walletFilePath = getWalletFilePath(
contextDir, fileName)
with open(walletFilePath, "w+") as walletFile:
encodedWallet = encode(wallet)
encodedWallet = encode(wallet, keys=True)
walletFile.write(encodedWallet)
return walletFilePath


def getWalletByPath(walletFilePath):
with open(walletFilePath) as walletFile:
wallet = decode(walletFile.read())
wallet = decode(walletFile.read(), keys=True)
return wallet


Expand Down

0 comments on commit 9c33ebd

Please sign in to comment.