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