fix(blockchair): handle zero balance addresses edge case#35
Conversation
|
|
||
| if (response.data[address] === undefined) { | ||
| return { | ||
| result: 0n, | ||
| } | ||
| } | ||
|
|
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
What was done?
The problem
When an address has a zero balance, they blockchair API returns an empty data object causing the
getBalanceto return an error , which in turn breaksgetUTXOAddress with balance

Zero Balance address
The fix
To fix this, 0 is returned in
getBalancewhen the data object is empty, and ingetUTXOsa default value of balance is set to 0.