mirror of
https://github.com/dashpay/dash.git
synced 2024-12-29 13:59:06 +01:00
58 lines
1.4 KiB
C++
58 lines
1.4 KiB
C++
// Copyright (c) 2014-2017 The Dash Core developers
|
|
// Distributed under the MIT/X11 software license, see the accompanying
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
#include "privatesend-util.h"
|
|
|
|
CKeyHolder::CKeyHolder(CWallet* pwallet) :
|
|
reserveKey(pwallet)
|
|
{
|
|
reserveKey.GetReservedKey(pubKey, false);
|
|
}
|
|
|
|
void CKeyHolder::KeepKey()
|
|
{
|
|
reserveKey.KeepKey();
|
|
}
|
|
|
|
void CKeyHolder::ReturnKey()
|
|
{
|
|
reserveKey.ReturnKey();
|
|
}
|
|
|
|
CScript CKeyHolder::GetScriptForDestination() const
|
|
{
|
|
return ::GetScriptForDestination(pubKey.GetID());
|
|
}
|
|
|
|
|
|
CScript CKeyHolderStorage::AddKey(CWallet* pwallet)
|
|
{
|
|
LOCK(cs_storage);
|
|
storage.emplace_back(std::unique_ptr<CKeyHolder>(new CKeyHolder(pwallet)));
|
|
LogPrintf("CKeyHolderStorage::%s -- storage size %lld\n", __func__, storage.size());
|
|
return storage.back()->GetScriptForDestination();
|
|
}
|
|
|
|
void CKeyHolderStorage::KeepAll(){
|
|
LOCK(cs_storage);
|
|
if (storage.size() > 0) {
|
|
for (auto &key : storage) {
|
|
key->KeepKey();
|
|
}
|
|
LogPrintf("CKeyHolderStorage::%s -- %lld keys kept\n", __func__, storage.size());
|
|
storage.clear();
|
|
}
|
|
}
|
|
|
|
void CKeyHolderStorage::ReturnAll()
|
|
{
|
|
LOCK(cs_storage);
|
|
if (storage.size() > 0) {
|
|
for (auto &key : storage) {
|
|
key->ReturnKey();
|
|
}
|
|
LogPrintf("CKeyHolderStorage::%s -- %lld keys returned\n", __func__, storage.size());
|
|
storage.clear();
|
|
}
|
|
}
|