Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/wallet.cpp
Show First 20 Lines • Show All 1,163 Lines • ▼ Show 20 Lines | |||||
bool CWallet::TransactionCanBeAbandoned(const TxId &txid) const { | bool CWallet::TransactionCanBeAbandoned(const TxId &txid) const { | ||||
LOCK2(cs_main, cs_wallet); | LOCK2(cs_main, cs_wallet); | ||||
const CWalletTx *wtx = GetWalletTx(txid); | const CWalletTx *wtx = GetWalletTx(txid); | ||||
return wtx && !wtx->isAbandoned() && wtx->GetDepthInMainChain() == 0 && | return wtx && !wtx->isAbandoned() && wtx->GetDepthInMainChain() == 0 && | ||||
!wtx->InMempool(); | !wtx->InMempool(); | ||||
} | } | ||||
void CWallet::MarkInputsDirty(const CTransactionRef &tx) { | |||||
for (const CTxIn &txin : tx->vin) { | |||||
auto it = mapWallet.find(txin.prevout.GetTxId()); | |||||
if (it != mapWallet.end()) { | |||||
it->second.MarkDirty(); | |||||
} | |||||
} | |||||
} | |||||
bool CWallet::AbandonTransaction(const TxId &txid) { | bool CWallet::AbandonTransaction(const TxId &txid) { | ||||
LOCK2(cs_main, cs_wallet); | LOCK2(cs_main, cs_wallet); | ||||
WalletBatch batch(*database, "r+"); | WalletBatch batch(*database, "r+"); | ||||
std::set<TxId> todo; | std::set<TxId> todo; | ||||
std::set<TxId> done; | std::set<TxId> done; | ||||
Show All 37 Lines | while (!todo.empty()) { | ||||
todo.insert(iter->second); | todo.insert(iter->second); | ||||
} | } | ||||
iter++; | iter++; | ||||
} | } | ||||
// If a transaction changes 'conflicted' state, that changes the | // If a transaction changes 'conflicted' state, that changes the | ||||
// balance available of the outputs it spends. So force those to be | // balance available of the outputs it spends. So force those to be | ||||
// recomputed. | // recomputed. | ||||
for (const CTxIn &txin : wtx.tx->vin) { | MarkInputsDirty(wtx.tx); | ||||
auto it2 = mapWallet.find(txin.prevout.GetTxId()); | |||||
if (it2 != mapWallet.end()) { | |||||
it2->second.MarkDirty(); | |||||
} | |||||
} | |||||
} | } | ||||
} | } | ||||
return true; | return true; | ||||
} | } | ||||
void CWallet::MarkConflicted(const BlockHash &hashBlock, const TxId &txid) { | void CWallet::MarkConflicted(const BlockHash &hashBlock, const TxId &txid) { | ||||
LOCK2(cs_main, cs_wallet); | LOCK2(cs_main, cs_wallet); | ||||
▲ Show 20 Lines • Show All 42 Lines • ▼ Show 20 Lines | while (!todo.empty()) { | ||||
if (!done.count(iter->second)) { | if (!done.count(iter->second)) { | ||||
todo.insert(iter->second); | todo.insert(iter->second); | ||||
} | } | ||||
iter++; | iter++; | ||||
} | } | ||||
// If a transaction changes 'conflicted' state, that changes the | // If a transaction changes 'conflicted' state, that changes the | ||||
// balance available of the outputs it spends. So force those to be | // balance available of the outputs it spends. So force those to be | ||||
// recomputed. | // recomputed. | ||||
for (const CTxIn &txin : wtx.tx->vin) { | MarkInputsDirty(wtx.tx); | ||||
auto it2 = mapWallet.find(txin.prevout.GetTxId()); | |||||
if (it2 != mapWallet.end()) { | |||||
it2->second.MarkDirty(); | |||||
} | |||||
} | |||||
} | } | ||||
} | } | ||||
} | } | ||||
void CWallet::SyncTransaction(const CTransactionRef &ptx, | void CWallet::SyncTransaction(const CTransactionRef &ptx, | ||||
const CBlockIndex *pindex, int posInBlock, | const CBlockIndex *pindex, int posInBlock, | ||||
bool update_tx) { | bool update_tx) { | ||||
const CTransaction &tx = *ptx; | const CTransaction &tx = *ptx; | ||||
if (!AddToWalletIfInvolvingMe(ptx, pindex, posInBlock, update_tx)) { | if (!AddToWalletIfInvolvingMe(ptx, pindex, posInBlock, update_tx)) { | ||||
// Not one of ours | // Not one of ours | ||||
return; | return; | ||||
} | } | ||||
// If a transaction changes 'conflicted' state, that changes the balance | // If a transaction changes 'conflicted' state, that changes the balance | ||||
// available of the outputs it spends. So force those to be | // available of the outputs it spends. So force those to be | ||||
// recomputed, also: | // recomputed, also: | ||||
for (const CTxIn &txin : tx.vin) { | MarkInputsDirty(ptx); | ||||
auto it = mapWallet.find(txin.prevout.GetTxId()); | |||||
if (it != mapWallet.end()) { | |||||
it->second.MarkDirty(); | |||||
} | |||||
} | |||||
} | } | ||||
void CWallet::TransactionAddedToMempool(const CTransactionRef &ptx) { | void CWallet::TransactionAddedToMempool(const CTransactionRef &ptx) { | ||||
LOCK2(cs_main, cs_wallet); | LOCK2(cs_main, cs_wallet); | ||||
SyncTransaction(ptx); | SyncTransaction(ptx); | ||||
auto it = mapWallet.find(ptx->GetId()); | auto it = mapWallet.find(ptx->GetId()); | ||||
if (it != mapWallet.end()) { | if (it != mapWallet.end()) { | ||||
▲ Show 20 Lines • Show All 3,587 Lines • Show Last 20 Lines |