I'm looking at adding Joulecoin to my
MinerSwitcher setup, but I've run into a snag: I can't get the block reward out of joulecoind.
MinerSwitcher depends on
ProfitLib, which in turn depends on a set of coin daemons and some exchange data (currently from Cryptsy, but I'm looking at adding support for more exchanges) to determine which coin to mine at a particular time.
This block of ProfitLib code uses python-bitcoinrpc calls to retrieve the current block reward:
b=jsonrpc.ServiceProxy(url)
# get block reward, including transaction fees
# note #1: Novacoin (and coins derived from it?) report
# 1% of actual value here
# note #2: Namecoin doesn't support getblocktemplate, so get
# coinbase value from last block
# note #3: PPCoin doesn't want any parameters passed to
# getblocktemplate. Bitcoin requires at least
# an empty dictionary to be passed. Others don't
# care.
reward=Decimal(0)
try:
reward=Decimal(b.getblocktemplate()["coinbasevalue"])
except:
pass
if (reward==0):
try:
reward=Decimal(b.getblocktemplate({})["coinbasevalue"])
except:
pass
if (reward==0):
try:
vouts=b.decoderawtransaction(b.getrawtransaction(b.getblock(b.getblockhash(b.getblockcount()))["tx"][0]))["vout"]
for j, vout in enumerate(vouts):
reward+=vout["value"]
except:
pass
if (coin=="NVC" or coin=="DEM" or coin=="OSC"):
reward*=100
It tries three different methods, determined over the course of adding 25 other coins, that work:
* getblocktemplate with no input
* getblocktemplate with an empty input
* if getblocktemplate isn't available, get the coinbase value from the first transaction of the last block mined
This works for every other coin, but not for Joulecoin. getblocktemplate is a valid call; joulecoind getblocktemplate returns what you'd expect. There appears to be a communication error between
python-bitcoinrpc and joulecoind.
I knocked together this test script:
import bitcoinrpc
import jsonrpc
import sys
from decimal import *
import pprint
url="http://salfter:redacted@localhost:8844"
#url="http://salfter:redacted@localhost:8332"
b=jsonrpc.ServiceProxy(url)
pprint.pprint(b.getblocktemplate()["coinbasevalue"])
The first url definition points to my joulecoind instance. The second, commented-out definition points to my bitcoind instance. If you run it against bitcoind, you get the current coinbase value:
Run it against joulecoind, however, and you get this:
Traceback (most recent call last):
File "test.py", line 12, in <module>
pprint.pprint(b.getblocktemplate()["coinbasevalue"])
File "/usr/local/lib/python2.7/dist-packages/bitcoinrpc/authproxy.py", line 120, in __call__
response = self._get_response()
File "/usr/local/lib/python2.7/dist-packages/bitcoinrpc/authproxy.py", line 146, in _get_response
parse_float=decimal.Decimal)
File "/usr/lib/python2.7/json/__init__.py", line 351, in loads
return cls(encoding=encoding, **kw).decode(s)
File "/usr/lib/python2.7/json/decoder.py", line 366, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/lib/python2.7/json/decoder.py", line 384, in raw_decode
raise ValueError("No JSON object could be decoded")
ValueError: No JSON object could be decoded
Something is going seriously wrong here. I built joulecoind from GitHub source yesterday:
git clone https://github.com/joulecoin/joulecoin
cd joulecoin
./autogen.sh && ./configure --with-incompatible-bdb && make -j3 && sudo cp src/joulecoind /usr/local/bin
It's hard to reach any other conclusion than that there's a bug somewhere in the Joulecoin codebase, given that I have 25 other coins configured and running properly with the same code.