Outputs table added

pull/1/head
moneroexamples 8 years ago
parent cd961c9ea2
commit 693bcc3eb0

@ -26,6 +26,102 @@ using namespace std;
using namespace nlohmann;
class MysqlOutpus
{
shared_ptr<MySqlConnector> conn;
public:
MysqlOutpus(shared_ptr<MySqlConnector> _conn): conn {_conn}
{}
bool
select(const uint64_t& address_id, vector<XmrOutput>& outs)
{
//
// 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 = conn->query(XmrOutput::SELECT_STMT);
query.parse();
try
{
query.storein(outs, address_id);
if (!outs.empty())
{
return true;
}
}
catch (mysqlpp::Exception& e)
{
MYSQL_EXCEPTION_MSG(e);
}
catch (std::exception& e)
{
MYSQL_EXCEPTION_MSG(e);
}
return false;
}
uint64_t
insert(const XmrOutput& out_data)
{
// static shared_ptr<Query> query;
//
// if (!query)
// {
// Query q = MySqlConnector::getInstance().query(XmrOutput::INSERT_STMT);
// q.parse();
// query = shared_ptr<Query>(new Query(q));
// }
Query query = conn->query(XmrOutput::INSERT_STMT);
query.parse();
// cout << query << endl;
try
{
SimpleResult sr = query.execute(out_data.account_id,
out_data.tx_id,
out_data.tx_pub_key,
out_data.out_index,
out_data.mixin,
out_data.timestamp);
if (sr.rows() == 1)
return sr.insert_id();
}
catch (mysqlpp::Exception& e)
{
MYSQL_EXCEPTION_MSG(e);
return 0;
}
return 0;
}
};
class MysqlTransactions
{

@ -84,6 +84,7 @@ struct XmrAccount : public Accounts
return j;
}
friend std::ostream& operator<< (std::ostream& stream, const XmrAccount& acc);
};
@ -176,7 +177,57 @@ ostream& operator<< (std::ostream& os, const XmrTransaction& acc) {
};
sql_create_7(Outputs, 1, 3,
sql_bigint_unsigned, id,
sql_bigint_unsigned, account_id,
sql_bigint_unsigned, tx_id,
sql_varchar , tx_pub_key,
sql_bigint_unsigned, out_index,
sql_bigint_unsigned, mixin,
sql_timestamp , timestamp);
struct XmrOutput : public Outputs
{
static constexpr const char* SELECT_STMT = R"(
SELECT * FROM `Outputs` WHERE `account_id` = (%0q)
)";
static constexpr const char* INSERT_STMT = R"(
INSERT IGNORE INTO `Outputs` (`account_id`, `tx_id`, `tx_pub_key`, `out_index`, `mixin`, `timestamp`)
VALUES (%0q, %1q, %2q,
%3q, %4q, %5q);
)";
using Outputs::Outputs;
json
to_json() const
{
json j {{"id" , id},
{"account_id" , account_id},
{"tx_id" , tx_id},
{"tx_pub_key" , tx_pub_key},
{"out_index" , out_index},
{"mixin" , mixin},
{"timestamp" , timestamp}
};
return j;
}
friend std::ostream& operator<< (std::ostream& stream, const XmrOutput& out);
};
ostream& operator<< (std::ostream& os, const XmrOutput& out) {
os << "XmrOutputs: " << out.to_json().dump() << '\n';
return os;
};
}

Loading…
Cancel
Save