text: // Copyright (c) 2014-2019 The Dash Core developers
  // Copyright (c) 2017-2019 The OmegaCoin 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();
      }
  }
  