From 624c04b989287404fc6997cb7f67b9f620b3d4f1 Mon Sep 17 00:00:00 2001 From: Kittywhiskers Van Gogh <63189531+kittywhiskers@users.noreply.github.com> Date: Mon, 26 Jul 2021 09:02:26 +0530 Subject: [PATCH 1/7] move-only: move CKeyPool and CReserveKey to a dedicated file --- src/Makefile.am | 2 + src/wallet/keypool.cpp | 57 +++++++++++++++++ src/wallet/keypool.h | 85 +++++++++++++++++++++++++ src/wallet/wallet.cpp | 46 ------------- src/wallet/wallet.h | 71 +-------------------- src/wallet/walletdb.h | 2 +- test/lint/lint-circular-dependencies.sh | 2 + 7 files changed, 148 insertions(+), 117 deletions(-) create mode 100644 src/wallet/keypool.cpp create mode 100644 src/wallet/keypool.h diff --git a/src/Makefile.am b/src/Makefile.am index 400f6436d689..971da21ddc55 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -292,6 +292,7 @@ BITCOIN_CORE_H = \ wallet/crypter.h \ wallet/db.h \ wallet/fees.h \ + wallet/keypool.h \ wallet/psbtwallet.h \ wallet/rpcwallet.h \ wallet/wallet.h \ @@ -440,6 +441,7 @@ libdash_wallet_a_SOURCES = \ wallet/db.cpp \ wallet/fees.cpp \ wallet/init.cpp \ + wallet/keypool.cpp \ wallet/psbtwallet.cpp \ wallet/rpcdump.cpp \ wallet/rpcwallet.cpp \ diff --git a/src/wallet/keypool.cpp b/src/wallet/keypool.cpp new file mode 100644 index 000000000000..0f98b48c352a --- /dev/null +++ b/src/wallet/keypool.cpp @@ -0,0 +1,57 @@ +// Copyright (c) 2009-2010 Satoshi Nakamoto +// Copyright (c) 2009-2017 The Bitcoin Core developers +// Copyright (c) 2021 The Dash Core developers +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#include + +#include +#include + +CKeyPool::CKeyPool() +{ + nTime = GetTime(); + fInternal = false; +} + +CKeyPool::CKeyPool(const CPubKey& vchPubKeyIn, bool fInternalIn) +{ + nTime = GetTime(); + vchPubKey = vchPubKeyIn; + fInternal = fInternalIn; +} + +bool CReserveKey::GetReservedKey(CPubKey& pubkey, bool fInternalIn) +{ + if (nIndex == -1) + { + CKeyPool keypool; + if (!pwallet->ReserveKeyFromKeyPool(nIndex, keypool, fInternalIn)) { + return false; + } + vchPubKey = keypool.vchPubKey; + fInternal = keypool.fInternal; + } + assert(vchPubKey.IsValid()); + pubkey = vchPubKey; + return true; +} + +void CReserveKey::KeepKey() +{ + if (nIndex != -1) { + pwallet->KeepKey(nIndex); + } + nIndex = -1; + vchPubKey = CPubKey(); +} + +void CReserveKey::ReturnKey() +{ + if (nIndex != -1) { + pwallet->ReturnKey(nIndex, fInternal, vchPubKey); + } + nIndex = -1; + vchPubKey = CPubKey(); +} diff --git a/src/wallet/keypool.h b/src/wallet/keypool.h new file mode 100644 index 000000000000..0fba1001a203 --- /dev/null +++ b/src/wallet/keypool.h @@ -0,0 +1,85 @@ +// Copyright (c) 2009-2010 Satoshi Nakamoto +// Copyright (c) 2009-2017 The Bitcoin Core developers +// Copyright (c) 2021 The Dash Core developers +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#ifndef BITCOIN_WALLET_KEYPOOL_H +#define BITCOIN_WALLET_KEYPOOL_H + +#include +#include +#include