Skip to content

Commit 468859a

Browse files
authored
feat(ironfish): Save encrypted accounts in the wallet (#5237)
* feat(ironfish): Save encrypted accounts in the wallet * feat(ironfish): Revert storing id * test(ironfish): Fix account value test
1 parent 286dc4a commit 468859a

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

ironfish/src/wallet/wallet.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import {
4242
import { WorkerPool } from '../workerPool'
4343
import { DecryptedNote, DecryptNotesItem } from '../workerPool/tasks/decryptNotes'
4444
import { Account, ACCOUNT_SCHEMA_VERSION } from './account/account'
45+
import { EncryptedAccount } from './account/encryptedAccount'
4546
import { AssetBalances } from './assetBalances'
4647
import {
4748
DuplicateAccountNameError,
@@ -94,6 +95,7 @@ export class Wallet {
9495
readonly onAccountRemoved = new Event<[account: Account]>()
9596

9697
protected readonly accountById = new Map<string, Account>()
98+
protected readonly encryptedAccounts = new Map<string, EncryptedAccount>()
9799
readonly walletDb: WalletDB
98100
private readonly logger: Logger
99101
readonly workerPool: WorkerPool
@@ -208,9 +210,17 @@ export class Wallet {
208210
}
209211

210212
private async load(): Promise<void> {
211-
for await (const accountValue of this.walletDb.loadAccounts()) {
212-
const account = new Account({ accountValue, walletDb: this.walletDb })
213-
this.accountById.set(account.id, account)
213+
for await (const [id, accountValue] of this.walletDb.loadAccounts()) {
214+
if (accountValue.encrypted) {
215+
const encryptedAccount = new EncryptedAccount({
216+
data: accountValue.data,
217+
walletDb: this.walletDb,
218+
})
219+
this.encryptedAccounts.set(id, encryptedAccount)
220+
} else {
221+
const account = new Account({ accountValue, walletDb: this.walletDb })
222+
this.accountById.set(account.id, account)
223+
}
214224
}
215225

216226
const meta = await this.walletDb.loadAccountsMeta()

ironfish/src/wallet/walletdb/walletdb.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import { BufferUtils } from '../../utils'
3232
import { BloomFilter } from '../../utils/bloomFilter'
3333
import { WorkerPool } from '../../workerPool'
3434
import { Account, calculateAccountPrefix } from '../account/account'
35-
import { AccountValue, AccountValueEncoding, DecryptedAccountValue } from './accountValue'
35+
import { AccountValue, AccountValueEncoding } from './accountValue'
3636
import { AssetValue, AssetValueEncoding } from './assetValue'
3737
import { BalanceValue, BalanceValueEncoding } from './balanceValue'
3838
import { DecryptedNoteValue, DecryptedNoteValueEncoding } from './decryptedNoteValue'
@@ -393,12 +393,9 @@ export class WalletDB {
393393

394394
async *loadAccounts(
395395
tx?: IDatabaseTransaction,
396-
): AsyncGenerator<DecryptedAccountValue, void, unknown> {
397-
for await (const account of this.accounts.getAllValuesIter(tx)) {
398-
// TODO(rohanjadvani): Remove this when encrypted accounts are managed in the wallet
399-
if (!account.encrypted) {
400-
yield account
401-
}
396+
): AsyncGenerator<[string, AccountValue], void, unknown> {
397+
for await (const [id, account] of this.accounts.getAllIter(tx)) {
398+
yield [id, account]
402399
}
403400
}
404401

0 commit comments

Comments
 (0)