dryphp / bitcoin.php

Bitcoin library for PHP.
http://www.nostate.com/3962/bitcoin-php-a-php-library-for-bitcoin/
242 stars 115 forks source link

added in exception to deal with not having enough bitcoins. #1

Closed DarrellDuane closed 13 years ago

DarrellDuane commented 13 years ago

Hi Mike, I've started using your library quite a bit, its very helpful. I did find that you've got Ctrl-Ms (Carriage Returns) in your file at the end of every line, which I've removed.

I've only added three lines in the sendtoaddress() method which checks to see if the person has enough bitcoins in their wallet to actually send the amount they want to send. However, because I removed all of these CRs, it will appear as if every line has changed. Not sure if there is a way around this for you in the editor you use, it'd be great to have them removed and typically you can save your files without the Carriage Returns.

I'm sending this pull request more as a test of the process, I expect that the next time I send a pull request I'll have a lot more code for you to integrate.

mikegogulski commented 13 years ago

Hi Darrell, nice to hear from you.

I'm not convinced that adding these kind of checks into the library is a good idea, though. My philosophy thus far has been to make each API-mirroring function simply sanitize/sanity-check the inputs, then execute a single JSON-RPC request to the server.

Without this change, the process for a send with insufficient funds would look like:

Quite sufficient, I think, to cover the instances where the balance is too low for the requested send.

On the other side, with your change and for a send request with sufficient funds, we get:

Seems to me like a waste of a method call, since sendtoaddress within the bitcoin server is going to do the balance check anyway.

Or have I missed something?

(PS: I've updated the library to 0.3.19 and included all of the new method calls, but have yet to write tests for them, which is why it's not here yet.)