aboutsummaryrefslogtreecommitdiff
path: root/src/rpcdump.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/rpcdump.cpp')
-rw-r--r--src/rpcdump.cpp28
1 files changed, 18 insertions, 10 deletions
diff --git a/src/rpcdump.cpp b/src/rpcdump.cpp
index 30e504a095..77cef02736 100644
--- a/src/rpcdump.cpp
+++ b/src/rpcdump.cpp
@@ -34,19 +34,25 @@ public:
Value importprivkey(const Array& params, bool fHelp)
{
- if (fHelp || params.size() < 1 || params.size() > 2)
+ if (fHelp || params.size() < 1 || params.size() > 3)
throw runtime_error(
- "importprivkey <bitcoinprivkey> [label]\n"
+ "importprivkey <bitcoinprivkey> [label] [rescan=true]\n"
"Adds a private key (as returned by dumpprivkey) to your wallet.");
string strSecret = params[0].get_str();
string strLabel = "";
if (params.size() > 1)
strLabel = params[1].get_str();
+
+ // Whether to perform rescan after import
+ bool fRescan = true;
+ if (params.size() > 2)
+ fRescan = params[2].get_bool();
+
CBitcoinSecret vchSecret;
bool fGood = vchSecret.SetString(strSecret);
- if (!fGood) throw JSONRPCError(-5,"Invalid private key");
+ if (!fGood) throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid private key");
CKey key;
bool fCompressed;
@@ -60,10 +66,12 @@ Value importprivkey(const Array& params, bool fHelp)
pwalletMain->SetAddressBookName(vchAddress, strLabel);
if (!pwalletMain->AddKey(key))
- throw JSONRPCError(-4,"Error adding key to wallet");
-
- pwalletMain->ScanForWalletTransactions(pindexGenesisBlock, true);
- pwalletMain->ReacceptWalletTransactions();
+ throw JSONRPCError(RPC_WALLET_ERROR, "Error adding key to wallet");
+
+ if (fRescan) {
+ pwalletMain->ScanForWalletTransactions(pindexGenesisBlock, true);
+ pwalletMain->ReacceptWalletTransactions();
+ }
}
return Value::null;
@@ -79,13 +87,13 @@ Value dumpprivkey(const Array& params, bool fHelp)
string strAddress = params[0].get_str();
CBitcoinAddress address;
if (!address.SetString(strAddress))
- throw JSONRPCError(-5, "Invalid Bitcoin address");
+ throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Bitcoin address");
CKeyID keyID;
if (!address.GetKeyID(keyID))
- throw JSONRPCError(-3, "Address does not refer to a key");
+ throw JSONRPCError(RPC_TYPE_ERROR, "Address does not refer to a key");
CSecret vchSecret;
bool fCompressed;
if (!pwalletMain->GetSecret(keyID, vchSecret, fCompressed))
- throw JSONRPCError(-4,"Private key for address " + strAddress + " is not known");
+ throw JSONRPCError(RPC_WALLET_ERROR, "Private key for address " + strAddress + " is not known");
return CBitcoinSecret(vchSecret, fCompressed).ToString();
}