Skip to content

Commit

Permalink
make 'getAddressesForAccount' method abstract
Browse files Browse the repository at this point in the history
  • Loading branch information
alejoacosta74 authored and rileystephens28 committed Nov 13, 2024
1 parent 43f2fba commit abac1d7
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 12 deletions.
12 changes: 1 addition & 11 deletions src/wallet/hdwallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,17 +146,7 @@ export abstract class AbstractHDWallet<T extends NeuteredAddressInfo = NeuteredA
abstract getAddressInfo(address: string): T | null;
abstract getPrivateKey(address: string): string;
abstract getAddressesForZone(zone: Zone): T[];

/**
* Gets the addresses for a given account.
*
* @param {number} account - The account number.
* @returns {T[]} The addresses for the account.
*/
public getAddressesForAccount(account: number): T[] {
const addresses = this._addresses.values();
return Array.from(addresses).filter((addressInfo) => addressInfo.account === account) as T[];
}
abstract getAddressesForAccount(account: number): T[];

/**
* Creates an instance of the HD wallet.
Expand Down
13 changes: 13 additions & 0 deletions src/wallet/qi-hdwallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1707,4 +1707,17 @@ export class QiHDWallet extends AbstractHDWallet<QiAddressInfo> {

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);
}
}
13 changes: 12 additions & 1 deletion src/wallet/quai-hdwallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -369,11 +369,22 @@ export class QuaiHDWallet extends AbstractHDWallet<NeuteredAddressInfo> {
* 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);
}
}

0 comments on commit abac1d7

Please sign in to comment.