aboutsummaryrefslogtreecommitdiff
path: root/src/main.cpp
diff options
context:
space:
mode:
authorJorge Timón <jtimon@jtimon.cc>2015-02-05 01:11:44 +0100
committerJorge Timón <jtimon@jtimon.cc>2015-03-24 17:21:41 +0100
commit26c16d9de9874ad2f5fe28377b838a19a558639d (patch)
treeb717b2b494657038684a4259d66b1904858b9b42 /src/main.cpp
parent22cfe23196c5006d6dd79e1e1a24323148246bde (diff)
Includes: Refactor: Move CValidationInterface and CMainSignals out of main
Diffstat (limited to 'src/main.cpp')
-rw-r--r--src/main.cpp77
1 files changed, 8 insertions, 69 deletions
diff --git a/src/main.cpp b/src/main.cpp
index aa6f904574..0ffacc338e 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -5,9 +5,9 @@
#include "main.h"
-#include "arith_uint256.h"
#include "addrman.h"
#include "alert.h"
+#include "arith_uint256.h"
#include "chainparams.h"
#include "checkpoints.h"
#include "checkqueue.h"
@@ -21,6 +21,7 @@
#include "undo.h"
#include "util.h"
#include "utilmoneystr.h"
+#include "validationinterface.h"
#include <sstream>
@@ -158,68 +159,6 @@ namespace {
//////////////////////////////////////////////////////////////////////////////
//
-// dispatching functions
-//
-
-// These functions dispatch to one or all registered wallets
-
-namespace {
-
-struct CMainSignals {
- /** Notifies listeners of updated transaction data (transaction, and optionally the block it is found in. */
- boost::signals2::signal<void (const CTransaction &, const CBlock *)> SyncTransaction;
- /** Notifies listeners of an erased transaction (currently disabled, requires transaction replacement). */
- boost::signals2::signal<void (const uint256 &)> EraseTransaction;
- /** Notifies listeners of an updated transaction without new data (for now: a coinbase potentially becoming visible). */
- boost::signals2::signal<void (const uint256 &)> UpdatedTransaction;
- /** Notifies listeners of a new active block chain. */
- boost::signals2::signal<void (const CBlockLocator &)> SetBestChain;
- /** Notifies listeners about an inventory item being seen on the network. */
- boost::signals2::signal<void (const uint256 &)> Inventory;
- /** Tells listeners to broadcast their data. */
- boost::signals2::signal<void ()> Broadcast;
- /** Notifies listeners of a block validation result */
- boost::signals2::signal<void (const CBlock&, const CValidationState&)> BlockChecked;
-} g_signals;
-
-} // anon namespace
-
-void RegisterValidationInterface(CValidationInterface* pwalletIn) {
- g_signals.SyncTransaction.connect(boost::bind(&CValidationInterface::SyncTransaction, pwalletIn, _1, _2));
- g_signals.EraseTransaction.connect(boost::bind(&CValidationInterface::EraseFromWallet, pwalletIn, _1));
- g_signals.UpdatedTransaction.connect(boost::bind(&CValidationInterface::UpdatedTransaction, pwalletIn, _1));
- g_signals.SetBestChain.connect(boost::bind(&CValidationInterface::SetBestChain, pwalletIn, _1));
- g_signals.Inventory.connect(boost::bind(&CValidationInterface::Inventory, pwalletIn, _1));
- g_signals.Broadcast.connect(boost::bind(&CValidationInterface::ResendWalletTransactions, pwalletIn));
- g_signals.BlockChecked.connect(boost::bind(&CValidationInterface::BlockChecked, pwalletIn, _1, _2));
-}
-
-void UnregisterValidationInterface(CValidationInterface* pwalletIn) {
- g_signals.BlockChecked.disconnect(boost::bind(&CValidationInterface::BlockChecked, pwalletIn, _1, _2));
- g_signals.Broadcast.disconnect(boost::bind(&CValidationInterface::ResendWalletTransactions, pwalletIn));
- g_signals.Inventory.disconnect(boost::bind(&CValidationInterface::Inventory, pwalletIn, _1));
- g_signals.SetBestChain.disconnect(boost::bind(&CValidationInterface::SetBestChain, pwalletIn, _1));
- g_signals.UpdatedTransaction.disconnect(boost::bind(&CValidationInterface::UpdatedTransaction, pwalletIn, _1));
- g_signals.EraseTransaction.disconnect(boost::bind(&CValidationInterface::EraseFromWallet, pwalletIn, _1));
- g_signals.SyncTransaction.disconnect(boost::bind(&CValidationInterface::SyncTransaction, pwalletIn, _1, _2));
-}
-
-void UnregisterAllValidationInterfaces() {
- g_signals.BlockChecked.disconnect_all_slots();
- g_signals.Broadcast.disconnect_all_slots();
- g_signals.Inventory.disconnect_all_slots();
- g_signals.SetBestChain.disconnect_all_slots();
- g_signals.UpdatedTransaction.disconnect_all_slots();
- g_signals.EraseTransaction.disconnect_all_slots();
- g_signals.SyncTransaction.disconnect_all_slots();
-}
-
-void SyncWithWallets(const CTransaction &tx, const CBlock *pblock) {
- g_signals.SyncTransaction(tx, pblock);
-}
-
-//////////////////////////////////////////////////////////////////////////////
-//
// Registration of network node signals.
//
@@ -1897,7 +1836,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
// Watch for changes to the previous coinbase transaction.
static uint256 hashPrevBestCoinBase;
- g_signals.UpdatedTransaction(hashPrevBestCoinBase);
+ GetMainSignals().UpdatedTransaction(hashPrevBestCoinBase);
hashPrevBestCoinBase = block.vtx[0].GetHash();
int64_t nTime4 = GetTimeMicros(); nTimeCallbacks += nTime4 - nTime3;
@@ -1956,7 +1895,7 @@ bool static FlushStateToDisk(CValidationState &state, FlushStateMode mode) {
return state.Abort("Failed to write to coin database");
// Update best block in wallet (so we can detect restored wallets).
if (mode != FLUSH_STATE_IF_NEEDED) {
- g_signals.SetBestChain(chainActive.GetLocator());
+ GetMainSignals().SetBestChain(chainActive.GetLocator());
}
nLastWrite = GetTimeMicros();
}
@@ -2080,7 +2019,7 @@ bool static ConnectTip(CValidationState &state, CBlockIndex *pindexNew, CBlock *
CCoinsViewCache view(pcoinsTip);
CInv inv(MSG_BLOCK, pindexNew->GetBlockHash());
bool rv = ConnectBlock(*pblock, state, pindexNew, view);
- g_signals.BlockChecked(*pblock, state);
+ GetMainSignals().BlockChecked(*pblock, state);
if (!rv) {
if (state.IsInvalid())
InvalidBlockFound(pindexNew, state);
@@ -3471,7 +3410,7 @@ void static ProcessGetData(CNode* pfrom)
}
// Track requests for our stuff.
- g_signals.Inventory(inv.hash);
+ GetMainSignals().Inventory(inv.hash);
if (inv.type == MSG_BLOCK || inv.type == MSG_FILTERED_BLOCK)
break;
@@ -3765,7 +3704,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
}
// Track requests for our stuff
- g_signals.Inventory(inv.hash);
+ GetMainSignals().Inventory(inv.hash);
if (pfrom->nSendSize > (SendBufferSize() * 2)) {
Misbehaving(pfrom->GetId(), 50);
@@ -4536,7 +4475,7 @@ bool SendMessages(CNode* pto, bool fSendTrickle)
// transactions become unconfirmed and spams other nodes.
if (!fReindex && !fImporting && !IsInitialBlockDownload())
{
- g_signals.Broadcast();
+ GetMainSignals().Broadcast();
}
//