From 7747198cba52e1bea7c90d0dbdaebee9909c2fd1 Mon Sep 17 00:00:00 2001 From: moneroexamples Date: Wed, 22 Feb 2017 06:54:27 +0000 Subject: [PATCH] small html changes --- html/js/config.js | 2 +- html/partials/account-overview.html | 5 +-- html/partials/account-transactions.html | 5 +-- main.cpp | 12 ++++-- src/CmdLineOptions.cpp | 7 +++- src/YourMoneroRequests.cpp | 50 ++++++++++++++----------- src/YourMoneroRequests.h | 12 +++--- src/tools.h | 2 +- 8 files changed, 54 insertions(+), 41 deletions(-) diff --git a/html/js/config.js b/html/js/config.js index c733f49..807c872 100755 --- a/html/js/config.js +++ b/html/js/config.js @@ -1,6 +1,6 @@ var config = { apiUrl: "http://127.0.0.1:1984/", - testnet: false, + testnet: true, coinUnitPlaces: 12, txMinConfirms: 10, // corresponds to CRYPTONOTE_DEFAULT_TX_SPENDABLE_AGE in Monero txCoinbaseMinConfirms: 60, // corresponds to CRYPTONOTE_MINED_MONEY_UNLOCK_WINDOW in Monero diff --git a/html/partials/account-overview.html b/html/partials/account-overview.html index c5f19a4..05e7a41 100755 --- a/html/partials/account-overview.html +++ b/html/partials/account-overview.html @@ -87,12 +87,11 @@
-
+
+
{{tx_locked_reason(tx)}}
-
-
Block no:   {{tx_is_mempool(tx) ? 'N/A (tx in mempool)' : tx.height}} diff --git a/html/partials/account-transactions.html b/html/partials/account-transactions.html index ba482b6..311661d 100755 --- a/html/partials/account-transactions.html +++ b/html/partials/account-transactions.html @@ -103,12 +103,11 @@
-
+
{{tx_locked_reason(tx)}}
-
-
+
Block no:   {{tx_is_mempool(tx) ? 'N/A (tx in mempool)' : tx.height}} diff --git a/main.cpp b/main.cpp index ada7ef7..7c7fc07 100644 --- a/main.cpp +++ b/main.cpp @@ -40,8 +40,11 @@ bool do_not_relay = *do_not_relay_opt; string address_str = address_opt ? *address_opt : ""; string viewkey_str = viewkey_opt ? *viewkey_opt : ""; -auto port_opt = opts.get_option("port"); -auto bc_path_opt = opts.get_option("bc-path"); + + +auto port_opt = opts.get_option("port"); +auto bc_path_opt = opts.get_option("bc-path"); +auto frontend_url_opt = opts.get_option("frontend-url"); //cast port number in string to uint16 uint16_t app_port = boost::lexical_cast(*port_opt); @@ -105,10 +108,13 @@ xmreg::CurrentBlockchainStatus::start_monitor_blockchain_thread(); // create REST JSON API services xmreg::YourMoneroRequests::show_logs = true; +// Open Monero frontend url. Frontend url must match this value in +// server. Otherwise CORS problems between frontend and backend can occure +xmreg::YourMoneroRequests::frontend_url = *frontend_url_opt; + xmreg::YourMoneroRequests your_xmr( shared_ptr(new xmreg::MySqlAccounts{})); - auto login = your_xmr.make_resource( &xmreg::YourMoneroRequests::login, "/login"); diff --git a/src/CmdLineOptions.cpp b/src/CmdLineOptions.cpp index 20c20bd..23e163d 100644 --- a/src/CmdLineOptions.cpp +++ b/src/CmdLineOptions.cpp @@ -18,7 +18,7 @@ namespace xmreg p.add("txhash", -1); options_description desc( - "yourmonero, start YourMonare backend service"); + "openmonero, start Open Monero backend service"); desc.add_options() ("help,h", value()->default_value(false)->implicit_value(true), @@ -38,7 +38,10 @@ namespace xmreg ("bc-path,b", value(), "path to lmdb blockchain") ("deamon-url,d", value()->default_value("http:://127.0.0.1:18081"), - "monero address string"); + "monero address string") + ("frontend-url,u", value()->default_value("http://127.0.0.1:81"), + "URl of the Open Monero frotnend."); + store(command_line_parser(acc, avv) .options(desc) diff --git a/src/YourMoneroRequests.cpp b/src/YourMoneroRequests.cpp index 97cf2d3..2db0c1d 100644 --- a/src/YourMoneroRequests.cpp +++ b/src/YourMoneroRequests.cpp @@ -13,25 +13,6 @@ namespace xmreg { -multimap -make_headers(const multimap& extra_headers) -{ - multimap headers { - {"Date", get_current_time()}, - {"Access-Control-Allow-Origin", "http://127.0.0.1:81"}, - {"access-control-allow-headers", "*, DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Set-Cookie"}, - {"access-control-max-age", "86400, 1728000"}, - {"access-control-allow-methods", "GET, POST, OPTIONS"}, - {"access-control-allow-credentials", "true"}, - {"Content-Type", "application/json"} - }; - - headers.insert(extra_headers.begin(), extra_headers.end()); - - return headers; -}; - - handel_::handel_(const fetch_func_t& callback): request_callback {callback} {} @@ -659,7 +640,7 @@ YourMoneroRequests::import_wallet_request(const shared_ptr< Session > session, c string xmr_address = j_request["address"]; - // a placeholder for exciting or new account data + // a placeholder for existing or new payment data xmreg::XmrPayment xmr_payment; json j_response; @@ -808,6 +789,28 @@ YourMoneroRequests::generic_options_handler( const shared_ptr< Session > session }); } + + + +multimap +YourMoneroRequests::make_headers(const multimap& extra_headers) +{ + multimap headers { + {"Date", get_current_time()}, + {"Access-Control-Allow-Origin", frontend_url}, + {"access-control-allow-headers", "*, DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Set-Cookie"}, + {"access-control-max-age", "86400, 1728000"}, + {"access-control-allow-methods", "GET, POST, OPTIONS"}, + {"access-control-allow-credentials", "true"}, + {"Content-Type", "application/json"} + }; + + headers.insert(extra_headers.begin(), extra_headers.end()); + + return headers; +}; + + void YourMoneroRequests::print_json_log(const string& text, const json& j) { @@ -836,8 +839,11 @@ YourMoneroRequests::get_current_blockchain_height() } -// define static variables -bool YourMoneroRequests::show_logs = false; +// define defai;t static variables +bool YourMoneroRequests::show_logs {false}; +string YourMoneroRequests::frontend_url {"http://127.0.0.1:81"}; +string YourMoneroRequests::service_url {"http://localhost:1984"}; + } diff --git a/src/YourMoneroRequests.h b/src/YourMoneroRequests.h index 90f0162..ede1109 100644 --- a/src/YourMoneroRequests.h +++ b/src/YourMoneroRequests.h @@ -22,11 +22,6 @@ using namespace restbed; using namespace nlohmann; -string -get_current_time(const char* format = "%a, %d %b %Y %H:%M:%S %Z"); - -multimap -make_headers(const multimap& extra_headers = multimap()); struct handel_ { @@ -51,6 +46,9 @@ public: static bool show_logs; + static string frontend_url; + static string service_url; + YourMoneroRequests(shared_ptr _acc); /** @@ -94,10 +92,12 @@ public: static void generic_options_handler( const shared_ptr< Session > session ); + static multimap + make_headers(const multimap& extra_headers = multimap()); + static void print_json_log(const string& text, const json& j); - static inline string body_to_string(const Bytes & body); diff --git a/src/tools.h b/src/tools.h index d05f023..a92e465 100644 --- a/src/tools.h +++ b/src/tools.h @@ -282,7 +282,7 @@ get_human_readable_timestamp(uint64_t ts); string -get_current_time(const char* format); +get_current_time(const char* format = "%a, %d %b %Y %H:%M:%S %Z"); }