From e80c359f84fc3f1682ca9ecf591dc2f663e96af2 Mon Sep 17 00:00:00 2001 From: moneroexamples Date: Sat, 10 Dec 2016 09:07:50 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E2=80=98asnlSig=E2=80=99=20is=20not=20a?= =?UTF-8?q?=20member=20of=20=E2=80=98rct=E2=80=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.cpp | 4 +- src/MySqlConnector.h | 191 +++++++++++++++++++++---------------------- src/tools.cpp | 2 +- 3 files changed, 95 insertions(+), 102 deletions(-) diff --git a/main.cpp b/main.cpp index 80016d2..c8b1f06 100644 --- a/main.cpp +++ b/main.cpp @@ -15,12 +15,12 @@ using namespace restbed; int main() { - xmreg::MySqlAccounts xmr_accounts; + xmreg::MySqlConnector xmr_accounts; //xmr_accounts.create_account("41vEA7Ye8Bpeda6g59v5t46koWrVn2PNgEKgzquJjmiKCFTsh9gajr8J3pad49rqu581TAtFGCH9CYTCkYrCpuWUG9GkgeB"); - xmr_accounts.select_account("41vEA7Ye8Bpeda6g59v5t46koWrVn2PNgEKgzquJjmiKCFTsh9gajr8J3pad49rqu581TAtFGCH9CYTCkYrCpuWUG9GkgeB"); + //xmr_accounts.select_account("41vEA7Ye8Bpeda6g59v5t46koWrVn2PNgEKgzquJjmiKCFTsh9gajr8J3pad49rqu581TAtFGCH9CYTCkYrCpuWUG9GkgeB"); diff --git a/src/MySqlConnector.h b/src/MySqlConnector.h index 1d10295..4d63017 100644 --- a/src/MySqlConnector.h +++ b/src/MySqlConnector.h @@ -5,25 +5,17 @@ #ifndef RESTBED_XMR_MYSQLCONNECTOR_H #define RESTBED_XMR_MYSQLCONNECTOR_H -#include -#include - - -#include "mysql_connection.h" - -#include -#include -#include -#include -#include +#include +#include +#include namespace xmreg { -using namespace sql; +using namespace mysqlpp; using namespace std; @@ -62,9 +54,8 @@ class MySqlConnector string dbname; protected: - Driver* driver; - unique_ptr con; + Connection conn; public: MySqlConnector( @@ -84,96 +75,98 @@ public: void connect() { - Driver* driver = get_driver_instance(); - con = unique_ptr(driver->connect(url, username, password)); - con->setSchema(dbname); - } - -}; - - -class MySqlAccounts: public MySqlConnector -{ - static constexpr const char* TABLE_NAME = "Accounts"; - - static constexpr const char* INSERT_STMT = R"( - INSERT INTO `Accounts` (`address`) VALUES (?) - )"; - - static constexpr const char* SELECT_STMT = R"( - SELECT * FROM `Accounts` WHERE `address` = ? - )"; - -public: - MySqlAccounts(): MySqlConnector() {} - - - bool - select_account(const string& address) - { - mysql_unqiue_ptr prep_stmt {con->prepareStatement(SELECT_STMT)}; - - prep_stmt->setString(1, address); - - try - { - unique_ptr res {prep_stmt->executeQuery()}; - - cout << res->getRow() << endl; - - } - catch (SQLException& e) - { - MYSQL_EXCEPTION_MSG(e); - return false; - } - - return true; - } - - bool - create_account(const string& address) - { - mysql_unqiue_ptr prep_stmt {con->prepareStatement(SELECT_STMT)}; - - prep_stmt->setString(1, address); - - try - { - prep_stmt->execute(); - } - catch (SQLException& e) + if (conn.connect(dbname.c_str(), url.c_str(), + username.c_str(), password.c_str())) { - MYSQL_EXCEPTION_MSG(e); - return false; + cout << "connection successful" << endl; } - - return true; - } - - bool - update_account( - const string& address, - const uint64_t& total_recieved = 0, - const uint64_t& total_sent = 0, - const uint64_t& scanned_height = 0, - const uint64_t& scanned_block_height = 0, - const uint64_t& start_height = 0, - const uint64_t& transaction_height = 0, - const uint64_t& blockchain_height = 0 - ) - { - mysql_unqiue_ptr prep_stmt(con->prepareStatement(INSERT_STMT)); - - prep_stmt->setString(1, address); - prep_stmt->setUInt64(2, total_recieved); - prep_stmt->setString(3, "a"); - prep_stmt->execute(); - - return false; } }; +// +// +//class MySqlAccounts: public MySqlConnector +//{ +// static constexpr const char* TABLE_NAME = "Accounts"; +// +// static constexpr const char* INSERT_STMT = R"( +// INSERT INTO `Accounts` (`address`) VALUES (?) +// )"; +// +// static constexpr const char* SELECT_STMT = R"( +// SELECT * FROM `Accounts` WHERE `address` = ? +// )"; +// +//public: +// MySqlAccounts(): MySqlConnector() {} +// +// +// bool +// select_account(const string& address) +// { +// mysql_unqiue_ptr prep_stmt {con->prepareStatement(SELECT_STMT)}; +// +// prep_stmt->setString(1, address); +// +// try +// { +// unique_ptr res {prep_stmt->executeQuery()}; +// +// cout << res->getRow() << endl; +// +// } +// catch (SQLException& e) +// { +// MYSQL_EXCEPTION_MSG(e); +// return false; +// } +// +// return true; +// } +// +// bool +// create_account(const string& address) +// { +// mysql_unqiue_ptr prep_stmt {con->prepareStatement(SELECT_STMT)}; +// +// prep_stmt->setString(1, address); +// +// try +// { +// prep_stmt->execute(); +// } +// catch (SQLException& e) +// { +// MYSQL_EXCEPTION_MSG(e); +// return false; +// } +// +// return true; +// } +// +// bool +// update_account( +// const string& address, +// const uint64_t& total_recieved = 0, +// const uint64_t& total_sent = 0, +// const uint64_t& scanned_height = 0, +// const uint64_t& scanned_block_height = 0, +// const uint64_t& start_height = 0, +// const uint64_t& transaction_height = 0, +// const uint64_t& blockchain_height = 0 +// ) +// { +// mysql_unqiue_ptr prep_stmt(con->prepareStatement(INSERT_STMT)); +// +// prep_stmt->setString(1, address); +// prep_stmt->setUInt64(2, total_recieved); +// prep_stmt->setString(3, "a"); +// prep_stmt->execute(); +// +// return false; +// } +// +//}; } diff --git a/src/tools.cpp b/src/tools.cpp index cc70900..e4357da 100644 --- a/src/tools.cpp +++ b/src/tools.cpp @@ -1167,7 +1167,7 @@ make_tx_from_json(const string& json_str, transaction& tx) for (json& range_s: j["rctsig_prunable"]["rangeSigs"]) { - rct::asnlSig asig; + rct::boroSig asig; if (!epee::string_tools::hex_to_pod(range_s["asig"], asig)) {