| 1176 | } |
| 1177 | |
| 1178 | bool CWallet::LoadToWallet(const Txid& hash, const UpdateWalletTxFn& fill_wtx) |
| 1179 | { |
| 1180 | const auto& ins = mapWallet.emplace(std::piecewise_construct, std::forward_as_tuple(hash), std::forward_as_tuple(nullptr, TxStateInactive{})); |
| 1181 | CWalletTx& wtx = ins.first->second; |
| 1182 | if (!fill_wtx(wtx, ins.second)) { |
| 1183 | return false; |
| 1184 | } |
| 1185 | // If wallet doesn't have a chain (e.g when using bitcoin-wallet tool), |
| 1186 | // don't bother to update txn. |
| 1187 | if (HaveChain()) { |
| 1188 | wtx.updateState(chain()); |
| 1189 | } |
| 1190 | if (/* insertion took place */ ins.second) { |
| 1191 | wtx.m_it_wtxOrdered = wtxOrdered.insert(std::make_pair(wtx.nOrderPos, &wtx)); |
| 1192 | } |
| 1193 | AddToSpends(wtx); |
| 1194 | for (const CTxIn& txin : wtx.tx->vin) { |
| 1195 | auto it = mapWallet.find(txin.prevout.hash); |
| 1196 | if (it != mapWallet.end()) { |
| 1197 | CWalletTx& prevtx = it->second; |
| 1198 | if (auto* prev = prevtx.state<TxStateBlockConflicted>()) { |
| 1199 | MarkConflicted(prev->conflicting_block_hash, prev->conflicting_block_height, wtx.GetHash()); |
| 1200 | } |
| 1201 | } |
| 1202 | } |
| 1203 | |
| 1204 | // Update birth time when tx time is older than it. |
| 1205 | MaybeUpdateBirthTime(wtx.GetTxTime()); |
| 1206 | |
| 1207 | // Make sure the tx outputs are known by the wallet |
| 1208 | RefreshTXOsFromTx(wtx); |
| 1209 | return true; |
| 1210 | } |
| 1211 | |
| 1212 | bool CWallet::AddToWalletIfInvolvingMe(const CTransactionRef& ptx, const SyncTxState& state, bool rescanning_old_block) |
| 1213 | { |