Permalink
Browse files

dumpwallet added to rpc commands

  • Loading branch information...
iamunick committed Jun 6, 2014
1 parent a71b94e commit b6a134395afb7c32f52a61e1fe29e6c91b5aec9f
Showing with 44 additions and 0 deletions.
  1. +2 −0 src/bitcoinrpc.cpp
  2. +2 −0 src/bitcoinrpc.h
  3. +2 −0 src/db.h
  4. +38 −0 src/rpcdump.cpp
View
@@ -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 },
View
@@ -137,8 +137,10 @@ 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 sendalert(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value importwallet(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value getgenerate(const json_spirit::Array& params, bool fHelp); // in rpcmining.cpp
extern json_spirit::Value setgenerate(const json_spirit::Array& params, bool fHelp);
View
@@ -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
View
@@ -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)
@@ -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 b6a1343

Please sign in to comment.