Hi,
Sorry I made a mistake, I'm using a custom .23 with a little patch.
Without this patch and with the patch from everythings fine.
But I can't figure out whats wrong with this patch:
diff -up orig/rpc.cpp new/rpc.cpp
--- orig/rpc.cpp
+++ new/rpc.cpp
@@ -184,6 +184,149 @@
}
+Value BlockToValue(CBlock &block)
+{
+ Object obj;
+ obj.push_back(Pair("hash", block.GetHash().ToString().c_str()));
+ obj.push_back(Pair("version", block.nVersion));
+ obj.push_back(Pair("prev_block", block.hashPrevBlock.ToString().c_str()));
+ obj.push_back(Pair("mrkl_root", block.hashMerkleRoot.ToString().c_str()));
+ obj.push_back(Pair("time", (uint64_t)block.nTime));
+ obj.push_back(Pair("bits", (uint64_t)block.nBits));
+ obj.push_back(Pair("nonce", (uint64_t)block.nNonce));
+ obj.push_back(Pair("n_tx", (int)block.vtx.size()));
+ obj.push_back(Pair("size", (int)::GetSerializeSize(block, SER_NETWORK)));
+
+ Array tx;
+ for (int i = 0; i < block.vtx.size(); i++) {
+ Object txobj;
+
+ txobj.push_back(Pair("hash", block.vtx[i].GetHash().ToString().c_str()));
+ txobj.push_back(Pair("version", block.vtx[i].nVersion));
+ txobj.push_back(Pair("lock_time", (uint64_t)block.vtx[i].nLockTime));
+ txobj.push_back(Pair("size",
+ (int)::GetSerializeSize(block.vtx[i], SER_NETWORK)));
+
+ Array tx_vin;
+ for (int j = 0; j < block.vtx[i].vin.size(); j++) {
+ Object vino;
+
+ Object vino_outpt;
+
+ vino_outpt.push_back(Pair("hash",
+ block.vtx[i].vin[j].prevout.hash.ToString().c_str()));
+ vino_outpt.push_back(Pair("n", (uint64_t)block.vtx[i].vin[j].prevout.n));
+
+ vino.push_back(Pair("prev_out", vino_outpt));
+
+ if (block.vtx[i].vin[j].prevout.IsNull())
+ vino.push_back(Pair("coinbase", HexStr(
+ block.vtx[i].vin[j].scriptSig.begin(),
+ block.vtx[i].vin[j].scriptSig.end(), false).c_str()));
+ else
+ vino.push_back(Pair("scriptSig",
+ block.vtx[i].vin[j].scriptSig.ToString().c_str()));
+ if (block.vtx[i].vin[j].nSequence != UINT_MAX)
+ vino.push_back(Pair("sequence", (uint64_t)block.vtx[i].vin[j].nSequence));
+
+ tx_vin.push_back(vino);
+ }
+
+ Array tx_vout;
+ for (int j = 0; j < block.vtx[i].vout.size(); j++) {
+ Object vouto;
+
+ vouto.push_back(Pair("value",
+ (double)block.vtx[i].vout[j].nValue / (double)COIN));
+ vouto.push_back(Pair("scriptPubKey",
+ block.vtx[i].vout[j].scriptPubKey.ToString().c_str()));
+
+ tx_vout.push_back(vouto);
+ }
+
+ txobj.push_back(Pair("in", tx_vin));
+ txobj.push_back(Pair("out", tx_vout));
+
+ tx.push_back(txobj);
+ }
+
+ obj.push_back(Pair("tx", tx));
+
+ Array mrkl;
+ for (int i = 0; i < block.vMerkleTree.size(); i++)
+ mrkl.push_back(block.vMerkleTree[i].ToString().c_str());
+
+ obj.push_back(Pair("mrkl_tree", mrkl));
+
+ return obj;
+}
+
+
+Value getblockbycount(const Array& params, bool fHelp)
+{
+ if (fHelp || params.size() != 1)
+ throw runtime_error(
+ "getblockbycount height\n"
+ "Dumps the block existing at specified height");
+
+ int64 height = params[0].get_int64();
+ if (height > nBestHeight)
+ throw runtime_error(
+ "getblockbycount height\n"
+ "Dumps the block existing at specified height");
+
+ string blkname = strprintf("blk%d", height);
+
+ CBlockIndex* pindex;
+ bool found = false;
+
+ for (map::iterator mi = mapBlockIndex.begin();
+ mi != mapBlockIndex.end(); ++mi)
+ {
+ pindex = (*mi).second;
+ if ((pindex->nHeight == height) && (pindex->IsInMainChain())) {
+ found = true;
+ break;
+ }
+ }
+
+ if (!found)
+ throw runtime_error(
+ "getblockbycount height\n"
+ "Dumps the block existing at specified height");
+
+ CBlock block;
+ block.ReadFromDisk(pindex);
+ block.BuildMerkleTree();
+
+ return BlockToValue(block);
+}
+
+
+Value getblockbyhash(const Array& params, bool fHelp)
+{
+ if (fHelp || params.size() != 1)
+ throw runtime_error(
+ "getblockbyhash hash\n"
+ "Dumps the block with specified hash");
+
+ uint256 hash;
+ hash.SetHex(params[0].get_str());
+
+ map::iterator mi = mapBlockIndex.find(hash);
+ if (mi == mapBlockIndex.end())
+ throw JSONRPCError(-18, "hash not found");
+
+ CBlockIndex* pindex = (*mi).second;
+
+ CBlock block;
+ block.ReadFromDisk(pindex);
+ block.BuildMerkleTree();
+
+ return BlockToValue(block);
+}
+
+
Value getconnectioncount(const Array& params, bool fHelp)
{
if (fHelp || params.size() != 0)
@@ -1423,6 +1566,8 @@
{
make_pair("help", &help),
make_pair("stop", &stop),
+ make_pair("getblockbycount", &getblockbycount),
+ make_pair("getblockbyhash", &getblockbyhash),
make_pair("getblockcount", &getblockcount),
make_pair("getblocknumber", &getblocknumber),
make_pair("getconnectioncount", &getconnectioncount),
@@ -2113,6 +2258,7 @@
if (strMethod == "listtransactions" && n > 1) ConvertTo(params[1]);
if (strMethod == "listtransactions" && n > 2) ConvertTo(params[2]);
if (strMethod == "listaccounts" && n > 0) ConvertTo(params[0]);
+ if (strMethod == "getblockbycount" && n > 0) ConvertTo(params[0]);
if (strMethod == "sendmany" && n > 1)
{
string s = params[1].get_str();
regards, talpan