Skip to content

fix(blockchair): handle zero balance addresses edge case#35

Merged
chybisov merged 5 commits into
mainfrom
fix-blockchair-get-balance
Sep 29, 2025
Merged

fix(blockchair): handle zero balance addresses edge case#35
chybisov merged 5 commits into
mainfrom
fix-blockchair-get-balance

Conversation

@tomiiide
Copy link
Copy Markdown
Contributor

@tomiiide tomiiide commented Sep 26, 2025

What was done?

The problem

When an address has a zero balance, they blockchair API returns an empty data object causing the getBalance to return an error , which in turn breaks getUTXO

Address with balance
Screenshot 2025-09-26 at 14 24 51

Zero Balance address

Screenshot 2025-09-26 at 14 24 46

The fix

To fix this, 0 is returned in getBalance when the data object is empty, and in getUTXOs a default value of balance is set to 0.

@tomiiide tomiiide requested a review from chybisov September 26, 2025 13:32
@tomiiide tomiiide self-assigned this Sep 26, 2025
Comment on lines +34 to +40

if (response.data[address] === undefined) {
return {
result: 0n,
}
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please provide some context - if we return 0n here now, are we still going to fallback to other providers to try fetch the price when it's not available in blockchair? We need to add tests for our retry logic.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a check above that throws an error when the req status is not a 200, or when blockchair returns an error object. So, if blockchair fails, the fallback would still happen.

This is for an edge case that happens on blockchair when the data object is empty, and it happens when the address is non existent or has a 0 address.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Though returning 0n did not break fallback logic. I've reverted to throwing an error as it is more accurate.

The error thrown by getBalance would be caught and thrown by getUTXOs which would trigger the fallback logic.

I also added test for this edge case.

@chybisov

@tomiiide tomiiide requested a review from chybisov September 29, 2025 09:48
@chybisov chybisov merged commit a57c5fd into main Sep 29, 2025
@chybisov chybisov deleted the fix-blockchair-get-balance branch September 29, 2025 09:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants