Author

Topic: Python wrapper for bitcoind (Read 10696 times)

legendary
Activity: 1708
Merit: 1020
April 08, 2012, 10:39:36 AM
#7
fyi: namecoind wrapper forked: http://dot-bit.org/forum/viewtopic.php?f=2&t=482
legendary
Activity: 1428
Merit: 1093
Core Armory Developer
August 14, 2011, 07:13:46 PM
#6
I'm differentiating users from developers, here.  I recognize the Tracebacks are useful for developers, but as a user, I don't plan to be debugging his code.  Plus, this isn't the result of a bug--it's a legitimate validation failure response.   Not a big deal, it was just a recommendation...

legendary
Activity: 1708
Merit: 1020
August 14, 2011, 06:16:55 PM
#5
[...]
Or whatever info/format-string you want, but those Traceback messages tend to scare users.

lol, for me it's the other way round.

it may be true but for me tracebacks are much more useful. custom error messages make finding bugs much harder and it can be a pain to reinstall the tracebacks.

legendary
Activity: 1428
Merit: 1093
Core Armory Developer
August 14, 2011, 04:07:35 PM
#4
Looks great, db.

Just a minor recommendation: given the ease with which you can catch errors in python, you might consider an except(BitcoinError) clause to gracefully fail when you have insufficient funds, or other error.   Your original post showed this:

Code:
>>> bitcoin.sendtoaddress("1Nsq3itZULUZjtZGcjNrtZtwT8aMsHu1R1", 1000000)
Traceback (most recent call last):
  File "", line 1, in
  File "bitcoin.py", line 73, in sendtoaddress
    _cmd("sendtoaddress %s %d %s %s" % (bitcoinaddress, amount, comment, comment_to))
  File "bitcoin.py", line 86, in _cmd
    return _parse(_cmd_raw(args))[0]
  File "bitcoin.py", line 92, in _cmd_raw
    raise BitcoinError(errors)
bitcoin.BitcoinError: error: Insufficient funds

It should be pretty easy to produce something like this, instead:

Code:
>>> bitcoin.sendtoaddress("1Nsq3itZULUZjtZGcjNrtZtwT8aMsHu1R1", 1000000)
***ERROR:  Insufficient funds***
   Attempted Transaction:  1000000
   Available Balance:       922100

Or whatever info/format-string you want, but those Traceback messages tend to scare users.
legendary
Activity: 1708
Merit: 1020
sr. member
Activity: 252
Merit: 268
July 08, 2010, 10:37:21 PM
#2
That's great! Thanks db!
db
sr. member
Activity: 279
Merit: 261
July 08, 2010, 06:50:43 PM
#1
While creating the Bitcoin automation for mullvad.net I made a python wrapper around bitcoind. Should anyone else find such a thing useful it is available here:

https://www.mullvad.net/download/bitcoin.py

Usage example:

>>> import bitcoin
>>> bitcoin.getaddressesbylabel("foo")
['16au2i9ny5pnwCPnoekov2hHMhtS7qcFjR', '19BkB63mo3NQRPNeHkc3bWnKGBU7oL8Dp7']
>>> bitcoin.getreceivedbylabel("Your Address")
6.0
>>> bitcoin.listreceivedbyaddress()
{'16au2i9ny5pnwCPnoekov2hHMhtS7qcFjR': {'amount': 2000.0, 'label': 'foo', 'confirmations': 226, 'address': '16au2i9ny5pnwCPnoekov2hHMhtS7qcFjR'}, '1FLD8wCNNBh2wg2mnGjD9ogoLaRxpSz7TW': {'amount': 6.0, 'label': 'Your Address', 'confirmations': 343, 'address': '1FLD8wCNNBh2wg2mnGjD9ogoLaRxpSz7TW'}}
>>> bitcoin.sendtoaddress("1Nsq3itZULUZjtZGcjNrtZtwT8aMsHu1R1", 1234.5)
>>> bitcoin.sendtoaddress("1Nsq3itZULUZjtZGcjNrtZtwT8aMsHu1R1", 1000000)
Traceback (most recent call last):
  File "", line 1, in
  File "bitcoin.py", line 73, in sendtoaddress
    _cmd("sendtoaddress %s %d %s %s" % (bitcoinaddress, amount, comment, comment_to))
  File "bitcoin.py", line 86, in _cmd
    return _parse(_cmd_raw(args))[0]
  File "bitcoin.py", line 92, in _cmd_raw
    raise BitcoinError(errors)
bitcoin.BitcoinError: error: Insufficient funds

>>>

Jump to: