diff --git a/src/CurrentBlockchainStatus.h b/src/CurrentBlockchainStatus.h index 149d7b0..4fae2a4 100644 --- a/src/CurrentBlockchainStatus.h +++ b/src/CurrentBlockchainStatus.h @@ -475,6 +475,9 @@ struct CurrentBlockchainStatus static bool ping_search_thread(const string& address); + static bool + set_new_searched_blk_no(const string& address, uint64_t new_value); + static void clean_search_thread_map(); @@ -503,6 +506,7 @@ class TxSearch uint64_t last_ping_timestamp; + atomic searched_blk_no; // represents a row in mysql's Accounts table XmrAccount acc; @@ -539,6 +543,10 @@ public: throw TxSearchException("Cant parse private key: " + acc.viewkey); } + // start searching from last block that we searched for + // this accont + searched_blk_no = acc.scanned_block_height; + ping(); } @@ -546,9 +554,7 @@ public: search() { - // start searching from last block that we searched for - // this accont - uint64_t searched_blk_no = acc.scanned_block_height; + if (searched_blk_no > CurrentBlockchainStatus::current_height) { @@ -1029,6 +1035,12 @@ public: cout << "TxSearch destroyed" << endl; } + void + set_searched_blk_no(uint64_t new_value) + { + searched_blk_no = new_value; + } + void ping() @@ -1107,6 +1119,23 @@ CurrentBlockchainStatus::ping_search_thread(const string& address) return true; } +bool +CurrentBlockchainStatus::set_new_searched_blk_no(const string& address, uint64_t new_value) +{ + std::lock_guard lck (searching_threads_map_mtx); + + if (searching_threads.count(address) == 0) + { + // thread does not exist + cout << " thread does not exist" << endl; + return false; + } + + searching_threads[address].get()->set_searched_blk_no(new_value); + + return true; +} + void CurrentBlockchainStatus::clean_search_thread_map() diff --git a/src/YourMoneroRequests.h b/src/YourMoneroRequests.h index 2cf299d..7442ab5 100644 --- a/src/YourMoneroRequests.h +++ b/src/YourMoneroRequests.h @@ -584,8 +584,20 @@ public: { // if success, set acc to updated_acc; request_fulfilled = true; + + // change search blk number in the search thread + if (!CurrentBlockchainStatus::set_new_searched_blk_no(xmr_address, 0)) + { + cerr << "Updating searched_blk_no failed!" << endl; + j_response["status"] = "Updating searched_blk_no failed!"; + } } } + else + { + cerr << "Updating accounts due to made payment mysql failed! " << endl; + j_response["status"] = "Updating accounts due to made payment mysql failed!"; + } } else {