Skip to content

Commit

Permalink
Rebased the old dumpbootstrap branch.
Browse files Browse the repository at this point in the history
  • Loading branch information
dooglus committed Nov 21, 2014
1 parent 9bbcc9f commit 707f667
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 0 deletions.
39 changes: 39 additions & 0 deletions src/rpcblockchain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,45 @@ Value getbestblockhash(const Array& params, bool fHelp)
return hashBestChain.GetHex();
}

Value dumpbootstrap(const Array& params, bool fHelp)
{
if (fHelp || params.size() != 2)
throw runtime_error(
"dumpbootstrap \"destination\" \"blocks\"\n"
"\nCreates a bootstrap format block dump of the blockchain in destination, which can be a directory or a path with filename, up to the given block number.");

string strDest = params[0].get_str();
int nBlocks = params[1].get_int();
if (nBlocks < 0 || nBlocks > nBestHeight)
throw runtime_error("Block number out of range.");

boost::filesystem::path pathDest(strDest);
if (boost::filesystem::is_directory(pathDest))
pathDest /= "bootstrap.dat";

try {
FILE* file = fopen(pathDest.string().c_str(), "wb");
if (!file)
throw JSONRPCError(RPC_MISC_ERROR, "Error: Could not open bootstrap file for writing.");

CAutoFile fileout = CAutoFile(file, SER_DISK, CLIENT_VERSION);
if (!fileout)
throw JSONRPCError(RPC_MISC_ERROR, "Error: Could not open bootstrap file for writing.");

for (int nHeight = 0; nHeight <= nBlocks; nHeight++)
{
CBlock block;
CBlockIndex* pblockindex = FindBlockByHeight(nHeight);
block.ReadFromDisk(pblockindex, true);
fileout << FLATDATA(Params().MessageStart()) << fileout.GetSerializeSize(block) << block;
}
} catch(const boost::filesystem::filesystem_error &e) {
throw JSONRPCError(RPC_MISC_ERROR, "Error: Bootstrap dump failed!");
}

return Value::null;
}

Value getblockcount(const Array& params, bool fHelp)
{
if (fHelp || params.size() != 0)
Expand Down
1 change: 1 addition & 0 deletions src/rpcclient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ static const CRPCConvertParam vRPCConvertParams[] =
{ "signrawtransaction", 2 },
{ "keypoolrefill", 0 },
{ "importprivkey", 2 },
{ "dumpbootstrap", 1 },
};

class CRPCConvertTable
Expand Down
1 change: 1 addition & 0 deletions src/rpcserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ static const CRPCCommand vRPCCommands[] =
{ "validateaddress", &validateaddress, true, false, false },
{ "validatepubkey", &validatepubkey, true, false, false },
{ "verifymessage", &verifymessage, false, false, false },
{ "dumpbootstrap", &dumpbootstrap, false, false, false },

#ifdef ENABLE_WALLET
{ "getmininginfo", &getmininginfo, true, false, false },
Expand Down
1 change: 1 addition & 0 deletions src/rpcserver.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ extern json_spirit::Value listaddressgroupings(const json_spirit::Array& params,
extern json_spirit::Value listaccounts(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value listsinceblock(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value gettransaction(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value dumpbootstrap(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value backupwallet(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value keypoolrefill(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value walletpassphrase(const json_spirit::Array& params, bool fHelp);
Expand Down

0 comments on commit 707f667

Please sign in to comment.