Skip to content

Commit 8d2fbfa

Browse files
committed
Merge pull request #5681
8a893c9 Includes: Do not include main.h from any other header (Jorge Timón) eca0b1e Includes: MOVEONLY: move more method definitions out of wallet.h (Jorge Timón) 26c16d9 Includes: Refactor: Move CValidationInterface and CMainSignals out of main (Jorge Timón)
2 parents 22cfe23 + 8a893c9 commit 8d2fbfa

17 files changed

+221
-160
lines changed

src/Makefile.am

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ BITCOIN_CORE_H = \
138138
utilmoneystr.h \
139139
utilstrencodings.h \
140140
utiltime.h \
141+
validationinterface.h \
141142
version.h \
142143
wallet/crypter.h \
143144
wallet/walletdb.h \
@@ -191,6 +192,7 @@ libbitcoin_server_a_SOURCES = \
191192
timedata.cpp \
192193
txdb.cpp \
193194
txmempool.cpp \
195+
validationinterface.cpp \
194196
$(JSON_H) \
195197
$(BITCOIN_CORE_H)
196198

src/main.cpp

Lines changed: 8 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55

66
#include "main.h"
77

8-
#include "arith_uint256.h"
98
#include "addrman.h"
109
#include "alert.h"
10+
#include "arith_uint256.h"
1111
#include "chainparams.h"
1212
#include "checkpoints.h"
1313
#include "checkqueue.h"
@@ -21,6 +21,7 @@
2121
#include "undo.h"
2222
#include "util.h"
2323
#include "utilmoneystr.h"
24+
#include "validationinterface.h"
2425

2526
#include <sstream>
2627

@@ -156,68 +157,6 @@ namespace {
156157
set<int> setDirtyFileInfo;
157158
} // anon namespace
158159

159-
//////////////////////////////////////////////////////////////////////////////
160-
//
161-
// dispatching functions
162-
//
163-
164-
// These functions dispatch to one or all registered wallets
165-
166-
namespace {
167-
168-
struct CMainSignals {
169-
/** Notifies listeners of updated transaction data (transaction, and optionally the block it is found in. */
170-
boost::signals2::signal<void (const CTransaction &, const CBlock *)> SyncTransaction;
171-
/** Notifies listeners of an erased transaction (currently disabled, requires transaction replacement). */
172-
boost::signals2::signal<void (const uint256 &)> EraseTransaction;
173-
/** Notifies listeners of an updated transaction without new data (for now: a coinbase potentially becoming visible). */
174-
boost::signals2::signal<void (const uint256 &)> UpdatedTransaction;
175-
/** Notifies listeners of a new active block chain. */
176-
boost::signals2::signal<void (const CBlockLocator &)> SetBestChain;
177-
/** Notifies listeners about an inventory item being seen on the network. */
178-
boost::signals2::signal<void (const uint256 &)> Inventory;
179-
/** Tells listeners to broadcast their data. */
180-
boost::signals2::signal<void ()> Broadcast;
181-
/** Notifies listeners of a block validation result */
182-
boost::signals2::signal<void (const CBlock&, const CValidationState&)> BlockChecked;
183-
} g_signals;
184-
185-
} // anon namespace
186-
187-
void RegisterValidationInterface(CValidationInterface* pwalletIn) {
188-
g_signals.SyncTransaction.connect(boost::bind(&CValidationInterface::SyncTransaction, pwalletIn, _1, _2));
189-
g_signals.EraseTransaction.connect(boost::bind(&CValidationInterface::EraseFromWallet, pwalletIn, _1));
190-
g_signals.UpdatedTransaction.connect(boost::bind(&CValidationInterface::UpdatedTransaction, pwalletIn, _1));
191-
g_signals.SetBestChain.connect(boost::bind(&CValidationInterface::SetBestChain, pwalletIn, _1));
192-
g_signals.Inventory.connect(boost::bind(&CValidationInterface::Inventory, pwalletIn, _1));
193-
g_signals.Broadcast.connect(boost::bind(&CValidationInterface::ResendWalletTransactions, pwalletIn));
194-
g_signals.BlockChecked.connect(boost::bind(&CValidationInterface::BlockChecked, pwalletIn, _1, _2));
195-
}
196-
197-
void UnregisterValidationInterface(CValidationInterface* pwalletIn) {
198-
g_signals.BlockChecked.disconnect(boost::bind(&CValidationInterface::BlockChecked, pwalletIn, _1, _2));
199-
g_signals.Broadcast.disconnect(boost::bind(&CValidationInterface::ResendWalletTransactions, pwalletIn));
200-
g_signals.Inventory.disconnect(boost::bind(&CValidationInterface::Inventory, pwalletIn, _1));
201-
g_signals.SetBestChain.disconnect(boost::bind(&CValidationInterface::SetBestChain, pwalletIn, _1));
202-
g_signals.UpdatedTransaction.disconnect(boost::bind(&CValidationInterface::UpdatedTransaction, pwalletIn, _1));
203-
g_signals.EraseTransaction.disconnect(boost::bind(&CValidationInterface::EraseFromWallet, pwalletIn, _1));
204-
g_signals.SyncTransaction.disconnect(boost::bind(&CValidationInterface::SyncTransaction, pwalletIn, _1, _2));
205-
}
206-
207-
void UnregisterAllValidationInterfaces() {
208-
g_signals.BlockChecked.disconnect_all_slots();
209-
g_signals.Broadcast.disconnect_all_slots();
210-
g_signals.Inventory.disconnect_all_slots();
211-
g_signals.SetBestChain.disconnect_all_slots();
212-
g_signals.UpdatedTransaction.disconnect_all_slots();
213-
g_signals.EraseTransaction.disconnect_all_slots();
214-
g_signals.SyncTransaction.disconnect_all_slots();
215-
}
216-
217-
void SyncWithWallets(const CTransaction &tx, const CBlock *pblock) {
218-
g_signals.SyncTransaction(tx, pblock);
219-
}
220-
221160
//////////////////////////////////////////////////////////////////////////////
222161
//
223162
// Registration of network node signals.
@@ -1897,7 +1836,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
18971836

