From 7712367410d55446e56e9847fe05520e996e468f Mon Sep 17 00:00:00 2001 From: moneroexamples Date: Fri, 6 Jan 2017 01:27:58 +0000 Subject: [PATCH] before adding tx, check if it already exists --- src/CurrentBlockchainStatus.h | 14 ++++++++++++++ src/MySqlAccounts.h | 8 ++++---- src/ssqlses.h | 2 +- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/CurrentBlockchainStatus.h b/src/CurrentBlockchainStatus.h index 4fae2a4..4d4d6d0 100644 --- a/src/CurrentBlockchainStatus.h +++ b/src/CurrentBlockchainStatus.h @@ -791,8 +791,22 @@ public: if (!found_mine_outputs.empty()) { + // before adding this tx and its outputs to mysql + // check if it already exists. So that we dont + // do it twice. + XmrTransaction tx_data; + if (xmr_accounts->tx_exists(acc.id, tx_hash_str, tx_data)) + { + cout << "\nTransaction " << tx_hash_str + << " already present in mysql" + << endl; + + continue; + } + + tx_data.hash = tx_hash_str; tx_data.prefix_hash = tx_prefix_hash_str; tx_data.account_id = acc.id; diff --git a/src/MySqlAccounts.h b/src/MySqlAccounts.h index 7b609fe..4f414c3 100644 --- a/src/MySqlAccounts.h +++ b/src/MySqlAccounts.h @@ -475,7 +475,7 @@ public: bool - exist(const string& tx_hash_str, XmrTransaction& tx) + exist(const uint64_t& account_id, const string& tx_hash_str, XmrTransaction& tx) { Query query = conn->query(XmrTransaction::EXIST_STMT); @@ -486,7 +486,7 @@ public: vector outs; - query.storein(outs, tx_hash_str); + query.storein(outs, account_id, tx_hash_str); if (outs.empty()) { @@ -904,9 +904,9 @@ public: } bool - tx_exists(const string& tx_hash_str, XmrTransaction& tx) + tx_exists(const uint64_t& account_id, const string& tx_hash_str, XmrTransaction& tx) { - return mysql_tx->exist(tx_hash_str, tx); + return mysql_tx->exist(account_id, tx_hash_str, tx); } uint64_t diff --git a/src/ssqlses.h b/src/ssqlses.h index 5907f63..d3150d1 100644 --- a/src/ssqlses.h +++ b/src/ssqlses.h @@ -115,7 +115,7 @@ struct XmrTransaction : public Transactions )"; static constexpr const char* EXIST_STMT = R"( - SELECT * FROM `Transactions` WHERE `hash` = (%0q) + SELECT * FROM `Transactions` WHERE `account_id` = (%0q) AND `hash` = (%1q) )"; static constexpr const char* INSERT_STMT = R"(