| 276 | } |
| 277 | |
| 278 | void WalletState::fix_payment_queue_after_undo_redo() { |
| 279 | auto &by_hash_index = payment_queue.get<by_hash>(); |
| 280 | // std::cout << "by_hash_index.size=" << by_hash_index.size() << std::endl; |
| 281 | std::vector<Hash> added_to_bc; |
| 282 | std::vector<Hash> removed_from_bc; |
| 283 | bool pq_modified = false; |
| 284 | for (auto git = by_hash_index.begin(); git != by_hash_index.end(); ++git) { |
| 285 | if (git->in_blockchain() && !api_has_transaction(git->hash, false)) |
| 286 | removed_from_bc.push_back(git->hash); |
| 287 | if (!git->in_blockchain() && api_has_transaction(git->hash, false)) |
| 288 | added_to_bc.push_back(git->hash); |
| 289 | } |
| 290 | for (auto tid : removed_from_bc) { |
| 291 | auto git = by_hash_index.find(tid); |
| 292 | if (git == by_hash_index.end()) |
| 293 | continue; |
| 294 | QueueEntry entry = *git; |
| 295 | by_hash_index.erase(git); |
| 296 | entry.remove_height = 0; |
| 297 | payment_queue.insert(entry); |
| 298 | pq_modified = true; |
| 299 | add_transaction_to_mempool(tid, entry.pwtx, true); |
| 300 | } |
| 301 | for (auto tid : added_to_bc) { |
| 302 | auto git = by_hash_index.find(tid); |
| 303 | if (git == by_hash_index.end()) |
| 304 | continue; |
| 305 | api::Transaction ptx; |
| 306 | if (!api_get_transaction(tid, false, nullptr, &ptx)) |
| 307 | continue; |
| 308 | QueueEntry entry = *git; |
| 309 | by_hash_index.erase(git); |
| 310 | entry.remove_height = ptx.block_height + m_config.payment_queue_confirmations; |
| 311 | payment_queue.insert(entry); |
| 312 | pq_modified = true; |
| 313 | remove_transaction_from_mempool(tid, true); |
| 314 | } |
| 315 | auto &by_remove_height_index = payment_queue.get<by_remove_height>(); |
| 316 | // std::cout << "by_remove_height_index.size=" << by_remove_height_index.size() << std::endl; |
| 317 | auto git = by_remove_height_index.lower_bound(1); |
| 318 | while (git != by_remove_height_index.end() && get_tip_height() >= git->remove_height) { |
| 319 | m_wallet.payment_queue_remove(git->hash); |
| 320 | git = by_remove_height_index.erase(git); |
| 321 | pq_modified = true; |
| 322 | } |
| 323 | if (pq_modified) |
| 324 | m_tx_pool_version += 1; |
| 325 | } |
| 326 | |
| 327 | void WalletState::add_transaction_to_mempool(Hash tid, const PreparedWalletTransaction &pwtx, bool from_pq) { |
| 328 | const auto now = platform::now_unix_timestamp(); |
no test coverage detected