Bitcoin Forum
May 25, 2024, 08:25:31 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: python-bitcoinrpc  (Read 454 times)
tomtomtom7 (OP)
Jr. Member
*
Offline Offline

Activity: 38
Merit: 18


View Profile
October 13, 2013, 07:55:00 PM
 #1

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?)
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
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!