Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/wallet.cpp
Show First 20 Lines • Show All 943 Lines • ▼ Show 20 Lines | #endif | ||||
// Thread runs free. | // Thread runs free. | ||||
t.detach(); | t.detach(); | ||||
} | } | ||||
#endif | #endif | ||||
return &wtx; | return &wtx; | ||||
} | } | ||||
void CWallet::LoadToWallet(CWalletTx &wtxIn) { | bool CWallet::LoadToWallet(const TxId &txid, const UpdateWalletTxFn &fill_wtx) { | ||||
const auto &ins = | |||||
mapWallet.emplace(std::piecewise_construct, std::forward_as_tuple(txid), | |||||
std::forward_as_tuple(this, nullptr)); | |||||
CWalletTx &wtx = ins.first->second; | |||||
if (!fill_wtx(wtx, ins.second)) { | |||||
return false; | |||||
} | |||||
// If wallet doesn't have a chain (e.g wallet-tool), don't bother to update | // If wallet doesn't have a chain (e.g wallet-tool), don't bother to update | ||||
// txn. | // txn. | ||||
if (HaveChain()) { | if (HaveChain()) { | ||||
std::optional<int> block_height = | std::optional<int> block_height = | ||||
chain().getBlockHeight(wtxIn.m_confirm.hashBlock); | chain().getBlockHeight(wtx.m_confirm.hashBlock); | ||||
if (block_height) { | if (block_height) { | ||||
// Update cached block height variable since it not stored in the | // Update cached block height variable since it not stored in the | ||||
// serialized transaction. | // serialized transaction. | ||||
wtxIn.m_confirm.block_height = *block_height; | wtx.m_confirm.block_height = *block_height; | ||||
} else if (wtxIn.isConflicted() || wtxIn.isConfirmed()) { | } else if (wtx.isConflicted() || wtx.isConfirmed()) { | ||||
// If tx block (or conflicting block) was reorged out of chain | // If tx block (or conflicting block) was reorged out of chain | ||||
// while the wallet was shutdown, change tx status to UNCONFIRMED | // while the wallet was shutdown, change tx status to UNCONFIRMED | ||||
// and reset block height, hash, and index. ABANDONED tx don't have | // and reset block height, hash, and index. ABANDONED tx don't have | ||||
// associated blocks and don't need to be updated. The case where a | // associated blocks and don't need to be updated. The case where a | ||||
// transaction was reorged out while online and then reconfirmed | // transaction was reorged out while online and then reconfirmed | ||||
// while offline is covered by the rescan logic. | // while offline is covered by the rescan logic. | ||||
wtxIn.setUnconfirmed(); | wtx.setUnconfirmed(); | ||||
wtxIn.m_confirm.hashBlock = BlockHash(); | wtx.m_confirm.hashBlock = BlockHash(); | ||||
wtxIn.m_confirm.block_height = 0; | wtx.m_confirm.block_height = 0; | ||||
wtxIn.m_confirm.nIndex = 0; | wtx.m_confirm.nIndex = 0; | ||||
} | } | ||||
} | } | ||||
const TxId &txid = wtxIn.GetId(); | |||||
const auto &ins = mapWallet.emplace(txid, wtxIn); | |||||
CWalletTx &wtx = ins.first->second; | |||||
wtx.BindWallet(this); | |||||
if (/* insertion took place */ ins.second) { | if (/* insertion took place */ ins.second) { | ||||
wtx.m_it_wtxOrdered = | wtx.m_it_wtxOrdered = | ||||
wtxOrdered.insert(std::make_pair(wtx.nOrderPos, &wtx)); | wtxOrdered.insert(std::make_pair(wtx.nOrderPos, &wtx)); | ||||
} | } | ||||
AddToSpends(txid); | AddToSpends(txid); | ||||
for (const CTxIn &txin : wtx.tx->vin) { | for (const CTxIn &txin : wtx.tx->vin) { | ||||
auto it = mapWallet.find(txin.prevout.GetTxId()); | auto it = mapWallet.find(txin.prevout.GetTxId()); | ||||
if (it != mapWallet.end()) { | if (it != mapWallet.end()) { | ||||
CWalletTx &prevtx = it->second; | CWalletTx &prevtx = it->second; | ||||
if (prevtx.isConflicted()) { | if (prevtx.isConflicted()) { | ||||
MarkConflicted(prevtx.m_confirm.hashBlock, | MarkConflicted(prevtx.m_confirm.hashBlock, | ||||
prevtx.m_confirm.block_height, wtx.GetId()); | prevtx.m_confirm.block_height, wtx.GetId()); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
return true; | |||||
} | } | ||||
bool CWallet::AddToWalletIfInvolvingMe(const CTransactionRef &ptx, | bool CWallet::AddToWalletIfInvolvingMe(const CTransactionRef &ptx, | ||||
CWalletTx::Confirmation confirm, | CWalletTx::Confirmation confirm, | ||||
bool fUpdate) { | bool fUpdate) { | ||||
const CTransaction &tx = *ptx; | const CTransaction &tx = *ptx; | ||||
AssertLockHeld(cs_wallet); | AssertLockHeld(cs_wallet); | ||||
▲ Show 20 Lines • Show All 4,045 Lines • Show Last 20 Lines |