Skip to content

Commit

Permalink
dumpwallet added to rpc commands
Browse files Browse the repository at this point in the history
  • Loading branch information
Tranz5 committed May 21, 2014
1 parent 8701510 commit 4b49049
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/bitcoinrpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,9 @@ static const CRPCCommand vRPCCommands[] =
{ "submitblock", &submitblock, false, false },
{ "listsinceblock", &listsinceblock, false, false },
{ "dumpprivkey", &dumpprivkey, false, false },
{ "dumpwallet", &dumpwallet, true, false },
{ "importprivkey", &importprivkey, false, false },
{ "importwallet", &importwallet, false, false },
{ "listunspent", &listunspent, false, false },
{ "getrawtransaction", &getrawtransaction, false, false },
{ "createrawtransaction", &createrawtransaction, false, false },
Expand Down
2 changes: 2 additions & 0 deletions src/bitcoinrpc.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,9 @@ extern json_spirit::Value getpeerinfo(const json_spirit::Array& params, bool fHe
extern json_spirit::Value addnode(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value getaddednodeinfo(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value dumpprivkey(const json_spirit::Array& params, bool fHelp); // in rpcdump.cpp
extern json_spirit::Value dumpwallet(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value importprivkey(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value importwallet(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value sendalert(const json_spirit::Array& params, bool fHelp);

extern json_spirit::Value getgenerate(const json_spirit::Array& params, bool fHelp); // in rpcmining.cpp
Expand Down
2 changes: 2 additions & 0 deletions src/db.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ extern unsigned int nWalletDBUpdated;

void ThreadFlushWalletDB(void* parg);
bool BackupWallet(const CWallet& wallet, const std::string& strDest);
bool DumpWallet(CWallet* pwallet, const std::string& strDest);
bool ImportWallet(CWallet* pwallet, const std::string& strLocation);


class CDBEnv
Expand Down
38 changes: 38 additions & 0 deletions src/rpcdump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,25 @@ Value importprivkey(const Array& params, bool fHelp)
return Value::null;
}

Value importwallet(const Array& params, bool fHelp)
{
if (fHelp || params.size() != 1)
throw runtime_error(
"importwallet <filename>\n"
"Imports keys from a wallet dump file (see dumpwallet)."
+ HelpRequiringPassphrase());

EnsureWalletIsUnlocked();

if (fWalletUnlockMintOnly) // no importwallet in mint-only mode
throw JSONRPCError(RPC_WALLET_UNLOCK_NEEDED, "Wallet is unlocked for minting only.");

if(!ImportWallet(pwalletMain,params[0].get_str().c_str()))
throw JSONRPCError(RPC_WALLET_ERROR, "Error adding some keys to wallet");

return Value::null;
}

Value dumpprivkey(const Array& params, bool fHelp)
{
if (fHelp || params.size() != 1)
Expand All @@ -93,3 +112,22 @@ Value dumpprivkey(const Array& params, bool fHelp)
throw JSONRPCError(RPC_WALLET_ERROR, "Private key for address " + strAddress + " is not known");
return CBitcoinSecret(vchSecret, fCompressed).ToString();
}

Value dumpwallet(const Array& params, bool fHelp)
{
if (fHelp || params.size() != 1)
throw runtime_error(
"dumpwallet <filename>\n"
"Dumps all wallet keys in a human-readable format."
+ HelpRequiringPassphrase());

EnsureWalletIsUnlocked();

if (fWalletUnlockMintOnly) // no dumpwallet in mint-only mode
throw JSONRPCError(RPC_WALLET_UNLOCK_NEEDED, "Wallet is unlocked for minting only.");

if(!DumpWallet(pwalletMain, params[0].get_str().c_str() ))
throw JSONRPCError(RPC_WALLET_ERROR, "Error dumping wallet keys to file");

return Value::null;
}

0 comments on commit 4b49049

Please sign in to comment.