mirror of
https://github.com/dashpay/dash.git
synced 2024-12-26 12:32:48 +01:00
follow-up Merge #17260: Split some CWallet functions into new LegacyScriptPubKeyMan
Some changes are missing or incorrectly backported during CWallet refactoring in #17260, #17261 such as: - Missing changes for CWallet::GetOldestKeyPoolTime - useless check of spk_man existance in getnewaddress - GetHDChain is used assuming it exists only legacy keymanager - using internal spk_man API instead wallet's in getwalletinfo
This commit is contained in:
parent
fa23a64471
commit
6183bd1085
@ -258,10 +258,6 @@ UniValue getnewaddress(const JSONRPCRequest& request)
|
|||||||
if (!wallet) return NullUniValue;
|
if (!wallet) return NullUniValue;
|
||||||
CWallet* const pwallet = wallet.get();
|
CWallet* const pwallet = wallet.get();
|
||||||
|
|
||||||
LegacyScriptPubKeyMan* spk_man = pwallet->GetLegacyScriptPubKeyMan();
|
|
||||||
if (!spk_man) {
|
|
||||||
throw JSONRPCError(RPC_WALLET_ERROR, "This type of wallet does not support this command");
|
|
||||||
}
|
|
||||||
LOCK(pwallet->cs_wallet);
|
LOCK(pwallet->cs_wallet);
|
||||||
|
|
||||||
if (!pwallet->CanGetAddresses()) {
|
if (!pwallet->CanGetAddresses()) {
|
||||||
@ -2560,9 +2556,9 @@ static UniValue getwalletinfo(const JSONRPCRequest& request)
|
|||||||
if (spk_man) {
|
if (spk_man) {
|
||||||
obj.pushKV("timefirstkey", spk_man->GetTimeFirstKey());
|
obj.pushKV("timefirstkey", spk_man->GetTimeFirstKey());
|
||||||
obj.pushKV("keypoololdest", spk_man->GetOldestKeyPoolTime());
|
obj.pushKV("keypoololdest", spk_man->GetOldestKeyPoolTime());
|
||||||
obj.pushKV("keypoolsize", (int64_t)spk_man->KeypoolCountExternalKeys());
|
|
||||||
obj.pushKV("keypoolsize_hd_internal", (int64_t)(spk_man->KeypoolCountInternalKeys()));
|
|
||||||
}
|
}
|
||||||
|
obj.pushKV("keypoolsize", (int64_t)pwallet->KeypoolCountExternalKeys());
|
||||||
|
obj.pushKV("keypoolsize_hd_internal", (int64_t)(pwallet->KeypoolCountInternalKeys()));
|
||||||
obj.pushKV("keys_left", pwallet->nKeysLeftSinceAutoBackup);
|
obj.pushKV("keys_left", pwallet->nKeysLeftSinceAutoBackup);
|
||||||
if (pwallet->IsCrypted())
|
if (pwallet->IsCrypted())
|
||||||
obj.pushKV("unlocked_until", pwallet->nRelockTime);
|
obj.pushKV("unlocked_until", pwallet->nRelockTime);
|
||||||
|
@ -649,9 +649,11 @@ bool CWallet::EncryptWallet(const SecureString& strWalletPassphrase)
|
|||||||
// must get current HD chain before EncryptKeys
|
// must get current HD chain before EncryptKeys
|
||||||
CHDChain hdChainCurrent;
|
CHDChain hdChainCurrent;
|
||||||
|
|
||||||
// GetHDChain exist only at legacy.... how to validate it? just do static cast? we don't have any other type yet so may be ok temporary!
|
for (const auto& spk_man_pair : m_spk_managers) {
|
||||||
if (auto spk_man = GetLegacyScriptPubKeyMan()) {
|
auto spk_man = spk_man_pair.second.get();
|
||||||
spk_man->GetHDChain(hdChainCurrent);
|
LegacyScriptPubKeyMan *spk_man_legacy = dynamic_cast<LegacyScriptPubKeyMan*>(spk_man);
|
||||||
|
if (spk_man_legacy != nullptr) spk_man_legacy->GetHDChain(hdChainCurrent);
|
||||||
|
|
||||||
if (!spk_man->Encrypt(_vMasterKey, encrypted_batch)) {
|
if (!spk_man->Encrypt(_vMasterKey, encrypted_batch)) {
|
||||||
encrypted_batch->TxnAbort();
|
encrypted_batch->TxnAbort();
|
||||||
delete encrypted_batch;
|
delete encrypted_batch;
|
||||||
@ -661,10 +663,10 @@ bool CWallet::EncryptWallet(const SecureString& strWalletPassphrase)
|
|||||||
assert(false);
|
assert(false);
|
||||||
}
|
}
|
||||||
if (!hdChainCurrent.IsNull()) {
|
if (!hdChainCurrent.IsNull()) {
|
||||||
assert(spk_man->EncryptHDChain(_vMasterKey));
|
assert(spk_man_legacy->EncryptHDChain(_vMasterKey));
|
||||||
|
|
||||||
CHDChain hdChainCrypted;
|
CHDChain hdChainCrypted;
|
||||||
assert(spk_man->GetHDChain(hdChainCrypted));
|
assert(spk_man_legacy->GetHDChain(hdChainCrypted));
|
||||||
|
|
||||||
DBG(
|
DBG(
|
||||||
tfm::format(std::cout, "EncryptWallet -- current seed: '%s'\n", HexStr(hdChainCurrent.GetSeed()));
|
tfm::format(std::cout, "EncryptWallet -- current seed: '%s'\n", HexStr(hdChainCurrent.GetSeed()));
|
||||||
@ -675,7 +677,7 @@ bool CWallet::EncryptWallet(const SecureString& strWalletPassphrase)
|
|||||||
assert(hdChainCurrent.GetID() == hdChainCrypted.GetID());
|
assert(hdChainCurrent.GetID() == hdChainCrypted.GetID());
|
||||||
assert(hdChainCurrent.GetSeedHash() != hdChainCrypted.GetSeedHash());
|
assert(hdChainCurrent.GetSeedHash() != hdChainCrypted.GetSeedHash());
|
||||||
|
|
||||||
assert(spk_man->SetCryptedHDChain(*encrypted_batch, hdChainCrypted, false));
|
assert(spk_man_legacy->SetCryptedHDChain(*encrypted_batch, hdChainCrypted, false));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -4034,6 +4036,17 @@ bool CWallet::GetNewChangeDestination(CTxDestination& dest, std::string& error)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int64_t CWallet::GetOldestKeyPoolTime() const
|
||||||
|
{
|
||||||
|
LOCK(cs_wallet);
|
||||||
|
int64_t oldestKey = std::numeric_limits<int64_t>::max();
|
||||||
|
for (const auto& spk_man_pair : m_spk_managers) {
|
||||||
|
oldestKey = std::min(oldestKey, spk_man_pair.second->GetOldestKeyPoolTime());
|
||||||
|
}
|
||||||
|
|
||||||
|
return oldestKey;
|
||||||
|
}
|
||||||
|
|
||||||
void CWallet::MarkDestinationsDirty(const std::set<CTxDestination>& destinations) {
|
void CWallet::MarkDestinationsDirty(const std::set<CTxDestination>& destinations) {
|
||||||
for (auto& entry : mapWallet) {
|
for (auto& entry : mapWallet) {
|
||||||
CWalletTx& wtx = entry.second;
|
CWalletTx& wtx = entry.second;
|
||||||
|
Loading…
Reference in New Issue
Block a user