From: CryptoManiac Date: Sun, 3 Apr 2016 23:26:33 +0000 (+0300) Subject: Fix importprivkey issues. X-Git-Tag: nvc-v0.5.8~3 X-Git-Url: https://git.novaco.in/?p=novacoin.git;a=commitdiff_plain;h=7124035567b03ca15027318b75f3a398ae7b4d89 Fix importprivkey issues. 1) Handle parameters correctly; 2) Create label entry for a newly imported private key. --- diff --git a/src/bitcoinrpc.cpp b/src/bitcoinrpc.cpp index 60baac0..b32b86e 100644 --- a/src/bitcoinrpc.cpp +++ b/src/bitcoinrpc.cpp @@ -1256,6 +1256,7 @@ Array RPCConvertValues(const std::string &strMethod, const std::vector 0) ConvertTo(params[0]); if (strMethod == "keypoolreset" && n > 0) ConvertTo(params[0]); if (strMethod == "importaddress" && n > 2) ConvertTo(params[2]); + if (strMethod == "importprivkey" && n > 2) ConvertTo(params[2]); return params; } diff --git a/src/rpcdump.cpp b/src/rpcdump.cpp index bb877bf..756863c 100644 --- a/src/rpcdump.cpp +++ b/src/rpcdump.cpp @@ -67,23 +67,22 @@ Value importprivkey(const Array& params, bool fHelp) { LOCK2(cs_main, pwalletMain->cs_wallet); - pwalletMain->MarkDirty(); - pwalletMain->SetAddressBookName(addr, strLabel); - // Don't throw error in case a key is already there if (pwalletMain->HaveKey(keyid)) return Value::null; pwalletMain->mapKeyMetadata[addr].nCreateTime = 1; - if (!pwalletMain->AddKey(key)) throw JSONRPCError(RPC_WALLET_ERROR, "Error adding key to wallet"); - // whenever a key is imported, we need to scan the whole chain - pwalletMain->nTimeFirstKey = 1; // 0 would be considered 'no value' + pwalletMain->MarkDirty(); + pwalletMain->SetAddressBookName(addr, strLabel); - if (fRescan) + if (fRescan) { + // whenever a key is imported, we need to scan the whole chain + pwalletMain->nTimeFirstKey = 1; // 0 would be considered 'no value' + pwalletMain->ScanForWalletTransactions(pindexGenesisBlock, true); pwalletMain->ReacceptWalletTransactions(); }