Received balance incorrectly includes tx change
If change from a tx is sent back to the same address, it is erroneously counted in the totalReceived.
There is an issue on insight-api for this, but the bug lies here:
https://github.com/bitpay/insight-api/issues/351
Consider the massive discrepancy in total received as shown in that ticket between Insight and all other explorers.
I think we're going to need some additional indexes to make querying the satoshis being spent for each input faster here (see https://github.com/bitpay/bitcore-node/pull/376#issuecomment-173338788). There could also be some benefits with caching results, so we may want to take a look at adding that, and calculating the change in that case should be simple. However, there may be pros and cons to consider there that we should be careful.
Here is another case where we may need to lookup the previous transaction for each input to create the indexes: https://github.com/bitpay/bitcore-node/issues/397
Looks good in 3.0. Appears we can finally do this right this time. We're going to upgrade our Testnet instances and see how it goes.