dependence on mysql view removed

pull/2/head
moneroexamples 7 years ago
parent 9bf6bbf4ea
commit ba7da3de77

@ -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.

@ -105,6 +105,9 @@ MysqlInputs::select(const uint64_t& address_id, vector<XmrInput>& ins)
return false;
}
bool
MysqlInputs::select_for_tx(const uint64_t& address_id, vector<XmrInput>& ins)
{
@ -236,6 +239,39 @@ MysqlOutpus::select(const uint64_t& address_id, vector<XmrOutput>& outs)
return false;
}
bool
MysqlOutpus::select(const uint64_t& out_id, XmrOutput& out)
{
Query query = conn->query(XmrOutput::SELECT_STMT3);
query.parse();
try
{
vector<XmrOutput> 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<XmrOutput>& outs)
{
@ -921,6 +957,12 @@ MySqlAccounts::select_outputs(const uint64_t& account_id, vector<XmrOutput>& 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<XmrOutput>& outs)
{
@ -939,6 +981,14 @@ MySqlAccounts::select_inputs_for_tx(const uint64_t& tx_id, vector<XmrTransaction
return mysql_tx_inout->select_for_tx(tx_id, ins);
}
bool
MySqlAccounts::select_inputs_for_tx(const uint64_t& tx_id, vector<XmrInput>& ins)
{
return mysql_in->select_for_tx(tx_id, ins);
}
bool
MySqlAccounts::select_inputs_for_out(const uint64_t& output_id, vector<XmrInput>& ins)
{

@ -93,6 +93,8 @@ public:
bool
select_for_tx(const uint64_t& tx_id, vector<XmrOutput>& 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<XmrTransactionWithOutsAndIns>& txs);
bool
select_output_with_id(const uint64_t& out_id, XmrOutput& out);
bool
select_outputs(const uint64_t& account_id, vector<XmrOutput>& outs);
@ -232,8 +237,12 @@ public:
bool
select_inputs_for_tx(const uint64_t& tx_id, vector<XmrTransactionWithOutsAndIns>& ins);
bool
select_inputs_for_tx(const uint64_t& tx_id, vector<XmrInput>& ins);
bool
select_inputs_for_out(const uint64_t& output_id, vector<XmrInput>& ins);
bool
output_exists(const string& output_public_key_str, XmrOutput& out);

@ -179,7 +179,7 @@ YourMoneroRequests::get_address_txs(const shared_ptr< Session > session, const B
{
json j_tx = tx.to_json();
vector<XmrTransactionWithOutsAndIns> inputs;
vector<XmrInput> 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<XmrTransactionWithOutsAndIns> 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);

@ -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)
)";

Loading…
Cancel
Save