-
Notifications
You must be signed in to change notification settings - Fork 207
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: migrate wallet from .afj to .credo
Signed-off-by: Sai Ranjit Tummalapalli <sairanjit.tummalapalli@ayanworks.com>
- Loading branch information
Showing
7 changed files
with
185 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import type { BaseAgent } from '../../../../agent/BaseAgent' | ||
|
||
import { migrateToCredoFolder } from './migrateToCredoFolder' | ||
|
||
export async function updateV0_5ToV0_6<Agent extends BaseAgent>(agent: Agent): Promise<void> { | ||
await migrateToCredoFolder(agent) | ||
} |
36 changes: 36 additions & 0 deletions
36
packages/core/src/storage/migration/updates/0.5-0.6/migrateToCredoFolder.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import type { BaseAgent } from '../../../../agent/BaseAgent' | ||
import type { FileSystem } from '../../../FileSystem' | ||
|
||
import { InjectionSymbols } from '../../../../constants' | ||
import { CredoError } from '../../../../error' | ||
|
||
/** | ||
* Migrates the sqlite folder location from .afj to .credo in the storage directory in node and react native. | ||
* | ||
*/ | ||
export async function migrateToCredoFolder<Agent extends BaseAgent>(agent: Agent) { | ||
const walletId = agent.config.walletConfig?.id | ||
|
||
if (!walletId) { | ||
throw new CredoError('Wallet id is required to migrate the wallet to .credo') | ||
} | ||
|
||
// Adding type assertion to get the storage config | ||
const storageConfig = agent.config.walletConfig?.storage as { | ||
config?: { inMemory?: boolean } | ||
} | ||
|
||
// If no storage config is provided, we set default as sqlite | ||
// https://github.com/openwallet-foundation/credo-ts/blob/main/packages/askar/src/utils/askarWalletConfig.ts#L35 | ||
// and we only migrate the data folder if the storage config is not set to inMemory | ||
if (!storageConfig || (storageConfig.config && !storageConfig.config?.inMemory)) { | ||
return | ||
} | ||
|
||
agent.config.logger.info('Migrating data from .afj to .credo') | ||
|
||
const fileSystem = agent.dependencyManager.resolve<FileSystem>(InjectionSymbols.FileSystem) | ||
|
||
await fileSystem.migrateWalletToCredoFolder(walletId) | ||
agent.config.logger.info('Migration completed successfully') | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters