@@ -231,6 +231,82 @@ bool CWallet::SetMaxVersion(int nVersion)
231231 return true ;
232232}
233233
234+ set<uint256> CWallet::GetConflicts (const uint256& txid) const
235+ {
236+ set<uint256> result;
237+ AssertLockHeld (cs_wallet);
238+
239+ std::map<uint256, CWalletTx>::const_iterator it = mapWallet.find (txid);
240+ if (it == mapWallet.end ())
241+ return result;
242+ const CWalletTx& wtx = it->second ;
243+
244+ std::pair<TxConflicts::const_iterator, TxConflicts::const_iterator> range;
245+
246+ BOOST_FOREACH (const CTxIn& txin, wtx.vin )
247+ {
248+ range = mapTxConflicts.equal_range (txin.prevout );
249+ for (TxConflicts::const_iterator it = range.first ; it != range.second ; ++it)
250+ result.insert (it->second );
251+ }
252+ return result;
253+ }
254+
255+ void CWallet::SyncMetaData (pair<TxConflicts::iterator, TxConflicts::iterator> range)
256+ {
257+ // We want all the wallet transactions in range to have the same metadata as
258+ // the oldest (smallest nOrderPos).
259+ // So: find smallest nOrderPos:
260+
261+ int nMinOrderPos = std::numeric_limits<int >::max ();
262+ const CWalletTx* copyFrom = NULL ;
263+ for (TxConflicts::iterator it = range.first ; it != range.second ; ++it)
264+ {
265+ const uint256& hash = it->second ;
266+ int n = mapWallet[hash].nOrderPos ;
267+ if (n < nMinOrderPos)
268+ {
269+ nMinOrderPos = n;
270+ copyFrom = &mapWallet[hash];
271+ }
272+ }
273+ // Now copy data from copyFrom to rest:
274+ for (TxConflicts::iterator it = range.first ; it != range.second ; ++it)
275+ {
276+ const uint256& hash = it->second ;
277+ CWalletTx* copyTo = &mapWallet[hash];
278+ if (copyFrom == copyTo) continue ;
279+ copyTo->mapValue = copyFrom->mapValue ;
280+ copyTo->vOrderForm = copyFrom->vOrderForm ;
281+ // fTimeReceivedIsTxTime not copied on purpose
282+ // nTimeReceived not copied on purpose
283+ copyTo->nTimeSmart = copyFrom->nTimeSmart ;
284+ copyTo->fFromMe = copyFrom->fFromMe ;
285+ copyTo->strFromAccount = copyFrom->strFromAccount ;
286+ // vfSpent not copied on purpose
287+ // nOrderPos not copied on purpose
288+ // cached members not copied on purpose
289+ }
290+ }
291+
292+ void CWallet::AddToConflicts (const uint256& wtxhash)
293+ {
294+ assert (mapWallet.count (wtxhash));
295+ CWalletTx& thisTx = mapWallet[wtxhash];
296+ if (thisTx.IsCoinBase ())
297+ return ;
298+
299+ BOOST_FOREACH (const CTxIn& txin, thisTx.vin )
300+ {
301+ mapTxConflicts.insert (make_pair (txin.prevout , wtxhash));
302+
303+ pair<TxConflicts::iterator, TxConflicts::iterator> range;
304+ range = mapTxConflicts.equal_range (txin.prevout );
305+ if (range.first != range.second )
306+ SyncMetaData (range);
307+ }
308+ }
309+
234310bool CWallet::EncryptWallet (const SecureString& strWalletPassphrase)
235311{
236312 if (IsCrypted ())
@@ -385,9 +461,16 @@ void CWallet::MarkDirty()
385461 }
386462}
387463
388- bool CWallet::AddToWallet (const CWalletTx& wtxIn)
464+ bool CWallet::AddToWallet (const CWalletTx& wtxIn, bool fFromLoadWallet )
389465{
390466 uint256 hash = wtxIn.GetHash ();
467+
468+ if (fFromLoadWallet )
469+ {
470+ mapWallet[hash] = wtxIn;
471+ AddToConflicts (hash);
472+ }
473+ else
391474 {
392475 LOCK (cs_wallet);
393476 // Inserts only if not already there, returns tx inserted or tx found
@@ -445,6 +528,7 @@ bool CWallet::AddToWallet(const CWalletTx& wtxIn)
445528 wtxIn.GetHash ().ToString (),
446529 wtxIn.hashBlock .ToString ());
447530 }
531+ AddToConflicts (hash);
448532 }
449533
450534 bool fUpdated = false ;
@@ -907,6 +991,18 @@ void CWalletTx::RelayWalletTransaction()
907991 }
908992}
909993
994+ set<uint256> CWalletTx::GetConflicts () const
995+ {
996+ set<uint256> result;
997+ if (pwallet != NULL )
998+ {
999+ uint256 myHash = GetHash ();
1000+ result = pwallet->GetConflicts (myHash);
1001+ result.erase (myHash);
1002+ }
1003+ return result;
1004+ }
1005+
9101006void CWallet::ResendWalletTransactions ()
9111007{
9121008 // Do this infrequently and randomly to avoid giving away
@@ -980,7 +1076,7 @@ int64_t CWallet::GetUnconfirmedBalance() const
9801076 for (map<uint256, CWalletTx>::const_iterator it = mapWallet.begin (); it != mapWallet.end (); ++it)
9811077 {
9821078 const CWalletTx* pcoin = &(*it).second ;
983- if (!IsFinalTx (*pcoin) || !pcoin->IsTrusted ())
1079+ if (!IsFinalTx (*pcoin) || ( !pcoin->IsTrusted () && pcoin-> GetDepthInMainChain () == 0 ))
9841080 nTotal += pcoin->GetAvailableCredit ();
9851081 }
9861082 }
0 commit comments