18981837
// Watch for changes to the previous coinbase transaction.
18991838
static uint256 hashPrevBestCoinBase;
1900-
g_signals.UpdatedTransaction(hashPrevBestCoinBase);
1839+
GetMainSignals().UpdatedTransaction(hashPrevBestCoinBase);
19011840
hashPrevBestCoinBase = block.vtx[0].GetHash();
19021841

19031842
int64_t nTime4 = GetTimeMicros(); nTimeCallbacks += nTime4 - nTime3;
@@ -1956,7 +1895,7 @@ bool static FlushStateToDisk(CValidationState &state, FlushStateMode mode) {
19561895
return state.Abort("Failed to write to coin database");
19571896
// Update best block in wallet (so we can detect restored wallets).
19581897
if (mode != FLUSH_STATE_IF_NEEDED) {
1959-
g_signals.SetBestChain(chainActive.GetLocator());
1898+
GetMainSignals().SetBestChain(chainActive.GetLocator());
19601899
}
19611900
nLastWrite = GetTimeMicros();
19621901
}
@@ -2080,7 +2019,7 @@ bool static ConnectTip(CValidationState &state, CBlockIndex *pindexNew, CBlock *
20802019
CCoinsViewCache view(pcoinsTip);
20812020
CInv inv(MSG_BLOCK, pindexNew->GetBlockHash());
20822021
bool rv = ConnectBlock(*pblock, state, pindexNew, view);
2083-
g_signals.BlockChecked(*pblock, state);
2022+
GetMainSignals().BlockChecked(*pblock, state);
20842023
if (!rv) {
20852024
if (state.IsInvalid())
20862025
InvalidBlockFound(pindexNew, state);
@@ -3471,7 +3410,7 @@ void static ProcessGetData(CNode* pfrom)
34713410
}
34723411

34733412
// Track requests for our stuff.
3474-
g_signals.Inventory(inv.hash);
3413+
GetMainSignals().Inventory(inv.hash);
34753414

34763415
if (inv.type == MSG_BLOCK || inv.type == MSG_FILTERED_BLOCK)
34773416
break;
@@ -3765,7 +3704,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
37653704
}
37663705

37673706
// Track requests for our stuff
3768-
g_signals.Inventory(inv.hash);
3707+
GetMainSignals().Inventory(inv.hash);
37693708

