diff --git a/CMakeLists.txt b/CMakeLists.txt index ebb18cf..40895be 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -32,6 +32,8 @@ include_directories( ${MONERO_HEADERS_DIR}/contrib/epee/include ${MONERO_HEADERS_DIR}/external/db_drivers/liblmdb) +include_directories(/usr/include/mysql) + # get individual monero static libraries # that are needed in this project @@ -88,7 +90,8 @@ set(SOURCE_FILES add_executable(restbed_xmr ${SOURCE_FILES}) -target_link_libraries(restbed_xmr + +target_link_libraries(restbed_xmr PRIVATE myxrm myext restbed @@ -101,7 +104,8 @@ target_link_libraries(restbed_xmr lmdb ringct common - mysqlcppconn + mysqlpp + mysqlclient ${Boost_LIBRARIES} pthread unbound diff --git a/main.cpp b/main.cpp index c8b1f06..d029c72 100644 --- a/main.cpp +++ b/main.cpp @@ -15,12 +15,29 @@ using namespace restbed; int main() { - xmreg::MySqlConnector xmr_accounts; + xmreg::MySqlAccounts xmr_accounts; //xmr_accounts.create_account("41vEA7Ye8Bpeda6g59v5t46koWrVn2PNgEKgzquJjmiKCFTsh9gajr8J3pad49rqu581TAtFGCH9CYTCkYrCpuWUG9GkgeB"); - //xmr_accounts.select_account("41vEA7Ye8Bpeda6g59v5t46koWrVn2PNgEKgzquJjmiKCFTsh9gajr8J3pad49rqu581TAtFGCH9CYTCkYrCpuWUG9GkgeB"); + + xmreg::Account acc; + + bool r = xmr_accounts.select_account("41vEA7Ye8Bpeda6g9v5t46koWrVn2PNgEKgzquJjmiKCFTsh9gajr8J3pad49rqu581TAtFGCH9CYTCkYrCpuWUG9GkgeB", acc); + + if (r) + { + cout << "Account foudn: " << acc.id << endl; + } + else + { + cout << "Account does not exist" << endl; + } + + + + + diff --git a/src/MySqlConnector.h b/src/MySqlConnector.h index 4d63017..41c03a7 100644 --- a/src/MySqlConnector.h +++ b/src/MySqlConnector.h @@ -7,6 +7,8 @@ #include +#include + #include #include @@ -22,8 +24,6 @@ using namespace std; #define MYSQL_EXCEPTION_MSG(sql_excetption) cerr << "# ERR: SQLException in " << __FILE__ \ << "(" << __FUNCTION__ << ") on line " << __LINE__ << endl \ << "# ERR: " << sql_excetption.what() \ - << " (MySQL error code: " < 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; -// } -// + + + +// to see what it does can run preprecoess on this file +// g++ -I/usr/include/mysql -E ~/restbed-xmr/src/MySqlConnector.h > /tmp/out.h +sql_create_11(AccountRow, 1, 0, + sql_int_unsigned , id, + sql_varchar , address, + sql_bigint_unsigned, total_received, + sql_bigint_unsigned, scanned_height, + sql_bigint_unsigned, scanned_block_height, + sql_bigint_unsigned, start_height, + sql_bigint_unsigned, transaction_height, + sql_bigint_unsigned, blockchain_height, + sql_bigint_unsigned, total_sent, + sql_timestamp , created, + sql_timestamp , modified); + +struct Account : public AccountRow +{ + using AccountRow::AccountRow; +}; + + + +class MySqlAccounts: public MySqlConnector +{ + static constexpr const char* TABLE_NAME = "Accounts"; + + static constexpr const char* SELECT_STMT = R"( + SELECT * FROM `Accounts` WHERE `address` = (%0q) + )"; + + static constexpr const char* INSERT_STMT = R"( + INSERT INTO `Accounts` (`address`) VALUES (%0q) + )"; + + +public: + MySqlAccounts(): MySqlConnector() {} + + + bool + select_account(const string& address, Account& account) + { + + Query query = conn.query(SELECT_STMT); + query.parse(); + + try + { + vector res; + query.storein(res, address); + + if (!res.empty()) + { + account = res.at(0); + return true; + } + + } + catch (mysqlpp::Exception& e) + { + MYSQL_EXCEPTION_MSG(e); + } + + return false; + } + // bool // create_account(const string& address) // { @@ -165,8 +193,8 @@ public: // // return false; // } -// -//}; + +}; }