readme updated and code clean up

pull/155/head
moneroexamples 5 years ago
parent 03d045cd11
commit d5f6c1e008

@ -316,17 +316,17 @@ var api_minor = response.data.api & 0xffff;
### login ### login
Login an existing or new user into OpenMonero. Login an existing or a new user into OpenMonero.
```bash ```bash
curl -w "\n" -X POST http://127.0.0.1:1984/login -d '{"address": "A2VTvE8bC9APsWFn3mQzgW8Xfcy2SP2CRUArD6ZtthNaWDuuvyhtBcZ8WDuYMRt1HhcnNQvpXVUavEiZ9waTbyBhP6RM8TV", "view_key": "041a241325326f9d86519b714a9b7f78b29111551757eeb6334d39c21f8b7400"}' curl -w "\n" -X POST http://127.0.0.1:1984/login -d '{"address": "A2VTvE8bC9APsWFn3mQzgW8Xfcy2SP2CRUArD6ZtthNaWDuuvyhtBcZ8WDuYMRt1HhcnNQvpXVUavEiZ9waTbyBhP6RM8TV", "view_key": "041a241325326f9d86519b714a9b7f78b29111551757eeb6334d39c21f8b7400", "create_account": true}'
``` ```
Example output:
```json ```json
{"new_address":false,"status":"success"} {"generated_locally":false,"new_address":true,"start_height":0,"status":"success"}
``` ```
#### get_address_txs #### get_address_txs
Get the list of all txs for the given user with their possible spendings. Get the list of all txs for the given user with their possible spendings.

@ -91,8 +91,7 @@ OpenMoneroRequests::login(const shared_ptr<Session> session, const Bytes & body)
} }
// a placeholder for exciting or new account data // a placeholder for exciting or new account data id
uint64_t acc_id {0}; uint64_t acc_id {0};
// marks if this is new account creation or not // marks if this is new account creation or not
@ -120,7 +119,7 @@ OpenMoneroRequests::login(const shared_ptr<Session> session, const Bytes & body)
// set this flag to indicate that we have just created a // set this flag to indicate that we have just created a
// new account in mysql. this information is sent to front-end // new account in mysql. this information is sent to front-end
// as it can disply some greeting window to new users upon // as it can disply some greeting window to new users upon
// their first install // their first entry
new_account_created = true; new_account_created = true;
} // if (!acc) } // if (!acc)
@ -206,8 +205,16 @@ OpenMoneroRequests::get_address_txs(
// for this to continue, search thread must have already been // for this to continue, search thread must have already been
// created and still exisits. // created and still exisits.
if (login_and_start_search_thread(xmr_address, view_key, acc, j_response)) if (!login_and_start_search_thread(xmr_address, view_key, acc, j_response))
{ {
j_response = json {{"status", "error"},
{"reason", "Search thread does not exist."}};
// some error with loggin in or search thread start
session_close(session, j_response);
return;
}
// before fetching txs, check if provided view key // before fetching txs, check if provided view key
// is correct. this is simply to ensure that // is correct. this is simply to ensure that
// we cant fetch an account's txs using only address. // we cant fetch an account's txs using only address.
@ -299,17 +306,6 @@ OpenMoneroRequests::get_address_txs(
} // if (xmr_accounts->select_txs_for_ac } // if (xmr_accounts->select_txs_for_ac
} // if (current_bc_status->search_thread_exist(xmr_address))
else
{
j_response = json {{"status", "error"},
{"reason", "Search thread does not exist."}};
// some error with loggin in or search thread start
session_close(session, j_response);
return;
}
// append txs found in mempool to the json returned // append txs found in mempool to the json returned
json j_mempool_tx; json j_mempool_tx;
@ -363,14 +359,15 @@ OpenMoneroRequests::get_address_txs(
boost::lexical_cast<uint64_t>( boost::lexical_cast<uint64_t>(
j_response["total_received_unlocked"].get<string>()) j_response["total_received_unlocked"].get<string>())
+ total_received_mempool - total_sent_mempool); + total_received_mempool - total_sent_mempool);
}
} } //if(!j_mempool_tx.empty())
} // current_bc_status->find_txs_in_mempool
string response_body = j_response.dump(); string response_body = j_response.dump();
auto response_headers = make_headers({{ "Content-Length", auto response_headers = make_headers(
to_string(response_body.size())}}); {{ "Content-Length", to_string(response_body.size()) }});
session->close(OK, response_body, response_headers); session->close(OK, response_body, response_headers);
} }

Loading…
Cancel
Save