|
|
|
@ -108,22 +108,25 @@ class MysqlTransactions
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
select(const string& address, vector<XmrTransaction>& txs)
|
|
|
|
|
select(const uint64_t& address_id, vector<XmrTransaction>& txs)
|
|
|
|
|
{
|
|
|
|
|
//
|
|
|
|
|
// static shared_ptr<Query> query;
|
|
|
|
|
//
|
|
|
|
|
// if (!query)
|
|
|
|
|
// {
|
|
|
|
|
// Query q = MySqlConnector::getInstance().query(
|
|
|
|
|
// XmrTransaction::SELECT_STMT);
|
|
|
|
|
// q.parse();
|
|
|
|
|
// query = shared_ptr<Query>(new Query(q));
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
static shared_ptr<Query> query;
|
|
|
|
|
|
|
|
|
|
if (!query)
|
|
|
|
|
{
|
|
|
|
|
Query q = MySqlConnector::getInstance().query(
|
|
|
|
|
XmrTransaction::SELECT_STMT);
|
|
|
|
|
q.parse();
|
|
|
|
|
query = shared_ptr<Query>(new Query(q));
|
|
|
|
|
}
|
|
|
|
|
Query query = MySqlConnector::getInstance().query(XmrTransaction::SELECT_STMT);
|
|
|
|
|
query.parse();
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
query->storein(txs, address);
|
|
|
|
|
query.storein(txs, address_id);
|
|
|
|
|
|
|
|
|
|
if (!txs.empty())
|
|
|
|
|
{
|
|
|
|
@ -142,6 +145,53 @@ public:
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
uint64_t
|
|
|
|
|
insert(const XmrTransaction& tx_data)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
// static shared_ptr<Query> query;
|
|
|
|
|
//
|
|
|
|
|
// if (!query)
|
|
|
|
|
// {
|
|
|
|
|
// Query q = MySqlConnector::getInstance().query(XmrTransaction::INSERT_STMT);
|
|
|
|
|
// q.parse();
|
|
|
|
|
// query = shared_ptr<Query>(new Query(q));
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Query query = MySqlConnector::getInstance().query(XmrTransaction::INSERT_STMT);
|
|
|
|
|
query.parse();
|
|
|
|
|
|
|
|
|
|
// cout << query << endl;
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
SimpleResult sr = query.execute(tx_data.hash,
|
|
|
|
|
tx_data.account_id,
|
|
|
|
|
tx_data.total_received,
|
|
|
|
|
tx_data.total_sent,
|
|
|
|
|
tx_data.unlock_time,
|
|
|
|
|
tx_data.height,
|
|
|
|
|
tx_data.coinbase,
|
|
|
|
|
tx_data.payment_id,
|
|
|
|
|
tx_data.mixin,
|
|
|
|
|
tx_data.timestamp);
|
|
|
|
|
|
|
|
|
|
if (sr.rows() == 1)
|
|
|
|
|
return sr.insert_id();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
catch (mysqlpp::Exception& e)
|
|
|
|
|
{
|
|
|
|
|
MYSQL_EXCEPTION_MSG(e);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -149,6 +199,8 @@ public:
|
|
|
|
|
class MySqlAccounts
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
MysqlTransactions mysql_tx;
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -156,22 +208,22 @@ public:
|
|
|
|
|
select(const string& address, XmrAccount& account)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
static shared_ptr<Query> query;
|
|
|
|
|
|
|
|
|
|
if (!query)
|
|
|
|
|
{
|
|
|
|
|
Query q = MySqlConnector::getInstance().query(XmrAccount::SELECT_STMT);
|
|
|
|
|
q.parse();
|
|
|
|
|
query = shared_ptr<Query>(new Query(q));
|
|
|
|
|
}
|
|
|
|
|
// static shared_ptr<Query> query;
|
|
|
|
|
//
|
|
|
|
|
// if (!query)
|
|
|
|
|
// {
|
|
|
|
|
// Query q = MySqlConnector::getInstance().query(XmrAccount::SELECT_STMT);
|
|
|
|
|
// q.parse();
|
|
|
|
|
// query = shared_ptr<Query>(new Query(q));
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// Query query = conn.query(XmrAccount::SELECT_STMT);
|
|
|
|
|
// query.parse();
|
|
|
|
|
Query query = MySqlConnector::getInstance().query(XmrAccount::SELECT_STMT);
|
|
|
|
|
query.parse();
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
vector<XmrAccount> res;
|
|
|
|
|
query->storein(res, address);
|
|
|
|
|
query.storein(res, address);
|
|
|
|
|
|
|
|
|
|
if (!res.empty())
|
|
|
|
|
{
|
|
|
|
@ -196,22 +248,22 @@ public:
|
|
|
|
|
select(const int64_t& acc_id, XmrAccount& account)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
static shared_ptr<Query> query;
|
|
|
|
|
//static shared_ptr<Query> query;
|
|
|
|
|
|
|
|
|
|
if (!query)
|
|
|
|
|
{
|
|
|
|
|
Query q = MySqlConnector::getInstance().query(XmrAccount::SELECT_STMT2);
|
|
|
|
|
q.parse();
|
|
|
|
|
query = shared_ptr<Query>(new Query(q));
|
|
|
|
|
}
|
|
|
|
|
// if (!query)
|
|
|
|
|
// {
|
|
|
|
|
// Query q = MySqlConnector::getInstance().query(XmrAccount::SELECT_STMT2);
|
|
|
|
|
// q.parse();
|
|
|
|
|
// query = shared_ptr<Query>(new Query(q));
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// Query query = conn.query(XmrAccount::SELECT_STMT2);
|
|
|
|
|
// query.parse();
|
|
|
|
|
Query query = MySqlConnector::getInstance().query(XmrAccount::SELECT_STMT2);
|
|
|
|
|
query.parse();
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
vector<XmrAccount> res;
|
|
|
|
|
query->storein(res, acc_id);
|
|
|
|
|
query.storein(res, acc_id);
|
|
|
|
|
|
|
|
|
|
if (!res.empty())
|
|
|
|
|
{
|
|
|
|
@ -232,24 +284,24 @@ public:
|
|
|
|
|
insert(const string& address, const uint64_t& scanned_block_height = 0)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
static shared_ptr<Query> query;
|
|
|
|
|
// static shared_ptr<Query> query;
|
|
|
|
|
|
|
|
|
|
if (!query)
|
|
|
|
|
{
|
|
|
|
|
Query q = MySqlConnector::getInstance().query(XmrAccount::INSERT_STMT);
|
|
|
|
|
q.parse();
|
|
|
|
|
query = shared_ptr<Query>(new Query(q));
|
|
|
|
|
}
|
|
|
|
|
// if (!query)
|
|
|
|
|
// {
|
|
|
|
|
// Query q = MySqlConnector::getInstance().query(XmrAccount::INSERT_STMT);
|
|
|
|
|
// q.parse();
|
|
|
|
|
// query = shared_ptr<Query>(new Query(q));
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Query query = conn.query(XmrAccount::INSERT_STMT);
|
|
|
|
|
// query.parse();
|
|
|
|
|
Query query = MySqlConnector::getInstance().query(XmrAccount::INSERT_STMT);
|
|
|
|
|
query.parse();
|
|
|
|
|
|
|
|
|
|
// cout << query << endl;
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
SimpleResult sr = query->execute(address, scanned_block_height);
|
|
|
|
|
SimpleResult sr = query.execute(address, scanned_block_height);
|
|
|
|
|
|
|
|
|
|
if (sr.rows() == 1)
|
|
|
|
|
return sr.insert_id();
|
|
|
|
@ -264,6 +316,39 @@ public:
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint64_t
|
|
|
|
|
insert_tx(const XmrTransaction& tx_data)
|
|
|
|
|
{
|
|
|
|
|
return mysql_tx.insert(tx_data);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
select_txs(const string& xmr_address, vector<XmrTransaction>& txs)
|
|
|
|
|
{
|
|
|
|
|
// having address first get its address_id
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// a placeholder for exciting or new account data
|
|
|
|
|
xmreg::XmrAccount acc;
|
|
|
|
|
|
|
|
|
|
// select this account if its existing one
|
|
|
|
|
if (!select(xmr_address, acc))
|
|
|
|
|
{
|
|
|
|
|
cerr << "Address" << xmr_address << "does not exist in database" << endl;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return mysql_tx.select(acc.id, txs);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
select_txs(const uint64_t& account_id, vector<XmrTransaction>& txs)
|
|
|
|
|
{
|
|
|
|
|
return mysql_tx.select(account_id, txs);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
update(XmrAccount& acc_orginal, XmrAccount& acc_new)
|
|
|
|
|
{
|
|
|
|
|