@@ -74,93 +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 ();
98
- }
99
-
100
- // get the wallet transaction with the given hash (if it exists)
101
- bool static GetTransaction (const uint256& hashTx, CWalletTx& wtx)
102
- {
103
- LOCK (cs_setpwalletRegistered);
104
- BOOST_FOREACH (CWallet* pwallet, setpwalletRegistered)
105
- if (pwallet->GetTransaction (hashTx,wtx))
106
- return true ;
107
- return false ;
108
- }
109
-
110
- // erases transaction with the given hash from all wallets
111
- void static EraseFromWallets (uint256 hash)
112
- {
113
- LOCK (cs_setpwalletRegistered);
114
- BOOST_FOREACH (CWallet* pwallet, setpwalletRegistered)
115
- pwallet->EraseFromWallet (hash);
116
- }
117
-
118
- // make sure all wallets know about the given transaction, in the given block
119
- void SyncWithWallets (const uint256 &hash, const CTransaction& tx, const CBlock* pblock, bool fUpdate )
120
- {
121
- LOCK (cs_setpwalletRegistered);
122
- BOOST_FOREACH (CWallet* pwallet, setpwalletRegistered)
123
- pwallet->AddToWalletIfInvolvingMe (hash, tx, pblock, fUpdate );
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;
124
92
}
125
93
126
- // notify wallets about a new best chain
127
- void static SetBestChain (const CBlockLocator& loc)
128
- {
129
- LOCK (cs_setpwalletRegistered);
130
- BOOST_FOREACH (CWallet* pwallet, setpwalletRegistered)
131
- pwallet->SetBestChain (loc);
132
- }
133
-
134
- // notify wallets about an updated transaction
135
- void static UpdatedTransaction (const uint256& hashTx)
136
- {
137
- LOCK (cs_setpwalletRegistered);
138
- BOOST_FOREACH (CWallet* pwallet, setpwalletRegistered)
139
- pwallet->UpdatedTransaction (hashTx);
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));
140
101
}
141
102
142
- // dump all wallets
143
- void static PrintWallets (const CBlock& block)
144
- {
145
- LOCK (cs_setpwalletRegistered);
146
- BOOST_FOREACH (CWallet* pwallet, setpwalletRegistered)
147
- pwallet->PrintWallet (block);
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));
148
110
}
149
111
150
- // notify wallets about an incoming inventory (for request counts)
151
- void static Inventory (const uint256& hash)
152
- {
153
- LOCK (cs_setpwalletRegistered);
154
- BOOST_FOREACH (CWallet* pwallet, setpwalletRegistered)
155
- pwallet->Inventory (hash);
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 ();
156
119
}
157
120
158
- // ask wallets to resend their transactions
159
- void static ResendWalletTransactions ()
160
- {
161
- LOCK (cs_setpwalletRegistered);
162
- BOOST_FOREACH (CWallet* pwallet, setpwalletRegistered)
163
- pwallet->ResendWalletTransactions ();
121
+ void SyncWithWallets (const uint256 &hash, const CTransaction &tx, const CBlock *pblock) {
122
+ g_signals.SyncTransaction (hash, tx, pblock);
164
123
}
165
124
166
125
// ////////////////////////////////////////////////////////////////////////////
@@ -931,8 +890,8 @@ bool CTxMemPool::accept(CValidationState &state, const CTransaction &tx, bool fL
931
890
// /// are we sure this is ok when loading transactions or restoring block txes
932
891
// If updated, erase old tx from wallet
933
892
if (ptxOld)
934
- EraseFromWallets (ptxOld->GetHash ());
935
- SyncWithWallets (hash, tx, NULL , true );
893
+ g_signals. EraseTransaction (ptxOld->GetHash ());
894
+ g_signals. SyncTransaction (hash, tx, NULL );
936
895
937
896
LogPrint (" mempool" , " CTxMemPool::accept() : accepted %s (poolsz %" PRIszu" )\n " ,
938
897
hash.ToString ().c_str (),
@@ -1095,27 +1054,6 @@ bool CMerkleTx::AcceptToMemoryPool(bool fLimitFree)
1095
1054
}
1096
1055
1097
1056
1098
-
1099
- bool CWalletTx::AcceptWalletTransaction ()
1100
- {
1101
- {
1102
- LOCK (mempool.cs );
1103
- // Add previous supporting transactions first
1104
- BOOST_FOREACH (CMerkleTx& tx, vtxPrev)
1105
- {
1106
- if (!tx.IsCoinBase ())
1107
- {
1108
- uint256 hash = tx.GetHash ();
1109
- if (!mempool.exists (hash) && pcoinsTip->HaveCoins (hash))
1110
- tx.AcceptToMemoryPool (false );
1111
- }
1112
- }
1113
- return AcceptToMemoryPool (false );
1114
- }
1115
- return false ;
1116
- }
1117
-
1118
-
1119
1057
// Return transaction in tx, and if it was found inside a block, its hash is placed in hashBlock
1120
1058
bool GetTransaction (const uint256 &hash, CTransaction &txOut, uint256 &hashBlock, bool fAllowSlow )
1121
1059
{
@@ -1992,7 +1930,7 @@ bool ConnectBlock(CBlock& block, CValidationState& state, CBlockIndex* pindex, C
1992
1930
1993
1931
// Watch for transactions paying to me
1994
1932
for (unsigned int i = 0 ; i < block.vtx .size (); i++)
1995
- SyncWithWallets (block.GetTxHash (i), block.vtx [i], &block, true );
1933
+ g_signals. SyncTransaction (block.GetTxHash (i), block.vtx [i], &block);
1996
1934
1997
1935
return true ;
1998
1936
}
@@ -2126,7 +2064,7 @@ bool SetBestChain(CValidationState &state, CBlockIndex* pindexNew)
2126
2064
2127
2065
// Update best block in wallet (so we can detect restored wallets)
2128
2066
if ((pindexNew->nHeight % 20160 ) == 0 || (!fIsInitialDownload && (pindexNew->nHeight % 144 ) == 0 ))
2129
- :: SetBestChain (chainActive.GetLocator(pindexNew));
2067
+ g_signals. SetBestChain (chainActive.GetLocator (pindexNew));
2130
2068
2131
2069
// New best block
2132
2070
nTimeBestReceived = GetTime ();
@@ -2206,7 +2144,7 @@ bool AddToBlockIndex(CBlock& block, CValidationState& state, const CDiskBlockPos
2206
2144
CheckForkWarningConditions ();
2207
2145
// Notify UI to display prev block's coinbase if it was ours
2208
2146
static uint256 hashPrevBestCoinBase;
2209
- UpdatedTransaction (hashPrevBestCoinBase);
2147
+ g_signals. UpdatedTransaction (hashPrevBestCoinBase);
2210
2148
hashPrevBestCoinBase = block.GetTxHash (0 );
2211
2149
} else
2212
2150
CheckForkWarningConditionsOnNewFork (pindexNew);
@@ -3041,8 +2979,6 @@ void PrintBlockTree()
3041
2979
DateTimeStrFormat (" %Y-%m-%d %H:%M:%S" , block.GetBlockTime ()).c_str (),
3042
2980
block.vtx .size ());
3043
2981
3044
- PrintWallets (block);
3045
-
3046
2982
// put the main time-chain first
3047
2983
vector<CBlockIndex*>& vNext = mapNext[pindex];
3048
2984
for (unsigned int i = 0 ; i < vNext.size (); i++)
@@ -3331,7 +3267,7 @@ void static ProcessGetData(CNode* pfrom)
3331
3267
}
3332
3268
3333
3269
// Track requests for our stuff.
3334
- Inventory (inv.hash );
3270
+ g_signals. Inventory (inv.hash );
3335
3271
}
3336
3272
}
3337
3273
@@ -3593,7 +3529,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
3593
3529
}
3594
3530
3595
3531
// Track requests for our stuff
3596
- Inventory (inv.hash );
3532
+ g_signals. Inventory (inv.hash );
3597
3533
}
3598
3534
}
3599
3535
@@ -4215,7 +4151,7 @@ bool SendMessages(CNode* pto, bool fSendTrickle)
4215
4151
// transactions become unconfirmed and spams other nodes.
4216
4152
if (!fReindex && !fImporting && !IsInitialBlockDownload ())
4217
4153
{
4218
- ResendWalletTransactions ();
4154
+ g_signals. Broadcast ();
4219
4155
}
4220
4156
4221
4157
//
@@ -4243,15 +4179,6 @@ bool SendMessages(CNode* pto, bool fSendTrickle)
4243
4179
hashRand = Hash (BEGIN (hashRand), END (hashRand));
4244
4180
bool fTrickleWait = ((hashRand & 3 ) != 0 );
4245
4181
4246
- // always trickle our own transactions
4247
- if (!fTrickleWait )
4248
- {
4249
- CWalletTx wtx;
4250
- if (GetTransaction (inv.hash , wtx))
4251
- if (wtx.fFromMe )
4252
- fTrickleWait = true ;
4253
- }
4254
-
4255
4182
if (fTrickleWait )
4256
4183
{
4257
4184
vInvWait.push_back (inv);
0 commit comments