--- a/trb ea3bff957a593cf36b6458aa69a2bb0bc89f2e73474f5bbf35ffe4ee57098ab03fbe74a238e4b342d30ad4ac6b1cfe736cecc1af21c3d278d1d37d5c01379742 +++ b/trb 3b4af11b93f21d72b536f19b65fd8b7913a2c5da0f7c0c3bdc271de9a61c2e46cf7d6eb1c7be75dc501ca38469e6c44efb0bba08157e4dda2abcc7fdb3477a3d @@ -6998,7 +6998,7 @@ #endif // __INCLUDED_PROTOCOL_H__ ############################################################################## -82826 @ ./bitcoin/src/bitcoinrpc.cpp +84080 @ ./bitcoin/src/bitcoinrpc.cpp ############################################################################## // Copyright (c) 2010 Satoshi Nakamoto // Copyright (c) 2009-2012 The Bitcoin developers @@ -8784,12 +8784,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; +} @@ -8839,6 +8866,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])); @@ -8865,6 +8893,7 @@ "validateaddress", "getwork", "getmemorypool", + "dumpblock", }; set setAllowInSafeMode(pAllowInSafeMode, pAllowInSafeMode + sizeof(pAllowInSafeMode)/sizeof(pAllowInSafeMode[0])); @@ -9366,6 +9395,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();