MCPcopy Create free account
hub / github.com/ElementsProject/elements / LoadToWallet

Method LoadToWallet

src/wallet/wallet.cpp:1045–1087  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1043}
1044
1045bool CWallet::LoadToWallet(const uint256& hash, const UpdateWalletTxFn& fill_wtx)
1046{
1047 const auto& ins = mapWallet.emplace(std::piecewise_construct, std::forward_as_tuple(hash), std::forward_as_tuple(nullptr, TxStateInactive{}));
1048 CWalletTx& wtx = ins.first->second;
1049 if (!fill_wtx(wtx, ins.second)) {
1050 return false;
1051 }
1052 // If wallet doesn't have a chain (e.g when using bitcoin-wallet tool),
1053 // don't bother to update txn.
1054 if (HaveChain()) {
1055 bool active;
1056 auto lookup_block = [&](const uint256& hash, int& height, TxState& state) {
1057 // If tx block (or conflicting block) was reorged out of chain
1058 // while the wallet was shutdown, change tx status to UNCONFIRMED
1059 // and reset block height, hash, and index. ABANDONED tx don't have
1060 // associated blocks and don't need to be updated. The case where a
1061 // transaction was reorged out while online and then reconfirmed
1062 // while offline is covered by the rescan logic.
1063 if (!chain().findBlock(hash, FoundBlock().inActiveChain(active).height(height)) || !active) {
1064 state = TxStateInactive{};
1065 }
1066 };
1067 if (auto* conf = wtx.state<TxStateConfirmed>()) {
1068 lookup_block(conf->confirmed_block_hash, conf->confirmed_block_height, wtx.m_state);
1069 } else if (auto* conf = wtx.state<TxStateConflicted>()) {
1070 lookup_block(conf->conflicting_block_hash, conf->conflicting_block_height, wtx.m_state);
1071 }
1072 }
1073 if (/* insertion took place */ ins.second) {
1074 wtx.m_it_wtxOrdered = wtxOrdered.insert(std::make_pair(wtx.nOrderPos, &wtx));
1075 }
1076 AddToSpends(hash);
1077 for (const CTxIn& txin : wtx.tx->vin) {
1078 auto it = mapWallet.find(txin.prevout.hash);
1079 if (it != mapWallet.end()) {
1080 CWalletTx& prevtx = it->second;
1081 if (auto* prev = prevtx.state<TxStateConflicted>()) {
1082 MarkConflicted(prev->conflicting_block_hash, prev->conflicting_block_height, wtx.GetHash());
1083 }
1084 }
1085 }
1086 return true;
1087}
1088
1089bool CWallet::AddToWalletIfInvolvingMe(const CTransactionRef& ptx, const SyncTxState& state, bool fUpdate, bool rescanning_old_block)
1090{

Callers 1

walletdb.cppFile · 0.80

Calls 7

FoundBlockClass · 0.85
findBlockMethod · 0.80
findMethod · 0.80
heightMethod · 0.45
insertMethod · 0.45
endMethod · 0.45
GetHashMethod · 0.45

Tested by

no test coverage detected