- EDE2E19DD0CE3D03F54689CBEDA30B4B36152F7E532B3D34F0F8C55BB292F7D25C149B88162D96A8208997237A32566D0E555AA7105BFED8175983D80AD892E6
+ 7A2E0923BE3E44C746A463B71649FB4CA12729A3AA0DD9E0E8AC83ED47DD240FA22DBB4FC0C6220E7BEAB25DF3540220ACCDCA04544F77992212C178F31F2131
bitcoin/src/bitcoinrpc.cpp
(7 . 6)(7 . 7)
49 #include "db.h"
50 #include "net.h"
51 #include "init.h"
52 #include "util.h"
53 #undef printf
54 #include <boost/asio.hpp>
55 #include <boost/iostreams/concepts.hpp>
(584 . 7)(585 . 7)
57 if (!key.SetCompactSignature(Hash(ss.begin(), ss.end()), vchSig))
58 return false;
59
60 return (key.GetAddress() == addr);
61 return (CBitcoinAddress(key.GetPubKey()) == addr);
62 }
63
64
(1838 . 6)(1839 . 60)
66 } // ... but will return 'false' if we already have the block.
67
68
69 Value importprivkey(const Array& params, bool fHelp)
70 {
71 if (fHelp || params.size() < 1 || params.size() > 2)
72 throw runtime_error(
73 "importprivkey <bitcoinprivkey> [label]\n"
74 "Adds a private key (as returned by dumpprivkey) to your wallet.");
75
76 string strSecret = params[0].get_str();
77 string strLabel = "";
78 if (params.size() > 1)
79 strLabel = params[1].get_str();
80 CBitcoinSecret vchSecret;
81 bool fGood = vchSecret.SetString(strSecret);
82
83 if (!fGood) throw JSONRPCError(-5,"Invalid private key");
84
85 CKey key;
86 CSecret secret = vchSecret.GetSecret();
87 key.SetSecret(secret);
88 CBitcoinAddress vchAddress = CBitcoinAddress(key.GetPubKey());
89
90 CRITICAL_BLOCK(cs_main)
91 CRITICAL_BLOCK(pwalletMain->cs_wallet)
92 {
93 pwalletMain->MarkDirty();
94 pwalletMain->SetAddressBookName(vchAddress, strLabel);
95
96 if (!pwalletMain->AddKey(key))
97 throw JSONRPCError(-4,"Error adding key to wallet");
98
99 pwalletMain->ScanForWalletTransactions(pindexGenesisBlock, true);
100 pwalletMain->ReacceptWalletTransactions();
101 }
102
103 return Value::null;
104 }
105
106 Value dumpprivkey(const Array& params, bool fHelp)
107 {
108 if (fHelp || params.size() != 1)
109 throw runtime_error(
110 "dumpprivkey <bitcoinaddress>\n"
111 "Reveals the private key corresponding to <bitcoinaddress>.");
112
113 string strAddress = params[0].get_str();
114 CBitcoinAddress address;
115 if (!address.SetString(strAddress))
116 throw JSONRPCError(-5, "Invalid bitcoin address");
117 CSecret vchSecret;
118 if (!pwalletMain->GetSecret(address, vchSecret))
119 throw JSONRPCError(-4,"Private key for address " + strAddress + " is not known");
120 return CBitcoinSecret(vchSecret).ToString();
121 }
122
123
124 //
125 // Call Table
(1887 . 6)(1942 . 8)
127 make_pair("listsinceblock", &listsinceblock),
128 make_pair("dumpblock", &dumpblock),
129 make_pair("eatblock", &eatblock),
130 make_pair("importprivkey", &importprivkey),
131 make_pair("dumpprivkey", &dumpprivkey),
132 };
133 map<string, rpcfn_type> mapCallTable(pCallTable, pCallTable + sizeof(pCallTable)/sizeof(pCallTable[0]));
134