Create wallet security menu
[novacoin.git] / src / rpcdump.cpp
index e287742..1e31e73 100644 (file)
@@ -7,13 +7,13 @@
 #include "ui_interface.h"
 #include "base58.h"
 
-#include <boost/lexical_cast.hpp>
-
 #define printf OutputDebugStringF
 
 using namespace json_spirit;
 using namespace std;
 
+void EnsureWalletIsUnlocked();
+
 class CTxDump
 {
 public:
@@ -71,6 +71,22 @@ 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(!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)
@@ -78,6 +94,8 @@ Value dumpprivkey(const Array& params, bool fHelp)
             "dumpprivkey <novacoinaddress>\n"
             "Reveals the private key corresponding to <novacoinaddress>.");
 
+    EnsureWalletIsUnlocked();
+
     string strAddress = params[0].get_str();
     CBitcoinAddress address;
     if (!address.SetString(strAddress))
@@ -93,3 +111,19 @@ 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(!DumpWallet(pwalletMain, params[0].get_str().c_str() ))
+      throw JSONRPCError(RPC_WALLET_ERROR, "Error dumping wallet keys to file");
+
+    return Value::null;
+}