1 // Copyright (c) 2009-2012 Bitcoin Developers
2 // Copyright (c) 2012 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 <ppcoinprivkey> [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");
60 CSecret secret = vchSecret.GetSecret(fCompressed);
61 key.SetSecret(secret, fCompressed);
62 CBitcoinAddress vchAddress = CBitcoinAddress(key.GetPubKey());
65 LOCK2(cs_main, pwalletMain->cs_wallet);
67 pwalletMain->MarkDirty();
68 pwalletMain->SetAddressBookName(vchAddress, strLabel);
70 if (!pwalletMain->AddKey(key))
71 throw JSONRPCError(-4,"Error adding key to wallet");
73 pwalletMain->ScanForWalletTransactions(pindexGenesisBlock, true);
74 pwalletMain->ReacceptWalletTransactions();
82 Value dumpprivkey(const Array& params, bool fHelp)
84 if (fHelp || params.size() != 1)
86 "dumpprivkey <ppcoinaddress>\n"
87 "Reveals the private key corresponding to <ppcoinaddress>.");
89 string strAddress = params[0].get_str();
90 CBitcoinAddress address;
91 if (!address.SetString(strAddress))
92 throw JSONRPCError(-5, "Invalid ppcoin address");
95 if (!pwalletMain->GetSecret(address, vchSecret, fCompressed))
96 throw JSONRPCError(-4,"Private key for address " + strAddress + " is not known");
97 return CBitcoinSecret(vchSecret, fCompressed).ToString();