diff --git a/packages/core-database/src/repositories/wallets-business-repository.ts b/packages/core-database/src/repositories/wallets-business-repository.ts index 8f1598a8ce..e8b686df70 100644 --- a/packages/core-database/src/repositories/wallets-business-repository.ts +++ b/packages/core-database/src/repositories/wallets-business-repository.ts @@ -42,11 +42,8 @@ export class WalletsBusinessRepository implements Database.IWalletsBusinessRepos return this.search({ ...params, ...{ vote: publicKey } }); } - // @TODO: simplify this public findById(id: string): State.IWallet { - return this.search().rows.find( - wallet => wallet.address === id || wallet.publicKey === id || wallet.username === id, - ); + return this.databaseServiceProvider().walletManager.findById(id); } public count(): number { diff --git a/packages/core-interfaces/src/core-state/wallets.ts b/packages/core-interfaces/src/core-state/wallets.ts index 0905bc753e..cc3ce4fbf7 100644 --- a/packages/core-interfaces/src/core-state/wallets.ts +++ b/packages/core-interfaces/src/core-state/wallets.ts @@ -46,6 +46,8 @@ export interface IWalletManager { allByUsername(): IWallet[]; + findById(id: string): IWallet; + findByAddress(address: string): IWallet; has(addressOrPublicKey: string): boolean; diff --git a/packages/core-state/src/wallets/wallet-manager.ts b/packages/core-state/src/wallets/wallet-manager.ts index f81ae782b4..37dbf54381 100644 --- a/packages/core-state/src/wallets/wallet-manager.ts +++ b/packages/core-state/src/wallets/wallet-manager.ts @@ -32,6 +32,10 @@ export class WalletManager implements State.IWalletManager { return Object.values(this.byUsername); } + public findById(id: string): State.IWallet { + return this.byAddress[id] || this.byPublicKey[id] || this.byUsername[id]; + } + public findByAddress(address: string): State.IWallet { if (address && !this.byAddress[address]) { this.byAddress[address] = new Wallet(address); @@ -310,9 +314,7 @@ export class WalletManager implements State.IWalletManager { if (a.publicKey === b.publicKey) { throw new Error( - `The balance and public key of both delegates are identical! Delegate "${ - a.username - }" appears twice in the list.`, + `The balance and public key of both delegates are identical! Delegate "${a.username}" appears twice in the list.`, ); }