diff -uNr a/bitcoin/src/bitcoinrpc.cpp b/bitcoin/src/bitcoinrpc.cpp --- a/bitcoin/src/bitcoinrpc.cpp cfc24bce544ba71ed8e7e876a1074dc89da184c6aa7f0fc2ad8d0c213516b2b9539497d3176dd0a17ccb427d687ce8d3cc4d3b9969802c9da5f05a0617a2a30b +++ b/bitcoin/src/bitcoinrpc.cpp d5edc4c67519900497dc7f576070808e67519d2921981c63fc5c80d14dc2f8040544cd1c79ac202194dfa07fafd6245ebed5bab25b86cf5efb9e901659d0d8b5 @@ -1782,12 +1782,39 @@ } - - - - - - +Value dumpblock(const Array& params, bool fHelp) +{ + if (fHelp || params.size() < 1 || params.size() > 2) + throw runtime_error( + "dumpblock \n" + "Emit the block at to ."); + + int want_height = 0; + if (params.size() > 0) + want_height = params[0].get_int(); + + if (want_height > nBestHeight) + throw runtime_error("Requested block exceeds current nBestHeight!\n"); + + // path to dump block to + string filename = params[1].get_str(); + + // this is O(n^2)... + // possibly could be improved if we descend from best height if requested height is closer to it + for (map::iterator mi = mapBlockIndex.begin(); mi != mapBlockIndex.end(); ++mi) + { + CBlockIndex *pindex = (*mi).second; + if (pindex->nHeight == want_height) { + CBlock block; + block.ReadFromDisk(pindex); + printf("Dumping block %d to %s\n", want_height, filename.c_str()); + CAutoFile fileout = fopen(filename.c_str(), "wb+"); + fileout << block; + return true; + } + } + return false; +} @@ -1837,6 +1864,7 @@ make_pair("settxfee", &settxfee), make_pair("getmemorypool", &getmemorypool), make_pair("listsinceblock", &listsinceblock), + make_pair("dumpblock", &dumpblock), }; map mapCallTable(pCallTable, pCallTable + sizeof(pCallTable)/sizeof(pCallTable[0])); @@ -1863,6 +1891,7 @@ "validateaddress", "getwork", "getmemorypool", + "dumpblock", }; set setAllowInSafeMode(pAllowInSafeMode, pAllowInSafeMode + sizeof(pAllowInSafeMode)/sizeof(pAllowInSafeMode[0])); @@ -2364,6 +2393,7 @@ if (strMethod == "listaccounts" && n > 0) ConvertTo(params[0]); if (strMethod == "walletpassphrase" && n > 1) ConvertTo(params[1]); if (strMethod == "listsinceblock" && n > 1) ConvertTo(params[1]); + if (strMethod == "dumpblock" && n > 0) ConvertTo(params[0]); if (strMethod == "sendmany" && n > 1) { string s = params[1].get_str();