Skip to content

Commit

Permalink
fix bug in getOutpointsByAddress
Browse files Browse the repository at this point in the history
  • Loading branch information
alejoacosta74 committed Sep 22, 2024
1 parent 76d94e6 commit b684daf
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 11 deletions.
9 changes: 4 additions & 5 deletions src/providers/abstract-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1484,16 +1484,15 @@ export class AbstractProvider<C = FetchRequest> implements Provider {
}

async getOutpointsByAddress(address: AddressLike): Promise<Outpoint[]> {
const outpoints: OutpointResponseParams[] = await this.#getAccountValue(
const outpointsObj: Record<string, OutpointResponseParams> = await this.#getAccountValue(
{ method: 'getOutpointsByAddress' },
address,
'latest',
);

const outpointsArray = Array.isArray(outpoints) ? outpoints : [];

return outpointsArray.map((outpoint: OutpointResponseParams) => ({
txhash: outpoint.Txhash,
// Convert the object to an array of Outpoint objects
return Object.values(outpointsObj).map((outpoint: OutpointResponseParams) => ({
txhash: outpoint.TxHash,
index: outpoint.Index,
denomination: outpoint.Denomination,
}));
Expand Down
2 changes: 1 addition & 1 deletion src/providers/formatting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ export interface QiTransactionResponseParams {
}

export interface OutpointResponseParams {
Txhash: string;
TxHash: string;
Index: number;
Denomination: number;
}
6 changes: 1 addition & 5 deletions src/wallet/qi-hdwallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -482,11 +482,7 @@ export class QiHDWallet extends AbstractHDWallet {
*/
private async getOutpointsByAddress(address: string): Promise<Outpoint[]> {
try {
const outpointsMap = await this.provider!.getOutpointsByAddress(address);
if (!outpointsMap) {
return [];
}
return Object.values(outpointsMap) as Outpoint[];
return await this.provider!.getOutpointsByAddress(address);
} catch (error) {
throw new Error(`Failed to get outpoints for address: ${address} - error: ${error}`);
}
Expand Down

0 comments on commit b684daf

Please sign in to comment.