1- // Provides a cache of wallet balances and functionality for determining whether Omni state changes affected anything in the wallet
1+ /* *
2+ * @file walletcache.cpp
3+ *
4+ * Provides a cache of wallet balances and functionality for determining whether
5+ * Omni state changes affected anything in the wallet.
6+ */
7+
28#include " omnicore/walletcache.h"
39
410#include " omnicore/log.h"
915#include " init.h"
1016#include " sync.h"
1117#include " uint256.h"
18+ #ifdef ENABLE_WALLET
1219#include " wallet.h"
20+ #endif
1321
1422#include < stdint.h>
1523#include < algorithm>
2028#include < utility>
2129#include < vector>
2230
23- using namespace mastercore ;
24-
31+ namespace mastercore
32+ {
2533// ! Global vector of Omni transactions in the wallet
2634std::vector<uint256> walletTXIDCache;
2735
2836// ! Map of wallet balances
2937static std::map<std::string, CMPTally> walletBalancesCache;
3038
3139/* *
32- * Adds a txid to the wallet txid cache, performing duplicate detection
40+ * Adds a txid to the wallet txid cache, performing duplicate detection.
3341 */
3442void WalletTXIDCacheAdd (const uint256& hash)
3543{
@@ -42,21 +50,21 @@ void WalletTXIDCacheAdd(const uint256& hash)
4250}
4351
4452/* *
45- * Performs initial population of the wallet txid cache
53+ * Performs initial population of the wallet txid cache.
4654 */
4755void WalletTXIDCacheInit ()
4856{
4957 if (msc_debug_walletcache) PrintToLog (" WALLETTXIDCACHE: WalletTXIDCacheInit requested\n " );
50-
58+ # ifdef ENABLE_WALLET
5159 LOCK2 (cs_tally, pwalletMain->cs_wallet );
5260
5361 std::list<CAccountingEntry> acentries;
5462 CWallet::TxItems txOrdered = pwalletMain->OrderedTxItems (acentries, " *" );
5563
5664 // Iterate through the wallet, checking if each transaction is Omni (via levelDB)
5765 for (CWallet::TxItems::reverse_iterator it = txOrdered.rbegin (); it != txOrdered.rend (); ++it) {
58- CWalletTx * const pwtx = (*it). second .first ;
59- if (pwtx != 0 ) {
66+ const CWalletTx* pwtx = it-> second .first ;
67+ if (pwtx != NULL ) {
6068 // get the hash of the transaction and check leveldb to see if this is an Omni tx, if so add to cache
6169 const uint256& hash = pwtx->GetHash ();
6270 if (p_txlistdb->exists (hash)) {
@@ -65,11 +73,13 @@ void WalletTXIDCacheInit()
6573 }
6674 }
6775 }
76+ #endif
6877}
6978
7079/* *
71- * Updates the cache with the latest state, returning true if changes were made to wallet addresses (including watch only)
72- * Also prepares a list of addresses that were changed (for future usage)
80+ * Updates the cache with the latest state, returning true if changes were made to wallet addresses (including watch only).
81+ *
82+ * Also prepares a list of addresses that were changed (for future usage).
7383 */
7484int WalletCacheUpdate ()
7585{
@@ -125,3 +135,5 @@ int WalletCacheUpdate()
125135 return numChanges;
126136}
127137
138+
139+ } // namespace mastercore
0 commit comments