From 74875b736fd983a15d7f623b84481d994d1ff14c Mon Sep 17 00:00:00 2001 From: Alejo Acosta Date: Wed, 6 Nov 2024 14:49:00 -0300 Subject: [PATCH] make 'getAddressesForAccount' method abstract --- src/wallet/hdwallet.ts | 12 +----------- src/wallet/qi-hdwallet.ts | 13 +++++++++++++ src/wallet/quai-hdwallet.ts | 13 ++++++++++++- 3 files changed, 26 insertions(+), 12 deletions(-) diff --git a/src/wallet/hdwallet.ts b/src/wallet/hdwallet.ts index 3a750099..82ad8414 100644 --- a/src/wallet/hdwallet.ts +++ b/src/wallet/hdwallet.ts @@ -146,17 +146,7 @@ export abstract class AbstractHDWallet addressInfo.account === account) as T[]; - } + abstract getAddressesForAccount(account: number): T[]; /** * Creates an instance of the HD wallet. diff --git a/src/wallet/qi-hdwallet.ts b/src/wallet/qi-hdwallet.ts index f71e6c2d..1b76a199 100644 --- a/src/wallet/qi-hdwallet.ts +++ b/src/wallet/qi-hdwallet.ts @@ -1707,4 +1707,17 @@ export class QiHDWallet extends AbstractHDWallet { return addressInfo; } + + /** + * Gets the addresses for a given account. + * + * @param {number} account - The account number. + * @returns {QiAddressInfo[]} The addresses for the account. + */ + public getAddressesForAccount(account: number): QiAddressInfo[] { + const addresses = this._addressesMap.values(); + return Array.from(addresses) + .flat() + .filter((info) => info.account === account); + } } diff --git a/src/wallet/quai-hdwallet.ts b/src/wallet/quai-hdwallet.ts index 551c9576..46123614 100644 --- a/src/wallet/quai-hdwallet.ts +++ b/src/wallet/quai-hdwallet.ts @@ -369,11 +369,22 @@ export class QuaiHDWallet extends AbstractHDWallet { * Gets the addresses for a given zone. * * @param {Zone} zone - The zone. - * @returns {T[]} The addresses for the zone. + * @returns {NeuteredAddressInfo[]} The addresses for the zone. */ public getAddressesForZone(zone: Zone): NeuteredAddressInfo[] { this.validateZone(zone); const addresses = this._addresses.values(); return Array.from(addresses).filter((addressInfo) => addressInfo.zone === zone); } + + /** + * Gets the addresses for a given account. + * + * @param {number} account - The account number. + * @returns {NeuteredAddressInfo[]} The addresses for the account. + */ + public getAddressesForAccount(account: number): NeuteredAddressInfo[] { + const addresses = this._addresses.values(); + return Array.from(addresses).filter((addressInfo) => addressInfo.account === account); + } }