pybitcoin icon indicating copy to clipboard operation
pybitcoin copied to clipboard

get_unspents should return an empty list for valid addresses with no transactions

Open Saturnix opened this issue 10 years ago • 5 comments

get_unspents("19SbDasdasdNEkwRqnBAv7Ewumy7XcCau9Wp4BH9")

Expected behavior: result: [ ]

Actual behavior: result: Exception('Invalid response from blockchain.info.')

Reson: blockchain.info returns non-JSON response "No free outputs to spend" if the address is valid but with no unspents. The file "blockchain_info.py" (at lines 49 to 53) doesn't check for non-JSON responses but blatantly returns error if it cannot parse JSON content.

Proposed fix: at line 50: if r.content == "No free outputs to spend": return [ ]

Saturnix avatar Dec 29 '15 23:12 Saturnix

Thanks @Saturnix - would you like to submit a pull request?

shea256 avatar Dec 29 '15 23:12 shea256

Hello @shea256, thanks for your interest and wonderful work.

Do you agree that get_unspents should return empty list in this case? Please consider the impact this might have and possible regressions: I have not done so. A "find usages" of get_unspents finds no other place where this is used, so we should be fine.

Yes: I'd like to do a pull request now, though I'm completely new to Git. Sorry in advance should I fail to do so adequately.

Saturnix avatar Dec 29 '15 23:12 Saturnix

Yes, I agree that this should be an empty list.

Separate issue, but I'd point out that your bitcoin address isn't valid.

And no worries - I'd try looking into how to do a pull request and if you can't figure it out, I can always make the change. But I find it's best if contributors make the changes themselves, for the community at least.

What you should do:

  1. fork the project on github
  2. open the command line and clone the project
  3. make changes and commit them
  4. push your changes to your fork
  5. go to github and submit a pull request from your fork to the origin

shea256 avatar Dec 30 '15 00:12 shea256

Done. I hope I did everything ok.

Separate issue, but I'd point out that your bitcoin address isn't valid.

You're right: thanks for pointing out. I generated that address with your class BitcoinPrivateKey. I'll figure out if I've done something wrong with it or if there is a bug in pybitcoin. I suspect the first case: I'll report back.

Saturnix avatar Dec 30 '15 00:12 Saturnix

My error. To do some tests I've added "asdasd" inside of the address to check how the library handles invalid addresses. So I've copied the call to get_unspents with the invalid address, instead of the correct one (which is "get_unspents("19SbDNEkwRqnBAv7Ewumy7XcCau9Wp4BH9")).

1AM in the morning, I need to get some sleep...

Saturnix avatar Dec 30 '15 00:12 Saturnix