Add height param to importprivkey
This commit is contained in:
@@ -108,6 +108,7 @@ static const CRPCConvertParam vRPCConvertParams[] =
|
||||
{ "lockunspent", 0 },
|
||||
{ "lockunspent", 1 },
|
||||
{ "importprivkey", 2 },
|
||||
{ "importprivkey", 3 },
|
||||
{ "importaddress", 2 },
|
||||
{ "verifychain", 0 },
|
||||
{ "verifychain", 1 },
|
||||
|
||||
@@ -94,14 +94,15 @@ UniValue importprivkey(const UniValue& params, bool fHelp)
|
||||
if (!EnsureWalletIsAvailable(fHelp))
|
||||
return NullUniValue;
|
||||
|
||||
if (fHelp || params.size() < 1 || params.size() > 3)
|
||||
if (fHelp || params.size() < 1 || params.size() > 4)
|
||||
throw runtime_error(
|
||||
"importprivkey \"komodoprivkey\" ( \"label\" rescan )\n"
|
||||
"importprivkey \"komodoprivkey\" ( \"label\" rescan height)\n"
|
||||
"\nAdds a private key (as returned by dumpprivkey) to your wallet.\n"
|
||||
"\nArguments:\n"
|
||||
"1. \"komodoprivkey\" (string, required) The private key (see dumpprivkey)\n"
|
||||
"2. \"label\" (string, optional, default=\"\") An optional label\n"
|
||||
"3. rescan (boolean, optional, default=true) Rescan the wallet for transactions\n"
|
||||
"4. height (integer, optional, default=0) start at block height?\n"
|
||||
"\nNote: This call can take minutes to complete if rescan is true.\n"
|
||||
"\nExamples:\n"
|
||||
"\nDump a private key\n"
|
||||
@@ -111,7 +112,11 @@ UniValue importprivkey(const UniValue& params, bool fHelp)
|
||||
"\nImport using a label and without rescan\n"
|
||||
+ HelpExampleCli("importprivkey", "\"mykey\" \"testing\" false") +
|
||||
"\nAs a JSON-RPC call\n"
|
||||
+ HelpExampleRpc("importprivkey", "\"mykey\", \"testing\", false")
|
||||
+ HelpExampleRpc("importprivkey", "\"mykey\", \"testing\", false") +
|
||||
"\nImport with rescan from a block height\n"
|
||||
+ HelpExampleCli("importprivkey", "\"mykey\" \"testing\" true 1000") +
|
||||
"\nAs a JSON-RPC call\n"
|
||||
+ HelpExampleRpc("importprivkey", "\"mykey\", \"testing\", true, 1000")
|
||||
);
|
||||
|
||||
LOCK2(cs_main, pwalletMain->cs_wallet);
|
||||
@@ -120,6 +125,7 @@ UniValue importprivkey(const UniValue& params, bool fHelp)
|
||||
|
||||
string strSecret = params[0].get_str();
|
||||
string strLabel = "";
|
||||
int32_t height = 0;
|
||||
if (params.size() > 1)
|
||||
strLabel = params[1].get_str();
|
||||
|
||||
@@ -127,7 +133,12 @@ UniValue importprivkey(const UniValue& params, bool fHelp)
|
||||
bool fRescan = true;
|
||||
if (params.size() > 2)
|
||||
fRescan = params[2].get_bool();
|
||||
if ( fRescan && params.size() == 4 )
|
||||
height = params[3].get_int();
|
||||
|
||||
if ( height < 0 || height > chainActive.Height() )
|
||||
throw JSONRPCError(RPC_WALLET_ERROR, "Rescan height is out of range.");
|
||||
|
||||
CKey key = DecodeSecret(strSecret);
|
||||
if (!key.IsValid()) throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid private key encoding");
|
||||
|
||||
@@ -152,7 +163,7 @@ UniValue importprivkey(const UniValue& params, bool fHelp)
|
||||
pwalletMain->nTimeFirstKey = 1; // 0 would be considered 'no value'
|
||||
|
||||
if (fRescan) {
|
||||
pwalletMain->ScanForWalletTransactions(chainActive.Genesis(), true);
|
||||
pwalletMain->ScanForWalletTransactions(chainActive[height], true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user