Bitcoin Forum

Other => Beginners & Help => Topic started by: tomtomtom7 on October 13, 2013, 07:55:00 PM



Title: python-bitcoinrpc
Post by: tomtomtom7 on October 13, 2013, 07:55:00 PM
Hello,

I am having some trouble with creating transactions using python-bitcoinrpc (on python 2.7.x).

It seems that the library doesn't support the Decimal data type; when I do:

Code:
new_tx = btcoind.createrawtransaction([{ 'txid': mytx, 'vout': myvout}], { to_addr: Decimal('0.001') })

It raises:
Code:
...
  File "/usr/lib/python2.7/json/encoder.py", line 184, in default
    raise TypeError(repr(o) + " is not JSON serializable")
TypeError: Decimal('0.001') is not JSON serializable

I have seen some solutions (http://stackoverflow.com/questions/1960516/python-json-serialize-a-decimal-object? (http://stackoverflow.com/questions/1960516/python-json-serialize-a-decimal-object?))
but they all seem to entail converting the decimal either to float or to string. The first is not an option due to the loss of precision and the second creates a json-rpc error.

How can I ensure the decimal is properly encoded to json?

Thanks,
Tomas