|
|
@ -741,29 +741,14 @@ void CWallet::MarkDirty() |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bool CWallet::AddToWallet(const CWalletTx& wtxIn, bool fFromLoadWallet, CWalletDB* pwalletdb) |
|
|
|
bool CWallet::AddToWallet(const CWalletTx& wtxIn, bool fFlushOnClose) |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
LOCK(cs_wallet); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CWalletDB walletdb(strWalletFile, "r+", fFlushOnClose); |
|
|
|
|
|
|
|
|
|
|
|
uint256 hash = wtxIn.GetHash(); |
|
|
|
uint256 hash = wtxIn.GetHash(); |
|
|
|
|
|
|
|
|
|
|
|
if (fFromLoadWallet) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
mapWallet[hash] = wtxIn; |
|
|
|
|
|
|
|
CWalletTx& wtx = mapWallet[hash]; |
|
|
|
|
|
|
|
wtx.BindWallet(this); |
|
|
|
|
|
|
|
wtxOrdered.insert(make_pair(wtx.nOrderPos, TxPair(&wtx, (CAccountingEntry*)0))); |
|
|
|
|
|
|
|
AddToSpends(hash); |
|
|
|
|
|
|
|
BOOST_FOREACH(const CTxIn& txin, wtx.vin) { |
|
|
|
|
|
|
|
if (mapWallet.count(txin.prevout.hash)) { |
|
|
|
|
|
|
|
CWalletTx& prevtx = mapWallet[txin.prevout.hash]; |
|
|
|
|
|
|
|
if (prevtx.nIndex == -1 && !prevtx.hashUnset()) { |
|
|
|
|
|
|
|
MarkConflicted(prevtx.hashBlock, wtx.GetHash()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
LOCK(cs_wallet); |
|
|
|
|
|
|
|
// Inserts only if not already there, returns tx inserted or tx found
|
|
|
|
// Inserts only if not already there, returns tx inserted or tx found
|
|
|
|
pair<map<uint256, CWalletTx>::iterator, bool> ret = mapWallet.insert(make_pair(hash, wtxIn)); |
|
|
|
pair<map<uint256, CWalletTx>::iterator, bool> ret = mapWallet.insert(make_pair(hash, wtxIn)); |
|
|
|
CWalletTx& wtx = (*ret.first).second; |
|
|
|
CWalletTx& wtx = (*ret.first).second; |
|
|
@ -772,7 +757,7 @@ bool CWallet::AddToWallet(const CWalletTx& wtxIn, bool fFromLoadWallet, CWalletD |
|
|
|
if (fInsertedNew) |
|
|
|
if (fInsertedNew) |
|
|
|
{ |
|
|
|
{ |
|
|
|
wtx.nTimeReceived = GetAdjustedTime(); |
|
|
|
wtx.nTimeReceived = GetAdjustedTime(); |
|
|
|
wtx.nOrderPos = IncOrderPosNext(pwalletdb); |
|
|
|
wtx.nOrderPos = IncOrderPosNext(&walletdb); |
|
|
|
wtxOrdered.insert(make_pair(wtx.nOrderPos, TxPair(&wtx, (CAccountingEntry*)0))); |
|
|
|
wtxOrdered.insert(make_pair(wtx.nOrderPos, TxPair(&wtx, (CAccountingEntry*)0))); |
|
|
|
|
|
|
|
|
|
|
|
wtx.nTimeSmart = wtx.nTimeReceived; |
|
|
|
wtx.nTimeSmart = wtx.nTimeReceived; |
|
|
@ -854,7 +839,7 @@ bool CWallet::AddToWallet(const CWalletTx& wtxIn, bool fFromLoadWallet, CWalletD |
|
|
|
|
|
|
|
|
|
|
|
// Write to disk
|
|
|
|
// Write to disk
|
|
|
|
if (fInsertedNew || fUpdated) |
|
|
|
if (fInsertedNew || fUpdated) |
|
|
|
if (!pwalletdb->WriteTx(wtx)) |
|
|
|
if (!walletdb.WriteTx(wtx)) |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
|
|
|
|
|
|
|
|
// Break debit/credit balance caches:
|
|
|
|
// Break debit/credit balance caches:
|
|
|
@ -872,7 +857,27 @@ bool CWallet::AddToWallet(const CWalletTx& wtxIn, bool fFromLoadWallet, CWalletD |
|
|
|
boost::thread t(runCommand, strCmd); // thread runs free
|
|
|
|
boost::thread t(runCommand, strCmd); // thread runs free
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool CWallet::LoadToWallet(const CWalletTx& wtxIn) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
uint256 hash = wtxIn.GetHash(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mapWallet[hash] = wtxIn; |
|
|
|
|
|
|
|
CWalletTx& wtx = mapWallet[hash]; |
|
|
|
|
|
|
|
wtx.BindWallet(this); |
|
|
|
|
|
|
|
wtxOrdered.insert(make_pair(wtx.nOrderPos, TxPair(&wtx, (CAccountingEntry*)0))); |
|
|
|
|
|
|
|
AddToSpends(hash); |
|
|
|
|
|
|
|
BOOST_FOREACH(const CTxIn& txin, wtx.vin) { |
|
|
|
|
|
|
|
if (mapWallet.count(txin.prevout.hash)) { |
|
|
|
|
|
|
|
CWalletTx& prevtx = mapWallet[txin.prevout.hash]; |
|
|
|
|
|
|
|
if (prevtx.nIndex == -1 && !prevtx.hashUnset()) { |
|
|
|
|
|
|
|
MarkConflicted(prevtx.hashBlock, wtx.GetHash()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -909,11 +914,7 @@ bool CWallet::AddToWalletIfInvolvingMe(const CTransaction& tx, const CBlock* pbl |
|
|
|
if (pblock) |
|
|
|
if (pblock) |
|
|
|
wtx.SetMerkleBranch(*pblock); |
|
|
|
wtx.SetMerkleBranch(*pblock); |
|
|
|
|
|
|
|
|
|
|
|
// Do not flush the wallet here for performance reasons
|
|
|
|
return AddToWallet(wtx, false); |
|
|
|
// this is safe, as in case of a crash, we rescan the necessary blocks on startup through our SetBestChain-mechanism
|
|
|
|
|
|
|
|
CWalletDB walletdb(strWalletFile, "r+", false); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return AddToWallet(wtx, false, &walletdb); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
return false; |
|
|
|
return false; |
|
|
@ -2446,17 +2447,12 @@ bool CWallet::CommitTransaction(CWalletTx& wtxNew, CReserveKey& reservekey) |
|
|
|
LOCK2(cs_main, cs_wallet); |
|
|
|
LOCK2(cs_main, cs_wallet); |
|
|
|
LogPrintf("CommitTransaction:\n%s", wtxNew.ToString()); |
|
|
|
LogPrintf("CommitTransaction:\n%s", wtxNew.ToString()); |
|
|
|
{ |
|
|
|
{ |
|
|
|
// This is only to keep the database open to defeat the auto-flush for the
|
|
|
|
|
|
|
|
// duration of this scope. This is the only place where this optimization
|
|
|
|
|
|
|
|
// maybe makes sense; please don't do it anywhere else.
|
|
|
|
|
|
|
|
CWalletDB* pwalletdb = fFileBacked ? new CWalletDB(strWalletFile,"r+") : NULL; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Take key pair from key pool so it won't be used again
|
|
|
|
// Take key pair from key pool so it won't be used again
|
|
|
|
reservekey.KeepKey(); |
|
|
|
reservekey.KeepKey(); |
|
|
|
|
|
|
|
|
|
|
|
// Add tx to wallet, because if it has change it's also ours,
|
|
|
|
// Add tx to wallet, because if it has change it's also ours,
|
|
|
|
// otherwise just for transaction history.
|
|
|
|
// otherwise just for transaction history.
|
|
|
|
AddToWallet(wtxNew, false, pwalletdb); |
|
|
|
AddToWallet(wtxNew); |
|
|
|
|
|
|
|
|
|
|
|
// Notify that old coins are spent
|
|
|
|
// Notify that old coins are spent
|
|
|
|
set<CWalletTx*> setCoins; |
|
|
|
set<CWalletTx*> setCoins; |
|
|
@ -2466,9 +2462,6 @@ bool CWallet::CommitTransaction(CWalletTx& wtxNew, CReserveKey& reservekey) |
|
|
|
coin.BindWallet(this); |
|
|
|
coin.BindWallet(this); |
|
|
|
NotifyTransactionChanged(this, coin.GetHash(), CT_UPDATED); |
|
|
|
NotifyTransactionChanged(this, coin.GetHash(), CT_UPDATED); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (fFileBacked) |
|
|
|
|
|
|
|
delete pwalletdb; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Track how many getdata requests our transaction gets
|
|
|
|
// Track how many getdata requests our transaction gets
|
|
|
|