Skip to content

Commit

Permalink
feat(ironfish): Write encrypted accounts when toggling scanning
Browse files Browse the repository at this point in the history
  • Loading branch information
rohanjadvani committed Sep 19, 2024
1 parent 6fbfd31 commit eee04eb
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
2 changes: 1 addition & 1 deletion ironfish/src/rpc/routes/wallet/setScanning.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ routes.register<typeof SetScanningRequestSchema, SetScanningResponse>(
AssertHasRpcContext(request, context, 'wallet')

const account = getAccount(context.wallet, request.data.account)
await account.updateScanningEnabled(request.data.enabled)
await context.wallet.setScanningEnabled(account, request.data.enabled)
request.end()
},
)
12 changes: 11 additions & 1 deletion ironfish/src/wallet/account/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1299,10 +1299,20 @@ export class Account {

async updateScanningEnabled(
scanningEnabled: boolean,
options?: { masterKey: MasterKey | null },
tx?: IDatabaseTransaction,
): Promise<void> {
const walletEncrypted = await this.walletDb.accountsEncrypted(tx)

this.scanningEnabled = scanningEnabled
await this.walletDb.setAccount(this, tx)

if (walletEncrypted) {
Assert.isNotUndefined(options)
Assert.isNotNull(options?.masterKey)
await this.walletDb.setEncryptedAccount(this, options.masterKey, tx)
} else {
await this.walletDb.setAccount(this, tx)
}
}

async getTransactionNotes(
Expand Down
8 changes: 8 additions & 0 deletions ironfish/src/wallet/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1569,6 +1569,14 @@ export class Wallet {
await account.setName(name, { masterKey: this.masterKey }, tx)
}

async setScanningEnabled(
account: Account,
enabled: boolean,
tx?: IDatabaseTransaction,
): Promise<void> {
await account.updateScanningEnabled(enabled, { masterKey: this.masterKey }, tx)
}

get accounts(): Account[] {
return Array.from(this.accountById.values())
}
Expand Down

0 comments on commit eee04eb

Please sign in to comment.