From e23488a379ace5a9a2a63ecf6b1c3ccfb6af833b Mon Sep 17 00:00:00 2001 From: svost Date: Fri, 11 Feb 2022 16:30:42 +0300 Subject: [PATCH] Includes cleanup --- src/bignum.h | 1 + src/bitcoinrpc.cpp | 1 + src/init.cpp | 1 + src/init.h | 4 +- src/main.cpp | 29 +------- src/net.cpp | 1 + src/protocol.h | 7 +-- src/qt/bitcoin.cpp | 1 + src/qt/coincontroldialog.cpp | 1 + src/qt/optionsmodel.cpp | 1 + src/rpcdump.cpp | 3 +- src/rpcmining.cpp | 2 +- src/serialize.h | 2 - src/txdb-leveldb.h | 5 +- src/wallet.cpp | 167 ++++++++++++++++++++++++++++++++++++++++++ src/wallet.h | 141 ++++------------------------------- 16 files changed, 200 insertions(+), 167 deletions(-) diff --git a/src/bignum.h b/src/bignum.h index 8c6b588..418f343 100644 --- a/src/bignum.h +++ b/src/bignum.h @@ -8,6 +8,7 @@ #include "serialize.h" #include "uint256.h" +#include "version.h" #include diff --git a/src/bitcoinrpc.cpp b/src/bitcoinrpc.cpp index 4bda0c9..dafacef 100644 --- a/src/bitcoinrpc.cpp +++ b/src/bitcoinrpc.cpp @@ -10,6 +10,7 @@ #include "interface.h" #include "sync.h" #include "util.h" +#include "wallet.h" #undef printf diff --git a/src/init.cpp b/src/init.cpp index 84749d3..9d42a55 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -11,6 +11,7 @@ #include "ipcollector.h" #include "interface.h" #include "checkpoints.h" +#include "wallet.h" #include #include diff --git a/src/init.h b/src/init.h index 84f2712..e2f3d25 100644 --- a/src/init.h +++ b/src/init.h @@ -5,7 +5,9 @@ #ifndef BITCOIN_INIT_H #define BITCOIN_INIT_H -#include "wallet.h" +#include + +class CWallet; extern CWallet* pwalletMain; extern std::string strWalletFileName; diff --git a/src/main.cpp b/src/main.cpp index 8cf70d1..805c043 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -12,6 +12,7 @@ #include "interface.h" #include "checkqueue.h" #include "kernel.h" +#include "wallet.h" #include #include @@ -862,34 +863,6 @@ bool CMerkleTx::AcceptToMemoryPool() return AcceptToMemoryPool(txdb); } - - -bool CWalletTx::AcceptWalletTransaction(CTxDB& txdb, bool fCheckInputs) -{ - - { - LOCK(mempool.cs); - // Add previous supporting transactions first - for (CMerkleTx& tx : vtxPrev) - { - if (!(tx.IsCoinBase() || tx.IsCoinStake())) - { - uint256 hash = tx.GetHash(); - if (!mempool.exists(hash) && !txdb.ContainsTx(hash)) - tx.AcceptToMemoryPool(txdb, fCheckInputs); - } - } - return AcceptToMemoryPool(txdb, fCheckInputs); - } - return false; -} - -bool CWalletTx::AcceptWalletTransaction() -{ - CTxDB txdb("r"); - return AcceptWalletTransaction(txdb); -} - int CTxIndex::GetDepthInMainChain() const { // Read block header diff --git a/src/net.cpp b/src/net.cpp index 00bf067..28f40b8 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -9,6 +9,7 @@ #include "init.h" #include "addrman.h" #include "interface.h" +#include "main.h" #include "miner.h" #include "ntp.h" diff --git a/src/protocol.h b/src/protocol.h index fcc8c9e..675c0d8 100644 --- a/src/protocol.h +++ b/src/protocol.h @@ -3,18 +3,13 @@ // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#ifndef __cplusplus -# error This header can only be compiled as C++. -#endif - #ifndef __INCLUDED_PROTOCOL_H__ #define __INCLUDED_PROTOCOL_H__ #include "serialize.h" #include "netbase.h" -#include -#include #include "uint256.h" +#include "version.h" extern bool fTestNet; inline unsigned short GetDefaultPort() diff --git a/src/qt/bitcoin.cpp b/src/qt/bitcoin.cpp index 4c9af3a..f856c39 100644 --- a/src/qt/bitcoin.cpp +++ b/src/qt/bitcoin.cpp @@ -9,6 +9,7 @@ #include "guiconstants.h" #include "init.h" +#include "main.h" #include "interface.h" #include "qtipcserver.h" #include "intro.h" diff --git a/src/qt/coincontroldialog.cpp b/src/qt/coincontroldialog.cpp index e288f1f..25b2d6e 100644 --- a/src/qt/coincontroldialog.cpp +++ b/src/qt/coincontroldialog.cpp @@ -10,6 +10,7 @@ #include "optionsmodel.h" #include "coincontrol.h" #include "dialogwindowflags.h" +#include "wallet.h" #include #include diff --git a/src/qt/optionsmodel.cpp b/src/qt/optionsmodel.cpp index 59553c3..386a2cd 100644 --- a/src/qt/optionsmodel.cpp +++ b/src/qt/optionsmodel.cpp @@ -5,6 +5,7 @@ #include "init.h" #include "walletdb.h" #include "guiutil.h" +#include "wallet.h" OptionsModel::OptionsModel(QObject *parent) : QAbstractListModel(parent) diff --git a/src/rpcdump.cpp b/src/rpcdump.cpp index 44615a1..1bdc3cc 100644 --- a/src/rpcdump.cpp +++ b/src/rpcdump.cpp @@ -2,10 +2,11 @@ // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#include "init.h" // for pwalletMain +#include "init.h" #include "bitcoinrpc.h" #include "interface.h" #include "base58.h" +#include "wallet.h" #define printf OutputDebugStringF diff --git a/src/rpcmining.cpp b/src/rpcmining.cpp index 18c3134..c00c356 100644 --- a/src/rpcmining.cpp +++ b/src/rpcmining.cpp @@ -3,13 +3,13 @@ // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#include "main.h" #include "db.h" #include "txdb-leveldb.h" #include "init.h" #include "miner.h" #include "kernel.h" #include "bitcoinrpc.h" +#include "wallet.h" using namespace json_spirit; using namespace std; diff --git a/src/serialize.h b/src/serialize.h index f24fd5c..e9b6120 100644 --- a/src/serialize.h +++ b/src/serialize.h @@ -5,8 +5,6 @@ #ifndef BITCOIN_SERIALIZE_H #define BITCOIN_SERIALIZE_H -#include "version.h" - #include #include #include diff --git a/src/txdb-leveldb.h b/src/txdb-leveldb.h index 50b390b..ef8b1fd 100644 --- a/src/txdb-leveldb.h +++ b/src/txdb-leveldb.h @@ -8,10 +8,7 @@ #include "serialize.h" #include "streams.h" - -#include -#include -#include +#include "version.h" #include #include diff --git a/src/wallet.cpp b/src/wallet.cpp index 1b4025d..3ed6c9e 100644 --- a/src/wallet.cpp +++ b/src/wallet.cpp @@ -1374,6 +1374,32 @@ void CWalletTx::AddSupportingTransactions(CTxDB& txdb) reverse(vtxPrev.begin(), vtxPrev.end()); } +bool CWalletTx::AcceptWalletTransaction(CTxDB& txdb, bool fCheckInputs) +{ + + { + LOCK(mempool.cs); + // Add previous supporting transactions first + for (CMerkleTx& tx : vtxPrev) + { + if (!(tx.IsCoinBase() || tx.IsCoinStake())) + { + uint256 hash = tx.GetHash(); + if (!mempool.exists(hash) && !txdb.ContainsTx(hash)) + tx.AcceptToMemoryPool(txdb, fCheckInputs); + } + } + return AcceptToMemoryPool(txdb, fCheckInputs); + } + return false; +} + +bool CWalletTx::AcceptWalletTransaction() +{ + CTxDB txdb("r"); + return AcceptWalletTransaction(txdb); +} + bool CWalletTx::WriteToDisk() { return CWalletDB(pwallet->strWalletFile).WriteTx(GetHash(), *this); @@ -1939,6 +1965,35 @@ bool CWallet::SelectCoins(int64_t nTargetValue, unsigned int nSpendTime, set >& setCoinsRet, int64_t& nValueRet) const { @@ -2628,6 +2683,21 @@ void CWallet::PrintWallet(const CBlock& block) printf("\n"); } +void CWallet::Inventory(const uint256 &hash) +{ + { + LOCK(cs_wallet); + std::map::iterator mi = mapRequestCount.find(hash); + if (mi != mapRequestCount.end()) + (*mi).second++; + } +} + +unsigned int CWallet::GetKeyPoolSize() +{ + return (unsigned int)(setKeyPool.size()); +} + bool CWallet::GetTransaction(const uint256 &hashTx, CWalletTx& wtx) { { @@ -3066,6 +3136,18 @@ void CReserveKey::KeepKey() vchPubKey = CPubKey(); } +CReserveKey::CReserveKey(CWallet *pwalletIn) +{ + nIndex = -1; + pwallet = pwalletIn; +} + +CReserveKey::~CReserveKey() +{ + if (!fShutdown) + ReturnKey(); +} + void CReserveKey::ReturnKey() { if (nIndex != -1) @@ -3164,3 +3246,88 @@ void CWallet::ClearOrphans() EraseFromWallet(*it); } + +void CWalletTx::Init(const CWallet *pwalletIn) +{ + pwallet = pwalletIn; + vtxPrev.clear(); + mapValue.clear(); + vOrderForm.clear(); + fTimeReceivedIsTxTime = false; + nTimeReceived = 0; + nTimeSmart = 0; + fFromMe = false; + strFromAccount.clear(); + vfSpent.clear(); + fDebitCached = false; + fWatchDebitCached = false; + fCreditCached = false; + fWatchCreditCached = false; + fAvailableCreditCached = false; + fAvailableWatchCreditCached = false; + fImmatureCreditCached = false; + fImmatureWatchCreditCached = false; + fChangeCached = false; + nDebitCached = 0; + nWatchDebitCached = 0; + nCreditCached = 0; + nWatchCreditCached = 0; + nAvailableCreditCached = 0; + nAvailableWatchCreditCached = 0; + nImmatureCreditCached = 0; + nImmatureWatchCreditCached = 0; + nChangeCached = 0; + nOrderPos = -1; +} + +COutput::COutput(const CWalletTx *txIn, int iIn, int nDepthIn, bool fSpendableIn) +{ + tx = txIn; i = iIn; nDepth = nDepthIn; fSpendable = fSpendableIn; +} + +string COutput::ToString() const +{ + return strprintf("COutput(%s, %d, %d, %d) [%s]", tx->GetHash().ToString().substr(0,10).c_str(), i, fSpendable, nDepth, FormatMoney(tx->vout[i].nValue).c_str()); +} + +CAccount::CAccount() +{ + SetNull(); +} + +void CAccount::SetNull() +{ + vchPubKey = CPubKey(); +} + +CAccountingEntry::CAccountingEntry() +{ + SetNull(); +} + +void CAccountingEntry::SetNull() +{ + nCreditDebit = 0; + nTime = 0; + strAccount.clear(); + strOtherAccount.clear(); + strComment.clear(); + nOrderPos = -1; +} + +CWalletKey::CWalletKey(int64_t nExpires) +{ + nTimeCreated = (nExpires ? GetTime() : 0); + nTimeExpires = nExpires; +} + +CKeyPool::CKeyPool() +{ + nTime = GetTime(); +} + +CKeyPool::CKeyPool(const CPubKey &vchPubKeyIn) +{ + nTime = GetTime(); + vchPubKey = vchPubKeyIn; +} diff --git a/src/wallet.h b/src/wallet.h index 138446b..208e261 100644 --- a/src/wallet.h +++ b/src/wallet.h @@ -49,16 +49,9 @@ public: int64_t nTime; CPubKey vchPubKey; - CKeyPool() - { - nTime = GetTime(); - } + CKeyPool(); - CKeyPool(const CPubKey& vchPubKeyIn) - { - nTime = GetTime(); - vchPubKey = vchPubKeyIn; - } + CKeyPool(const CPubKey& vchPubKeyIn); IMPLEMENT_SERIALIZE ( @@ -110,32 +103,9 @@ public: MasterKeyMap mapMasterKeys; unsigned int nMasterKeyMaxID; - CWallet() - { - SetNull(); - } - CWallet(std::string strWalletFileIn) - { - SetNull(); - - strWalletFile = strWalletFileIn; - fFileBacked = true; - } - void SetNull() - { - nWalletVersion = FEATURE_BASE; - nWalletMaxVersion = FEATURE_BASE; - fFileBacked = false; - nMasterKeyMaxID = 0; - pwalletdbEncryption = NULL; - pwalletdbDecryption = NULL; - nNextResend = 0; - nLastResend = 0; - nOrderPosNext = 0; - nKernelsTried = 0; - nCoinDaysTried = 0; - nTimeFirstKey = 0; - } + CWallet(); + CWallet(std::string strWalletFileIn); + void SetNull(); std::map mapWallet; std::vector vMintingWalletUpdated; @@ -280,20 +250,9 @@ public: void UpdatedTransaction(const uint256 &hashTx); void PrintWallet(const CBlock& block); - void Inventory(const uint256 &hash) - { - { - LOCK(cs_wallet); - std::map::iterator mi = mapRequestCount.find(hash); - if (mi != mapRequestCount.end()) - (*mi).second++; - } - } + void Inventory(const uint256 &hash); - unsigned int GetKeyPoolSize() - { - return (unsigned int)(setKeyPool.size()); - } + unsigned int GetKeyPoolSize(); bool GetTransaction(const uint256 &hashTx, CWalletTx& wtx); bool SetDefaultKey(const CPubKey &vchPubKey); @@ -332,17 +291,9 @@ protected: int64_t nIndex; CPubKey vchPubKey; public: - CReserveKey(CWallet* pwalletIn) - { - nIndex = -1; - pwallet = pwalletIn; - } + CReserveKey(CWallet* pwalletIn); - ~CReserveKey() - { - if (!fShutdown) - ReturnKey(); - } + ~CReserveKey(); void ReturnKey(); CPubKey GetReservedKey(); @@ -432,38 +383,7 @@ public: Init(pwalletIn); } - void Init(const CWallet* pwalletIn) - { - pwallet = pwalletIn; - vtxPrev.clear(); - mapValue.clear(); - vOrderForm.clear(); - fTimeReceivedIsTxTime = false; - nTimeReceived = 0; - nTimeSmart = 0; - fFromMe = false; - strFromAccount.clear(); - vfSpent.clear(); - fDebitCached = false; - fWatchDebitCached = false; - fCreditCached = false; - fWatchCreditCached = false; - fAvailableCreditCached = false; - fAvailableWatchCreditCached = false; - fImmatureCreditCached = false; - fImmatureWatchCreditCached = false; - fChangeCached = false; - nDebitCached = 0; - nWatchDebitCached = 0; - nCreditCached = 0; - nWatchCreditCached = 0; - nAvailableCreditCached = 0; - nAvailableWatchCreditCached = 0; - nImmatureCreditCached = 0; - nImmatureWatchCreditCached = 0; - nChangeCached = 0; - nOrderPos = -1; - } + void Init(const CWallet* pwalletIn); IMPLEMENT_SERIALIZE ( @@ -580,15 +500,9 @@ public: int nDepth; bool fSpendable; - COutput(const CWalletTx *txIn, int iIn, int nDepthIn, bool fSpendableIn) - { - tx = txIn; i = iIn; nDepth = nDepthIn; fSpendable = fSpendableIn; - } + COutput(const CWalletTx *txIn, int iIn, int nDepthIn, bool fSpendableIn); - std::string ToString() const - { - return strprintf("COutput(%s, %d, %d, %d) [%s]", tx->GetHash().ToString().substr(0,10).c_str(), i, fSpendable, nDepth, FormatMoney(tx->vout[i].nValue).c_str()); - } + std::string ToString() const; }; @@ -605,11 +519,7 @@ public: //// todo: add something to note what created it (user, getnewaddress, change) //// maybe should have a map property map - CWalletKey(int64_t nExpires=0) - { - nTimeCreated = (nExpires ? GetTime() : 0); - nTimeExpires = nExpires; - } + CWalletKey(int64_t nExpires=0); IMPLEMENT_SERIALIZE ( @@ -635,15 +545,9 @@ class CAccount public: CPubKey vchPubKey; - CAccount() - { - SetNull(); - } + CAccount(); - void SetNull() - { - vchPubKey = CPubKey(); - } + void SetNull(); IMPLEMENT_SERIALIZE ( @@ -670,20 +574,9 @@ public: int64_t nOrderPos; // position in ordered transaction list uint64_t nEntryNo; - CAccountingEntry() - { - SetNull(); - } + CAccountingEntry(); - void SetNull() - { - nCreditDebit = 0; - nTime = 0; - strAccount.clear(); - strOtherAccount.clear(); - strComment.clear(); - nOrderPos = -1; - } + void SetNull(); IMPLEMENT_SERIALIZE ( -- 1.7.1