@@ -74,75 +74,52 @@ int64 nTransactionFee = 0;
74
74
75
75
// These functions dispatch to one or all registered wallets
76
76
77
-
78
- void RegisterWallet (CWallet* pwalletIn)
79
- {
80
- {
81
- LOCK (cs_setpwalletRegistered);
82
- setpwalletRegistered.insert (pwalletIn);
83
- }
84
- }
85
-
86
- void UnregisterWallet (CWallet* pwalletIn)
87
- {
88
- {
89
- LOCK (cs_setpwalletRegistered);
90
- setpwalletRegistered.erase (pwalletIn);
91
- }
92
- }
93
-
94
- void UnregisterAllWallets ()
95
- {
96
- LOCK (cs_setpwalletRegistered);
97
- setpwalletRegistered.clear ();
77
+ namespace {
78
+ struct CMainSignals {
79
+ // Notifies listeners of updated transaction data (passing hash, transaction, and optionally the block it is found in.
80
+ boost::signals2::signal<void (const uint256 &, const CTransaction &, const CBlock *)> SyncTransaction;
81
+ // Notifies listeners of an erased transaction (currently disabled, requires transaction replacement).
82
+ boost::signals2::signal<void (const uint256 &)> EraseTransaction;
83
+ // Notifies listeners of an updated transaction without new data (for now: a coinbase potentially becoming visible).
84
+ boost::signals2::signal<void (const uint256 &)> UpdatedTransaction;
85
+ // Notifies listeners of a new active block chain.
86
+ boost::signals2::signal<void (const CBlockLocator &)> SetBestChain;
87
+ // Notifies listeners about an inventory item being seen on the network.
88
+ boost::signals2::signal<void (const uint256 &)> Inventory;
89
+ // Tells listeners to broadcast their data.
90
+ boost::signals2::signal<void ()> Broadcast;
91
+ } g_signals;
98
92
}
99
93
100
- // erases transaction with the given hash from all wallets
101
- void static EraseFromWallets (uint256 hash)
102
- {
103
- LOCK (cs_setpwalletRegistered);
104
- BOOST_FOREACH (CWallet* pwallet, setpwalletRegistered)
105
- pwallet->EraseFromWallet (hash);
94
+ void RegisterWallet (CWalletInterface* pwalletIn) {
95
+ g_signals.SyncTransaction .connect (boost::bind (&CWalletInterface::SyncTransaction, pwalletIn, _1, _2, _3));
96
+ g_signals.EraseTransaction .connect (boost::bind (&CWalletInterface::EraseFromWallet, pwalletIn, _1));
97
+ g_signals.UpdatedTransaction .connect (boost::bind (&CWalletInterface::UpdatedTransaction, pwalletIn, _1));
98
+ g_signals.SetBestChain .connect (boost::bind (&CWalletInterface::SetBestChain, pwalletIn, _1));
99
+ g_signals.Inventory .connect (boost::bind (&CWalletInterface::Inventory, pwalletIn, _1));
100
+ g_signals.Broadcast .connect (boost::bind (&CWalletInterface::ResendWalletTransactions, pwalletIn));
106
101
}
107
102
108
- // make sure all wallets know about the given transaction, in the given block
109
- void SyncWithWallets (const uint256 &hash, const CTransaction& tx, const CBlock* pblock, bool fUpdate )
110
- {
111
- LOCK (cs_setpwalletRegistered);
112
- BOOST_FOREACH (CWallet* pwallet, setpwalletRegistered)
113
- pwallet->AddToWalletIfInvolvingMe (hash, tx, pblock, fUpdate );
103
+ void UnregisterWallet (CWalletInterface* pwalletIn) {
104
+ g_signals.Broadcast .disconnect (boost::bind (&CWalletInterface::ResendWalletTransactions, pwalletIn));
105
+ g_signals.Inventory .disconnect (boost::bind (&CWalletInterface::Inventory, pwalletIn, _1));
106
+ g_signals.SetBestChain .disconnect (boost::bind (&CWalletInterface::SetBestChain, pwalletIn, _1));
107
+ g_signals.UpdatedTransaction .disconnect (boost::bind (&CWalletInterface::UpdatedTransaction, pwalletIn, _1));
108
+ g_signals.EraseTransaction .disconnect (boost::bind (&CWalletInterface::EraseFromWallet, pwalletIn, _1));
109
+ g_signals.SyncTransaction .disconnect (boost::bind (&CWalletInterface::SyncTransaction, pwalletIn, _1, _2, _3));
114
110
}
115
111
116
- // notify wallets about a new best chain
117
- void static SetBestChain (const CBlockLocator& loc)
118
- {
119
- LOCK (cs_setpwalletRegistered);
120
- BOOST_FOREACH (CWallet* pwallet, setpwalletRegistered)
121
- pwallet->SetBestChain (loc);
112
+ void UnregisterAllWallets () {
113
+ g_signals.Broadcast .disconnect_all_slots ();
114
+ g_signals.Inventory .disconnect_all_slots ();
115
+ g_signals.SetBestChain .disconnect_all_slots ();
116
+ g_signals.UpdatedTransaction .disconnect_all_slots ();
117
+ g_signals.EraseTransaction .disconnect_all_slots ();
118
+ g_signals.SyncTransaction .disconnect_all_slots ();
122
119
}
123
120
124
- // notify wallets about an updated transaction
125
- void static UpdatedTransaction (const uint256& hashTx)
126
- {
127
- LOCK (cs_setpwalletRegistered);
128
- BOOST_FOREACH (CWallet* pwallet, setpwalletRegistered)
129
- pwallet->UpdatedTransaction (hashTx);
130
- }
131
-
132
- // notify wallets about an incoming inventory (for request counts)
133
- void static Inventory (const uint256& hash)
134
- {
135
- LOCK (cs_setpwalletRegistered);
136
- BOOST_FOREACH (CWallet* pwallet, setpwalletRegistered)
137
- pwallet->Inventory (hash);
138
- }
139
-
140
- // ask wallets to resend their transactions
141
- void static ResendWalletTransactions ()
142
- {
143
- LOCK (cs_setpwalletRegistered);
144
- BOOST_FOREACH (CWallet* pwallet, setpwalletRegistered)
145
- pwallet->ResendWalletTransactions ();
121
+ void SyncWithWallets (const uint256 &hash, const CTransaction &tx, const CBlock *pblock) {
122
+ g_signals.SyncTransaction (hash, tx, pblock);
146
123
}
147
124
148
125
// ////////////////////////////////////////////////////////////////////////////
@@ -913,8 +890,8 @@ bool CTxMemPool::accept(CValidationState &state, const CTransaction &tx, bool fL
913
890
// /// are we sure this is ok when loading transactions or restoring block txes
914
891
// If updated, erase old tx from wallet
915
892
if (ptxOld)
916
- EraseFromWallets (ptxOld->GetHash ());
917
- SyncWithWallets (hash, tx, NULL , true );
893
+ g_signals. EraseTransaction (ptxOld->GetHash ());
894
+ g_signals. SyncTransaction (hash, tx, NULL );
918
895
919
896
LogPrint (" mempool" , " CTxMemPool::accept() : accepted %s (poolsz %" PRIszu" )\n " ,
920
897
hash.ToString ().c_str (),
@@ -1974,7 +1951,7 @@ bool ConnectBlock(CBlock& block, CValidationState& state, CBlockIndex* pindex, C
1974
1951
1975
1952
// Watch for transactions paying to me
1976
1953
for (unsigned int i = 0 ; i < block.vtx .size (); i++)
1977
- SyncWithWallets (block.GetTxHash (i), block.vtx [i], &block, true );
1954
+ g_signals. SyncTransaction (block.GetTxHash (i), block.vtx [i], &block);
1978
1955
1979
1956
return true ;
1980
1957
}
@@ -2108,7 +2085,7 @@ bool SetBestChain(CValidationState &state, CBlockIndex* pindexNew)
2108
2085
2109
2086
// Update best block in wallet (so we can detect restored wallets)
2110
2087
if ((pindexNew->nHeight % 20160 ) == 0 || (!fIsInitialDownload && (pindexNew->nHeight % 144 ) == 0 ))
2111
- :: SetBestChain (chainActive.GetLocator(pindexNew));
2088
+ g_signals. SetBestChain (chainActive.GetLocator (pindexNew));
2112
2089
2113
2090
// New best block
2114
2091
nTimeBestReceived = GetTime ();
@@ -2188,7 +2165,7 @@ bool AddToBlockIndex(CBlock& block, CValidationState& state, const CDiskBlockPos
2188
2165
CheckForkWarningConditions ();
2189
2166
// Notify UI to display prev block's coinbase if it was ours
2190
2167
static uint256 hashPrevBestCoinBase;
2191
- UpdatedTransaction (hashPrevBestCoinBase);
2168
+ g_signals. UpdatedTransaction (hashPrevBestCoinBase);
2192
2169
hashPrevBestCoinBase = block.GetTxHash (0 );
2193
2170
} else
2194
2171
CheckForkWarningConditionsOnNewFork (pindexNew);
@@ -3311,7 +3288,7 @@ void static ProcessGetData(CNode* pfrom)
3311
3288
}
3312
3289
3313
3290
// Track requests for our stuff.
3314
- Inventory (inv.hash );
3291
+ g_signals. Inventory (inv.hash );
3315
3292
}
3316
3293
}
3317
3294
@@ -3573,7 +3550,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
3573
3550
}
3574
3551
3575
3552
// Track requests for our stuff
3576
- Inventory (inv.hash );
3553
+ g_signals. Inventory (inv.hash );
3577
3554
}
3578
3555
}
3579
3556
@@ -4193,7 +4170,7 @@ bool SendMessages(CNode* pto, bool fSendTrickle)
4193
4170
// transactions become unconfirmed and spams other nodes.
4194
4171
if (!fReindex && !fImporting && !IsInitialBlockDownload ())
4195
4172
{
4196
- ResendWalletTransactions ();
4173
+ g_signals. Broadcast ();
4197
4174
}
4198
4175
4199
4176
//
0 commit comments