1 // Copyright (c) 2009-2012 Bitcoin Developers
2 // Copyright (c) 2012-2013 The PPCoin developers
3 // Distributed under the MIT/X11 software license, see the accompanying
4 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
6 #include "init.h" // for pwalletMain
7 #include "bitcoinrpc.h"
8 #include "ui_interface.h"
10 #include <boost/lexical_cast.hpp>
12 #include "json/json_spirit_reader_template.h"
13 #include "json/json_spirit_writer_template.h"
14 #include "json/json_spirit_utils.h"
16 #define printf OutputDebugStringF
18 // using namespace boost::asio;
19 using namespace json_spirit;
22 extern Object JSONRPCError(int code, const string& message);
32 CTxDump(CWalletTx* ptx = NULL, int nOut = -1)
42 Value importprivkey(const Array& params, bool fHelp)
44 if (fHelp || params.size() < 1 || params.size() > 2)
46 "importprivkey <novacoinprivkey> [label]\n"
47 "Adds a private key (as returned by dumpprivkey) to your wallet.");
49 string strSecret = params[0].get_str();
51 if (params.size() > 1)
52 strLabel = params[1].get_str();
53 CBitcoinSecret vchSecret;
54 bool fGood = vchSecret.SetString(strSecret);
56 if (!fGood) throw JSONRPCError(-5,"Invalid private key");
57 if (fWalletUnlockMintOnly) // ppcoin: no importprivkey in mint-only mode
58 throw JSONRPCError(-102, "Wallet is unlocked for minting only.");
62 CSecret secret = vchSecret.GetSecret(fCompressed);
63 key.SetSecret(secret, fCompressed);
64 CBitcoinAddress vchAddress = CBitcoinAddress(key.GetPubKey());
67 LOCK2(cs_main, pwalletMain->cs_wallet);
69 pwalletMain->MarkDirty();
70 pwalletMain->SetAddressBookName(vchAddress, strLabel);
72 if (!pwalletMain->AddKey(key))
73 throw JSONRPCError(-4,"Error adding key to wallet");
75 pwalletMain->ScanForWalletTransactions(pindexGenesisBlock, true);
76 pwalletMain->ReacceptWalletTransactions();
84 Value dumpprivkey(const Array& params, bool fHelp)
86 if (fHelp || params.size() != 1)
88 "dumpprivkey <novacoinaddress>\n"
89 "Reveals the private key corresponding to <novacoinaddress>.");
91 string strAddress = params[0].get_str();
92 CBitcoinAddress address;
93 if (!address.SetString(strAddress))
94 throw JSONRPCError(-5, "Invalid novacoin address");
95 if (fWalletUnlockMintOnly) // ppcoin: no dumpprivkey in mint-only mode
96 throw JSONRPCError(-102, "Wallet is unlocked for minting only.");
99 if (!pwalletMain->GetSecret(address, vchSecret, fCompressed))
100 throw JSONRPCError(-4,"Private key for address " + strAddress + " is not known");
101 return CBitcoinSecret(vchSecret, fCompressed).ToString();