37703709
if (pfrom->nSendSize > (SendBufferSize() * 2)) {
37713710
Misbehaving(pfrom->GetId(), 50);
@@ -4536,7 +4475,7 @@ bool SendMessages(CNode* pto, bool fSendTrickle)
45364475
// transactions become unconfirmed and spams other nodes.
45374476
if (!fReindex && !fImporting && !IsInitialBlockDownload())
45384477
{
4539-
g_signals.Broadcast();
4478+
GetMainSignals().Broadcast();
45404479
}
45414480

45424481
//

src/main.h

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -133,15 +133,6 @@ extern CBlockIndex *pindexBestHeader;
133133
/** Minimum disk space required - used in CheckDiskSpace() */
134134
static const uint64_t nMinDiskSpace = 52428800;
135135

136-
/** Register a wallet to receive updates from core */
137-
void RegisterValidationInterface(CValidationInterface* pwalletIn);
138-
/** Unregister a wallet from core */
139-
void UnregisterValidationInterface(CValidationInterface* pwalletIn);
140-
/** Unregister all wallets from core */
141-
void UnregisterAllValidationInterfaces();
142-
/** Push an updated transaction to all registered wallets */
143-
void SyncWithWallets(const CTransaction& tx, const CBlock* pblock = NULL);
144-
145136
/** Register with a network node to receive its signals */
146137
void RegisterNodeSignals(CNodeSignals& nodeSignals);
147138
/** Unregister a network node */
@@ -152,7 +143,7 @@ void UnregisterNodeSignals(CNodeSignals& nodeSignals);
152143
* block is made active. Note that it does not, however, guarantee that the
153144
* specific block passed to it has been checked for validity!
154145
*
155-
* @param[out] state This may be set to an Error state if any error occurred processing it, including during validation/connection/etc of otherwise unrelated blocks during reorganisation; or it may be set to an Invalid state if pblock is itself invalid (but this is not guaranteed even when the block is checked). If you want to *possibly* get feedback on whether pblock is valid, you must also install a CValidationInterface - this will have its BlockChecked method called whenever *any* block completes validation.
146+
* @param[out] state This may be set to an Error state if any error occurred processing it, including during validation/connection/etc of otherwise unrelated blocks during reorganisation; or it may be set to an Invalid state if pblock is itself invalid (but this is not guaranteed even when the block is checked). If you want to *possibly* get feedback on whether pblock is valid, you must also install a CValidationInterface (see validationinterface.h) - this will have its BlockChecked method called whenever *any* block completes validation.
156147
* @param[in] pfrom The node which we are receiving the block from; it is added to mapBlockSource and may be penalised if the block is invalid.
157148
* @param[in] pblock The block we want to process.
158149
* @param[out] dbp If pblock is stored to disk (or already there), this will be set to its location.
@@ -512,19 +503,4 @@ extern CCoinsViewCache *pcoinsTip;
512503
/** Global variable that points to the active block tree (protected by cs_main) */
513504
extern CBlockTreeDB *pblocktree;
514505

515-
516-
class CValidationInterface {
517-
protected:
518-
virtual void SyncTransaction(const CTransaction &tx, const CBlock *pblock) {};
519-
virtual void EraseFromWallet(const uint256 &hash) {};
520-
virtual void SetBestChain(const CBlockLocator &locator) {};
521-
virtual void UpdatedTransaction(const uint256 &hash) {};
522-
virtual void Inventory(const uint256 &hash) {};
523-
virtual void ResendWalletTransactions() {};
524-
virtual void BlockChecked(const CBlock&, const CValidationState&) {};
525-
friend void ::RegisterValidationInterface(CValidationInterface*);
526-
friend void ::UnregisterValidationInterface(CValidationInterface*);
527-
friend void ::UnregisterAllValidationInterfaces();
528-
};
529-
530506
#endif // BITCOIN_MAIN_H

src/qt/addresstablemodel.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
#include "base58.h"
1111
#include "wallet/wallet.h"
1212

13+
#include <boost/foreach.hpp>
14+
1315
#include <QFont>
1416
#include <QDebug>
1517

src/qt/paymentserver.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
#include "base58.h"
1212
#include "chainparams.h"
13+
#include "main.h"
1314
#include "ui_interface.h"
1415
#include "util.h"
1516
#include "wallet/wallet.h"

src/qt/sendcoinsdialog.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
#include "base58.h"
1919
#include "coincontrol.h"
20+
#include "main.h"
2021
#include "ui_interface.h"
2122
#include "wallet/wallet.h"
2223

src/qt/signverifymessagedialog.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
#include "base58.h"
1414
#include "init.h"
15+
#include "main.h" // For strMessageMagic
1516
#include "wallet/wallet.h"
1617

1718
#include <string>

src/qt/transactionrecord.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,14 @@
55
#include "transactionrecord.h"
66

77
#include "base58.h"
8+
#include "main.h"
89
#include "timedata.h"
910
#include "wallet/wallet.h"
1011

1112
#include <stdint.h>
1213

14+
#include <boost/foreach.hpp>
15+
1316
/* Return positive answer if transaction should be shown in list.
1417
*/
1518
bool TransactionRecord::showTransaction(const CWalletTx &wtx)

src/test/rpc_wallet_tests.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "rpcclient.h"
77

88
#include "base58.h"
9+
#include "main.h"
910
#include "wallet/wallet.h"
1011

1112
#include "test/test_bitcoin.h"

src/txdb.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
#include "txdb.h"
77

8+
#include "main.h"
89
#include "pow.h"
910
#include "uint256.h"
1011

0 commit comments

Comments
 (0)