stacks-network / pybitcoin

A Bitcoin python library for private + public keys, addresses, transactions, & RPC
MIT License
277 stars 117 forks source link

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

Open Saturnix opened 8 years ago

Saturnix commented 8 years ago

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 [ ]

shea256 commented 8 years ago

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

Saturnix commented 8 years ago

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.

shea256 commented 8 years ago

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
Saturnix commented 8 years ago

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 commented 8 years ago

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...