diff --git a/README.md b/README.md index a1eb85b..f4dcde3 100644 --- a/README.md +++ b/README.md @@ -1,17 +1,26 @@ # JSON REST service for Monero -Example of using [restbed](https://github.com/Corvusoft/restbed/) to provide Monero related JSON REST service. +Example of using [restbed](https://github.com/Corvusoft/restbed/) to + provide Monero related JSON REST service. For the example, a service called Open Monero was developed. ## Open Monero -Open Monero is an open source implementation of backend for -https://mymonero.com/. The frontend, html, css, JavaScript, were adapted -from, and originally developed by https://mymonero.com/. - -However, unlike MyMonero's backend, Open Monero's backend is open sourced, free -to use, host and modify. - +Open Monero is an open source implementation of backend of +https://mymonero.com/. The frontend, which includes html, css, JavaScript were adapted +from (and originally developed by) https://mymonero.com/. The backend in this example +was developed to be fully compatible with the frontend. + +However, unlike MyMonero, Open Monero's backend is open sourced, free +to use, host and modify. Additionally, the following features were added/changed: + + - google analytics, cloudflare, images and flash were removed. + - transaction fees were set to zero. + - the wallets generated use 25 word mnemonics, fully compatible with official monero wallets +(13 word mnemonics generated by MyMonero work as usual though). + - import wallet fee was reduced. + - backend correctly decodes RingCT transactions. + ## Status Still under development as its not finished. diff --git a/src/MySqlAccounts.cpp b/src/MySqlAccounts.cpp index 746f218..50a5d06 100644 --- a/src/MySqlAccounts.cpp +++ b/src/MySqlAccounts.cpp @@ -105,6 +105,9 @@ MysqlInputs::select(const uint64_t& address_id, vector& ins) return false; } + + + bool MysqlInputs::select_for_tx(const uint64_t& address_id, vector& ins) { @@ -236,6 +239,39 @@ MysqlOutpus::select(const uint64_t& address_id, vector& outs) return false; } + +bool +MysqlOutpus::select(const uint64_t& out_id, XmrOutput& out) +{ + Query query = conn->query(XmrOutput::SELECT_STMT3); + query.parse(); + + try + { + vector outs; + + query.storein(outs, out_id); + + if (!outs.empty()) + { + out = outs.at(0); + return true; + } + } + catch (mysqlpp::Exception& e) + { + MYSQL_EXCEPTION_MSG(e); + } + catch (std::exception& e) + { + MYSQL_EXCEPTION_MSG(e); + } + + return false; +} + + + bool MysqlOutpus::select_for_tx(const uint64_t& tx_id, vector& outs) { @@ -921,6 +957,12 @@ MySqlAccounts::select_outputs(const uint64_t& account_id, vector& out return mysql_out->select(account_id, outs); } +bool +MySqlAccounts::select_output_with_id(const uint64_t& out_id, XmrOutput& out) +{ + return mysql_out->select(out_id, out); +} + bool MySqlAccounts::select_outputs_for_tx(const uint64_t& tx_id, vector& outs) { @@ -939,6 +981,14 @@ MySqlAccounts::select_inputs_for_tx(const uint64_t& tx_id, vectorselect_for_tx(tx_id, ins); } +bool +MySqlAccounts::select_inputs_for_tx(const uint64_t& tx_id, vector& ins) +{ + return mysql_in->select_for_tx(tx_id, ins); +} + + + bool MySqlAccounts::select_inputs_for_out(const uint64_t& output_id, vector& ins) { diff --git a/src/MySqlAccounts.h b/src/MySqlAccounts.h index 8f24bcb..d87799b 100644 --- a/src/MySqlAccounts.h +++ b/src/MySqlAccounts.h @@ -93,6 +93,8 @@ public: bool select_for_tx(const uint64_t& tx_id, vector& outs); + bool + select(const uint64_t& out_id, XmrOutput& out); bool exist(const string& output_public_key_str, XmrOutput& out); @@ -220,6 +222,9 @@ public: select_txs_with_inputs_and_outputs(const uint64_t& account_id, vector& txs); + bool + select_output_with_id(const uint64_t& out_id, XmrOutput& out); + bool select_outputs(const uint64_t& account_id, vector& outs); @@ -232,8 +237,12 @@ public: bool select_inputs_for_tx(const uint64_t& tx_id, vector& ins); + bool + select_inputs_for_tx(const uint64_t& tx_id, vector& ins); + bool select_inputs_for_out(const uint64_t& output_id, vector& ins); + bool output_exists(const string& output_public_key_str, XmrOutput& out); diff --git a/src/YourMoneroRequests.cpp b/src/YourMoneroRequests.cpp index c9b3874..1fc88ab 100644 --- a/src/YourMoneroRequests.cpp +++ b/src/YourMoneroRequests.cpp @@ -179,7 +179,7 @@ YourMoneroRequests::get_address_txs(const shared_ptr< Session > session, const B { json j_tx = tx.to_json(); - vector inputs; + vector inputs; if (xmr_accounts->select_inputs_for_tx(tx.id, inputs)) { @@ -187,17 +187,50 @@ YourMoneroRequests::get_address_txs(const shared_ptr< Session > session, const B uint64_t total_spent {0}; - for (XmrTransactionWithOutsAndIns input: inputs) + for (XmrInput input: inputs) { + XmrOutput out; + + if (!xmr_accounts->select_output_with_id(input.output_id, out)) + { + + } + total_spent += input.amount; - j_spent_outputs.push_back(input.spent_output()); + + j_spent_outputs.push_back({ + {"amount" , input.amount}, + {"key_image" , input.key_image}, + {"tx_pub_key" , out.tx_pub_key}, + {"out_index" , out.out_index}, + {"mixin" , out.mixin}}); } j_tx["total_sent"] = total_spent; j_tx["spent_outputs"] = j_spent_outputs; + } +// vector inputs; +// +// if (xmr_accounts->select_inputs_for_tx(tx.id, inputs)) +// { +// json j_spent_outputs = json::array(); +// +// uint64_t total_spent {0}; +// +// for (XmrTransactionWithOutsAndIns input: inputs) +// { +// total_spent += input.amount; +// j_spent_outputs.push_back(input.spent_output()); +// } +// +// j_tx["total_sent"] = total_spent; +// +// j_tx["spent_outputs"] = j_spent_outputs; +// } + total_received += tx.total_received; j_txs.push_back(j_tx); diff --git a/src/ssqlses.h b/src/ssqlses.h index 1a2a2d3..6f9a6ef 100644 --- a/src/ssqlses.h +++ b/src/ssqlses.h @@ -154,6 +154,10 @@ struct XmrOutput : public Outputs SELECT * FROM `Outputs` WHERE `tx_id` = (%0q) )"; + static constexpr const char* SELECT_STMT3 = R"( + SELECT * FROM `Outputs` WHERE `id` = (%0q) + )"; + static constexpr const char* EXIST_STMT = R"( SELECT * FROM `Outputs` WHERE `out_pub_key` = (%0q) )";