Skip to content

Commit

Permalink
Optional Rescan to importprivkey
Browse files Browse the repository at this point in the history
  • Loading branch information
ghostlander committed Aug 10, 2014
1 parent a5432f4 commit 1a8239e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/bitcoinrpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1241,6 +1241,7 @@ Array RPCConvertValues(const std::string &strMethod, const std::vector<std::stri
if (strMethod == "getnetworkhashps" && n > 0) ConvertTo<boost::int64_t>(params[0]);
if (strMethod == "getaddednodeinfo" && n > 0) ConvertTo<bool>(params[0]);
if (strMethod == "setstakegen" && n > 0) ConvertTo<bool>(params[0]);
if (strMethod == "importprivkey" && n > 2) ConvertTo<bool>(params[2]);

return params;
}
Expand Down
24 changes: 16 additions & 8 deletions src/rpcdump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,25 @@ class CTxDump
}
};

Value importprivkey(const Array& params, bool fHelp)
{
if (fHelp || params.size() < 1 || params.size() > 2)
throw runtime_error(
"importprivkey <orbitcoin_privkey> [label]\n"
"Adds a private key (as returned by dumpprivkey) to your wallet.");
Value importprivkey(const Array& params, bool fHelp) {

if(fHelp || (params.size() < 1) || (params.size() > 3))
throw(runtime_error(
"importprivkey <orbitcoin_privkey> [label] [rescan]\n"
"Adds a private key (as returned by dumpprivkey) to your wallet.\n"
"Block chain re-scanning is on (true) by default."));

EnsureWalletIsUnlocked();

string strSecret = params[0].get_str();
string strLabel = "";
if (params.size() > 1)
strLabel = params[1].get_str();

bool fRescan = true;
if(params.size() > 2)
fRescan = params[2].get_bool();

CBitcoinSecret vchSecret;
bool fGood = vchSecret.SetString(strSecret);

Expand All @@ -65,8 +71,10 @@ Value importprivkey(const Array& params, bool fHelp)
if (!pwalletMain->AddKey(key))
throw JSONRPCError(RPC_WALLET_ERROR, "Error adding key to wallet");

pwalletMain->ScanForWalletTransactions(pindexGenesisBlock, true);
pwalletMain->ReacceptWalletTransactions();
if(fRescan) {
pwalletMain->ScanForWalletTransactions(pindexGenesisBlock, true);
pwalletMain->ReacceptWalletTransactions();
}
}

return Value::null;
Expand Down

0 comments on commit 1a8239e

Please sign in to comment.