before adding tx, check if it already exists

pull/1/head
moneroexamples 7 years ago
parent 2d7aaeab77
commit 7712367410

@ -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;

@ -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<XmrTransaction> 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

@ -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"(

Loading…
Cancel
Save