diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index c02e4cf..64b8498 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -8,7 +8,7 @@ set(SOURCE_FILES CmdLineOptions.cpp CurrentBlockchainStatus.cpp MySqlConnector.cpp - MySqlAccounts.cpp ssqlses.cpp) + MySqlAccounts.cpp ssqlses.cpp ssqls_sql.h) # make static library called libmyxrm # that we are going to link to diff --git a/src/MySqlAccounts.h b/src/MySqlAccounts.h index 20d5dd1..9e205b4 100644 --- a/src/MySqlAccounts.h +++ b/src/MySqlAccounts.h @@ -7,7 +7,6 @@ #include "tools.h" #include "MySqlConnector.h" -//#include "ssqlses.h" #include diff --git a/src/MySqlConnector.cpp b/src/MySqlConnector.cpp index 686b815..0413349 100644 --- a/src/MySqlConnector.cpp +++ b/src/MySqlConnector.cpp @@ -4,8 +4,6 @@ #include "MySqlConnector.h" -//#include "ssqlses.h" - #include #include diff --git a/src/YourMoneroRequests.h b/src/YourMoneroRequests.h index 2dc598f..e9f8709 100644 --- a/src/YourMoneroRequests.h +++ b/src/YourMoneroRequests.h @@ -23,7 +23,7 @@ using namespace restbed; using namespace nlohmann; -string +inline string get_current_time(const char* format = "%a, %d %b %Y %H:%M:%S %Z") { @@ -36,7 +36,7 @@ get_current_time(const char* format = "%a, %d %b %Y %H:%M:%S %Z") } -multimap +inline multimap make_headers(const multimap& extra_headers = multimap()) { multimap headers { diff --git a/src/ssqls_sql.h b/src/ssqls_sql.h new file mode 100644 index 0000000..634ed94 --- /dev/null +++ b/src/ssqls_sql.h @@ -0,0 +1,102 @@ +// +// Created by mwo on 7/01/17. +// + +#ifndef RESTBED_XMR_SSQLS_RAW_H +#define RESTBED_XMR_SSQLS_RAW_H + +#include +#include + + +namespace xmreg +{ + +using namespace mysqlpp; + +// 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_7(Accounts, 1, 2, + sql_bigint_unsigned, id, + sql_varchar , address, + sql_bigint_unsigned, total_received, + sql_bigint_unsigned, scanned_block_height, + sql_bigint_unsigned, start_height, + sql_timestamp , created, + sql_timestamp , modified); + + + + +sql_create_12(Transactions, 1, 2, + sql_bigint_unsigned, id, + sql_varchar , hash, + sql_varchar , prefix_hash, + sql_bigint_unsigned, account_id, + sql_bigint_unsigned, total_received, + sql_bigint_unsigned, total_sent, + sql_bigint_unsigned, unlock_time, + sql_bigint_unsigned, height, + sql_bool , coinbase, + sql_varchar , payment_id, + sql_bigint_unsigned, mixin, + sql_timestamp , timestamp); + + + + +sql_create_10(Outputs, 1, 3, + sql_bigint_unsigned, id, + sql_bigint_unsigned, account_id, + sql_bigint_unsigned, tx_id, + sql_varchar , out_pub_key, + sql_varchar , tx_pub_key, + sql_bigint_unsigned, amount, + sql_bigint_unsigned, global_index, + sql_bigint_unsigned, out_index, + sql_bigint_unsigned, mixin, + sql_timestamp , timestamp); + + + +sql_create_7(Inputs, 1, 4, + sql_bigint_unsigned, id, + sql_bigint_unsigned, account_id, + sql_bigint_unsigned, tx_id, + sql_bigint_unsigned, output_id, + sql_varchar , key_image, + sql_bigint_unsigned, amount, + sql_timestamp , timestamp); + + + +sql_create_9(Payments, 1, 2, + sql_bigint_unsigned, id, + sql_varchar , address, + sql_varchar , payment_id, + sql_varchar , tx_hash, + sql_boolean , request_fulfilled, + sql_varchar , payment_address, + sql_bigint_unsigned, import_fee, + sql_timestamp , created, + sql_timestamp , modified); + + +// this is MySQL VIEW, based on the Transactions, +// Outputs and Inputs tables +sql_create_10(TransactionsWithOutsAndIns, 1, 2, + sql_bigint_unsigned, tx_id, + sql_bigint_unsigned, account_id, + sql_varchar , out_pub_key, + sql_bigint_unsigned, amount, + sql_bigint_unsigned, out_index, + sql_bigint_unsigned, global_index, + sql_varchar , tx_pub_key, + sql_timestamp , timestamp, + sql_varchar_null , key_image, + sql_bigint_unsigned, mixin); + + +}; + +#endif //RESTBED_XMR_SSQLSES_H \ No newline at end of file diff --git a/src/ssqlses.cpp b/src/ssqlses.cpp index b383a9a..1b11bc7 100644 --- a/src/ssqlses.cpp +++ b/src/ssqlses.cpp @@ -4,6 +4,7 @@ #include "ssqlses.h" + namespace xmreg { @@ -24,10 +25,169 @@ XmrAccount::to_json() const return j; } -ostream& operator<< (std::ostream& os, const XmrAccount& acc) { +ostream& operator<< (std::ostream& os, const XmrAccount& acc) +{ os << "XmrAccount: " << acc.to_json().dump() << '\n'; return os; }; +json +XmrTransaction::to_json() const +{ + json j {{"id" , id}, + {"hash" , hash}, + {"prefix_hash" , prefix_hash}, + {"account_id" , account_id}, + {"total_received" , total_received}, + {"total_sent" , total_sent}, + {"height" , height}, + {"payment_id" , payment_id}, + {"coinbase" , bool {coinbase}}, + {"mixin" , mixin}, + {"timestamp" , timestamp} + }; + + return j; +} + +DateTime +XmrTransaction::timestamp_to_DateTime(time_t timestamp) +{ + return DateTime(timestamp); +} + +ostream& operator<< (std::ostream& os, const XmrTransaction& acc) +{ + os << "XmrTransactions: " << acc.to_json().dump() << '\n'; + return os; +}; + + +json +XmrOutput::to_json() const +{ + json j {{"id" , id}, + {"account_id" , account_id}, + {"tx_id" , tx_id}, + {"out_pub_key" , out_pub_key}, + {"tx_pub_key" , tx_pub_key}, + {"amount" , amount}, + {"global_index" , global_index}, + {"out_index" , out_index}, + {"mixin" , mixin}, + {"timestamp" , timestamp} + }; + + return j; +} + + +ostream& operator<< (std::ostream& os, const XmrOutput& out) { + os << "XmrOutputs: " << out.to_json().dump() << '\n'; + return os; +}; + + +json +XmrInput::to_json() const +{ + json j {{"id" , id}, + {"account_id" , account_id}, + {"tx_id" , tx_id}, + {"output_id" , output_id}, + {"key_image" , key_image}, + {"amount" , amount}, + {"timestamp" , timestamp} + }; + + return j; +} + + + +ostream& operator<< (std::ostream& os, const XmrInput& out) +{ + os << "XmrInput: " << out.to_json().dump() << '\n'; + return os; +}; + +json +XmrPayment::to_json() const +{ + json j {{"id" , id}, + {"address" , address}, + {"payment_id" , payment_id}, + {"tx_hash" , tx_hash}, + {"request_fulfilled", bool {request_fulfilled}}, + {"payment_address" , payment_address}, + {"import_fee" , import_fee} + }; + + return j; +} + + +ostream& operator<< (std::ostream& os, const XmrPayment& out) { + os << "XmrPayment: " << out.to_json().dump() << '\n'; + return os; +}; + + +json +XmrTransactionWithOutsAndIns::to_json() const +{ + + json j {{"tx_id" , tx_id}, + {"account_id" , account_id}, + {"amount" , amount}, + {"tx_pub_key" , tx_pub_key}, + {"out_pub_key" , out_pub_key}, + {"global_index" , global_index}, + {"out_index" , out_index}, + {"timestamp" , timestamp}, + {"spend_key_images" , json::array()}, + {"key_image" , key_image_to_string()}, + {"mixin" , mixin} + }; + + return j; +} + +json +XmrTransactionWithOutsAndIns::spent_output() const +{ + json j {{"amount" , amount}, + {"key_image" , key_image_to_string()}, + {"tx_pub_key", tx_pub_key}, + {"out_index" , out_index}, + {"mixin" , mixin} + }; + + return j; +} + + +string +XmrTransactionWithOutsAndIns::key_image_to_string() const +{ + string key_image_str {"NULL"}; + + if (!key_image.is_null) + { + key_image_str = key_image.data; + } + + return key_image_str; +} + + + +ostream& operator<< (std::ostream& os, const XmrTransactionWithOutsAndIns& out) { + os << "XmrTransactionWithOutsAndIns: " << out.to_json().dump() << '\n'; + return os; +}; + + + } \ No newline at end of file diff --git a/src/ssqlses.h b/src/ssqlses.h index 954697d..aef4ab8 100644 --- a/src/ssqlses.h +++ b/src/ssqlses.h @@ -5,33 +5,19 @@ #ifndef RESTBED_XMR_SSQLSES_H #define RESTBED_XMR_SSQLSES_H - -#include - +#include "ssqls_sql.h" #include "../ext/json.hpp" namespace xmreg { -using namespace mysqlpp; + using namespace std; using namespace nlohmann; -// 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_7(Accounts, 1, 2, - sql_bigint_unsigned, id, - sql_varchar , address, - sql_bigint_unsigned, total_received, - sql_bigint_unsigned, scanned_block_height, - sql_bigint_unsigned, start_height, - sql_timestamp , created, - sql_timestamp , modified); - - struct XmrAccount : public Accounts { @@ -63,21 +49,6 @@ struct XmrAccount : public Accounts }; -sql_create_12(Transactions, 1, 2, - sql_bigint_unsigned, id, - sql_varchar , hash, - sql_varchar , prefix_hash, - sql_bigint_unsigned, account_id, - sql_bigint_unsigned, total_received, - sql_bigint_unsigned, total_sent, - sql_bigint_unsigned, unlock_time, - sql_bigint_unsigned, height, - sql_bool , coinbase, - sql_varchar , payment_id, - sql_bigint_unsigned, mixin, - sql_timestamp , timestamp); - - struct XmrTransaction : public Transactions { @@ -119,51 +90,15 @@ struct XmrTransaction : public Transactions using Transactions::Transactions; json - to_json() const - { - json j {{"id" , id}, - {"hash" , hash}, - {"prefix_hash" , prefix_hash}, - {"account_id" , account_id}, - {"total_received" , total_received}, - {"total_sent" , total_sent}, - {"height" , height}, - {"payment_id" , payment_id}, - {"coinbase" , bool {coinbase}}, - {"mixin" , mixin}, - {"timestamp" , timestamp} - }; - - return j; - } + to_json() const; static DateTime - timestamp_to_DateTime(time_t timestamp) - { - return DateTime(timestamp); - } + timestamp_to_DateTime(time_t timestamp); friend std::ostream& operator<< (std::ostream& stream, const XmrTransaction& acc); }; -ostream& operator<< (std::ostream& os, const XmrTransaction& acc) { - os << "XmrTransactions: " << acc.to_json().dump() << '\n'; - return os; -}; - - -sql_create_10(Outputs, 1, 3, - sql_bigint_unsigned, id, - sql_bigint_unsigned, account_id, - sql_bigint_unsigned, tx_id, - sql_varchar , out_pub_key, - sql_varchar , tx_pub_key, - sql_bigint_unsigned, amount, - sql_bigint_unsigned, global_index, - sql_bigint_unsigned, out_index, - sql_bigint_unsigned, mixin, - sql_timestamp , timestamp); struct XmrOutput : public Outputs @@ -193,43 +128,13 @@ struct XmrOutput : public Outputs using Outputs::Outputs; json - to_json() const - { - json j {{"id" , id}, - {"account_id" , account_id}, - {"tx_id" , tx_id}, - {"out_pub_key" , out_pub_key}, - {"tx_pub_key" , tx_pub_key}, - {"amount" , amount}, - {"global_index" , global_index}, - {"out_index" , out_index}, - {"mixin" , mixin}, - {"timestamp" , timestamp} - }; - - return j; - } + to_json() const; 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; -}; - - -sql_create_7(Inputs, 1, 4, - sql_bigint_unsigned, id, - sql_bigint_unsigned, account_id, - sql_bigint_unsigned, tx_id, - sql_bigint_unsigned, output_id, - sql_varchar , key_image, - sql_bigint_unsigned, amount, - sql_timestamp , timestamp); - struct XmrInput : public Inputs { @@ -253,48 +158,15 @@ struct XmrInput : public Inputs %3q, %4q, %5q); )"; - - using Inputs::Inputs; json - to_json() const - { - json j {{"id" , id}, - {"account_id" , account_id}, - {"tx_id" , tx_id}, - {"output_id" , output_id}, - {"key_image" , key_image}, - {"amount" , amount}, - {"timestamp" , timestamp} - }; - - return j; - } - + to_json() const; friend std::ostream& operator<< (std::ostream& stream, const XmrInput& out); }; -ostream& operator<< (std::ostream& os, const XmrInput& out) { - os << "XmrInput: " << out.to_json().dump() << '\n'; - return os; -}; - - - -sql_create_9(Payments, 1, 2, - sql_bigint_unsigned, id, - sql_varchar , address, - sql_varchar , payment_id, - sql_varchar , tx_hash, - sql_boolean , request_fulfilled, - sql_varchar , payment_address, - sql_bigint_unsigned, import_fee, - sql_timestamp , created, - sql_timestamp , modified); - struct XmrPayment : public Payments { @@ -320,47 +192,12 @@ struct XmrPayment : public Payments using Payments::Payments; json - to_json() const - { - json j {{"id" , id}, - {"address" , address}, - {"payment_id" , payment_id}, - {"tx_hash" , tx_hash}, - {"request_fulfilled", bool {request_fulfilled}}, - {"payment_address" , payment_address}, - {"import_fee" , import_fee} - }; - - return j; - } - + to_json() const; friend std::ostream& operator<< (std::ostream& stream, const XmrPayment& out); }; -ostream& operator<< (std::ostream& os, const XmrPayment& out) { - os << "XmrPayment: " << out.to_json().dump() << '\n'; - return os; -}; - - - - -// this is MySQL VIEW, based on the Transactions, -// Outputs and Inputs tables -sql_create_10(TransactionsWithOutsAndIns, 1, 2, - sql_bigint_unsigned, tx_id, - sql_bigint_unsigned, account_id, - sql_varchar , out_pub_key, - sql_bigint_unsigned, amount, - sql_bigint_unsigned, out_index, - sql_bigint_unsigned, global_index, - sql_varchar , tx_pub_key, - sql_timestamp , timestamp, - sql_varchar_null , key_image, - sql_bigint_unsigned, mixin); - struct XmrTransactionWithOutsAndIns : public TransactionsWithOutsAndIns @@ -378,62 +215,19 @@ struct XmrTransactionWithOutsAndIns : public TransactionsWithOutsAndIns using TransactionsWithOutsAndIns::TransactionsWithOutsAndIns; json - to_json() const - { - - json j {{"tx_id" , tx_id}, - {"account_id" , account_id}, - {"amount" , amount}, - {"tx_pub_key" , tx_pub_key}, - {"out_pub_key" , out_pub_key}, - {"global_index" , global_index}, - {"out_index" , out_index}, - {"timestamp" , timestamp}, - {"spend_key_images" , json::array()}, - {"key_image" , key_image_to_string()}, - {"mixin" , mixin} - }; - - return j; - } + to_json() const; json - spent_output() const - { - json j {{"amount" , amount}, - {"key_image" , key_image_to_string()}, - {"tx_pub_key", tx_pub_key}, - {"out_index" , out_index}, - {"mixin" , mixin} - }; - - return j; - } - - - string key_image_to_string() const - { - string key_image_str {"NULL"}; - - if (!key_image.is_null) - { - key_image_str = key_image.data; - } - - return key_image_str; - } + spent_output() const; + string + key_image_to_string() const; friend std::ostream& operator<< (std::ostream& stream, const XmrTransactionWithOutsAndIns& out); }; -ostream& operator<< (std::ostream& os, const XmrTransactionWithOutsAndIns& out) { - os << "XmrTransactionWithOutsAndIns: " << out.to_json().dump() << '\n'; - return os; -}; -