moneroexamples 7 years ago
parent d3b3e4904c
commit c26882897b

@ -7,7 +7,12 @@ set(PROJECT_NAME
project(${PROJECT_NAME}) project(${PROJECT_NAME})
set(CMAKE_CXX_FLAGS set(CMAKE_CXX_FLAGS
"${CMAKE_CXX_FLAGS} -std=c++14") "${CMAKE_CXX_FLAGS} -std=c++14 -fsanitize=address -fno-omit-frame-pointer")
set(CMAKE_C_FLAGS
"${CMAKE_C_FLAGS} -fsanitize=address -fno-omit-frame-pointer -DLEAK_SANITIZER")
#
if (WIN32) if (WIN32)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wa,-mbig-obj -O3") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wa,-mbig-obj -O3")
@ -102,16 +107,15 @@ set(LIBRARIES
cryptonote_basic cryptonote_basic
daemonizer daemonizer
cncrypto cncrypto
blocks blocks
lmdb lmdb
ringct ringct
common common
mnemonics mnemonics
epee
easylogging easylogging
checkpoints checkpoints
version version
epee
${Boost_LIBRARIES} ${Boost_LIBRARIES}
pthread pthread
unbound unbound

@ -11,6 +11,7 @@
#include <regex> #include <regex>
using boost::filesystem::path; using boost::filesystem::path;
using xmreg::remove_bad_chars;
using namespace std; using namespace std;
@ -276,18 +277,18 @@ main(int ac, const char* av[])
CROW_ROUTE(app, "/block/<string>") CROW_ROUTE(app, "/block/<string>")
([&](const crow::request& req, string block_hash) { ([&](const crow::request& req, string block_hash) {
return crow::response(xmrblocks.show_block(block_hash)); return crow::response(xmrblocks.show_block(remove_bad_chars(block_hash)));
}); });
CROW_ROUTE(app, "/tx/<string>") CROW_ROUTE(app, "/tx/<string>")
([&](const crow::request& req, string tx_hash) { ([&](const crow::request& req, string tx_hash) {
return crow::response(xmrblocks.show_tx(tx_hash)); return crow::response(xmrblocks.show_tx(remove_bad_chars(tx_hash)));
}); });
CROW_ROUTE(app, "/tx/<string>/<uint>") CROW_ROUTE(app, "/tx/<string>/<uint>")
([&](string tx_hash, uint16_t with_ring_signatures) ([&](string tx_hash, uint16_t with_ring_signatures)
{ {
return xmrblocks.show_tx(tx_hash, with_ring_signatures); return xmrblocks.show_tx(remove_bad_chars(tx_hash), with_ring_signatures);
}); });
CROW_ROUTE(app, "/myoutputs").methods("POST"_method) CROW_ROUTE(app, "/myoutputs").methods("POST"_method)
@ -304,13 +305,13 @@ main(int ac, const char* av[])
return string("xmr address, viewkey or tx hash not provided"); return string("xmr address, viewkey or tx hash not provided");
} }
string tx_hash = post_body["tx_hash"]; string tx_hash = remove_bad_chars(post_body["tx_hash"]);
string xmr_address = post_body["xmr_address"]; string xmr_address = remove_bad_chars(post_body["xmr_address"]);
string viewkey = post_body["viewkey"]; string viewkey = remove_bad_chars(post_body["viewkey"]);
// this will be only not empty when checking raw tx data // this will be only not empty when checking raw tx data
// using tx pusher // using tx pusher
string raw_tx_data = post_body["raw_tx_data"]; string raw_tx_data = remove_bad_chars(post_body["raw_tx_data"]);
string domain = get_domain(req); string domain = get_domain(req);
@ -326,8 +327,10 @@ main(int ac, const char* av[])
string domain = get_domain(req); string domain = get_domain(req);
return xmrblocks.show_my_outputs(tx_hash, xmr_address, return xmrblocks.show_my_outputs(remove_bad_chars(tx_hash),
viewkey, string {}, remove_bad_chars(xmr_address),
remove_bad_chars(viewkey),
string {},
domain); domain);
}); });
@ -345,18 +348,21 @@ main(int ac, const char* av[])
"tx hash not provided"); "tx hash not provided");
} }
string tx_hash = post_body["txhash"]; string tx_hash = remove_bad_chars(post_body["txhash"]);
string tx_prv_key = post_body["txprvkey"]; string tx_prv_key = remove_bad_chars(post_body["txprvkey"]);
string xmr_address = post_body["xmraddress"]; string xmr_address = remove_bad_chars(post_body["xmraddress"]);
// this will be only not empty when checking raw tx data // this will be only not empty when checking raw tx data
// using tx pusher // using tx pusher
string raw_tx_data = post_body["raw_tx_data"]; string raw_tx_data = remove_bad_chars(post_body["raw_tx_data"]);
string domain = get_domain(req); string domain = get_domain(req);
return xmrblocks.show_prove(tx_hash, xmr_address, return xmrblocks.show_prove(tx_hash,
tx_prv_key, raw_tx_data, domain); xmr_address,
tx_prv_key,
raw_tx_data,
domain);
}); });
@ -366,8 +372,11 @@ main(int ac, const char* av[])
string domain = get_domain(req); string domain = get_domain(req);
return xmrblocks.show_prove(tx_hash, xmr_address, return xmrblocks.show_prove(remove_bad_chars(tx_hash),
tx_prv_key, string {}, domain); remove_bad_chars(xmr_address),
remove_bad_chars(tx_prv_key),
string {},
domain);
}); });
if (enable_pusher) if (enable_pusher)
@ -388,8 +397,8 @@ main(int ac, const char* av[])
return string("Raw tx data or action not provided"); return string("Raw tx data or action not provided");
} }
string raw_tx_data = post_body["rawtxdata"]; string raw_tx_data = remove_bad_chars(post_body["rawtxdata"]);
string action = post_body["action"]; string action = remove_bad_chars(post_body["action"]);
if (action == "check") if (action == "check")
return xmrblocks.show_checkrawtx(raw_tx_data, action); return xmrblocks.show_checkrawtx(raw_tx_data, action);
@ -423,8 +432,8 @@ main(int ac, const char* av[])
return string("Viewkey not provided. Cant decrypt key image file without it"); return string("Viewkey not provided. Cant decrypt key image file without it");
} }
string raw_data = post_body["rawkeyimgsdata"]; string raw_data = remove_bad_chars(post_body["rawkeyimgsdata"]);
string viewkey = post_body["viewkey"]; string viewkey = remove_bad_chars(post_body["viewkey"]);
return xmrblocks.show_checkrawkeyimgs(raw_data, viewkey); return xmrblocks.show_checkrawkeyimgs(raw_data, viewkey);
}); });
@ -455,8 +464,8 @@ main(int ac, const char* av[])
"key image file without it"); "key image file without it");
} }
string raw_data = post_body["rawoutputkeysdata"]; string raw_data = remove_bad_chars(post_body["rawoutputkeysdata"]);
string viewkey = post_body["viewkey"]; string viewkey = remove_bad_chars(post_body["viewkey"]);
return xmrblocks.show_checkcheckrawoutput(raw_data, viewkey); return xmrblocks.show_checkcheckrawoutput(raw_data, viewkey);
}); });
@ -465,7 +474,7 @@ main(int ac, const char* av[])
CROW_ROUTE(app, "/search").methods("GET"_method) CROW_ROUTE(app, "/search").methods("GET"_method)
([&](const crow::request& req) { ([&](const crow::request& req) {
return xmrblocks.search(string(req.url_params.get("value"))); return xmrblocks.search(remove_bad_chars(string(req.url_params.get("value"))));
}); });
CROW_ROUTE(app, "/mempool") CROW_ROUTE(app, "/mempool")
@ -496,7 +505,7 @@ main(int ac, const char* av[])
CROW_ROUTE(app, "/api/transaction/<string>") CROW_ROUTE(app, "/api/transaction/<string>")
([&](const crow::request &req, string tx_hash) { ([&](const crow::request &req, string tx_hash) {
myxmr::jsonresponse r{xmrblocks.json_transaction(tx_hash)}; myxmr::jsonresponse r{xmrblocks.json_transaction(remove_bad_chars(tx_hash))};
return r; return r;
}); });
@ -504,7 +513,7 @@ main(int ac, const char* av[])
CROW_ROUTE(app, "/api/rawtransaction/<string>") CROW_ROUTE(app, "/api/rawtransaction/<string>")
([&](const crow::request &req, string tx_hash) { ([&](const crow::request &req, string tx_hash) {
myxmr::jsonresponse r{xmrblocks.json_rawtransaction(tx_hash)}; myxmr::jsonresponse r{xmrblocks.json_rawtransaction(remove_bad_chars(tx_hash))};
return r; return r;
}); });
@ -512,7 +521,7 @@ main(int ac, const char* av[])
CROW_ROUTE(app, "/api/block/<string>") CROW_ROUTE(app, "/api/block/<string>")
([&](const crow::request &req, string block_no_or_hash) { ([&](const crow::request &req, string block_no_or_hash) {
myxmr::jsonresponse r{xmrblocks.json_block(block_no_or_hash)}; myxmr::jsonresponse r{xmrblocks.json_block(remove_bad_chars(block_no_or_hash))};
return r; return r;
}); });
@ -520,7 +529,7 @@ main(int ac, const char* av[])
CROW_ROUTE(app, "/api/rawblock/<string>") CROW_ROUTE(app, "/api/rawblock/<string>")
([&](const crow::request &req, string block_no_or_hash) { ([&](const crow::request &req, string block_no_or_hash) {
myxmr::jsonresponse r{xmrblocks.json_rawblock(block_no_or_hash)}; myxmr::jsonresponse r{xmrblocks.json_rawblock(remove_bad_chars(block_no_or_hash))};
return r; return r;
}); });
@ -534,7 +543,8 @@ main(int ac, const char* av[])
string limit = regex_search(req.raw_url, regex {"limit=\\d+"}) ? string limit = regex_search(req.raw_url, regex {"limit=\\d+"}) ?
req.url_params.get("limit") : "25"; req.url_params.get("limit") : "25";
myxmr::jsonresponse r{xmrblocks.json_transactions(page, limit)}; myxmr::jsonresponse r{xmrblocks.json_transactions(
remove_bad_chars(page), remove_bad_chars(limit))};
return r; return r;
}); });
@ -551,7 +561,8 @@ main(int ac, const char* av[])
string limit = regex_search(req.raw_url, regex {"limit=\\d+"}) ? string limit = regex_search(req.raw_url, regex {"limit=\\d+"}) ?
req.url_params.get("limit") : "100000000"; req.url_params.get("limit") : "100000000";
myxmr::jsonresponse r{xmrblocks.json_mempool(page, limit)}; myxmr::jsonresponse r{xmrblocks.json_mempool(
remove_bad_chars(page), remove_bad_chars(limit))};
return r; return r;
}); });
@ -559,7 +570,7 @@ main(int ac, const char* av[])
CROW_ROUTE(app, "/api/search/<string>") CROW_ROUTE(app, "/api/search/<string>")
([&](const crow::request &req, string search_value) { ([&](const crow::request &req, string search_value) {
myxmr::jsonresponse r{xmrblocks.json_search(search_value)}; myxmr::jsonresponse r{xmrblocks.json_search(remove_bad_chars(search_value))};
return r; return r;
}); });
@ -605,7 +616,11 @@ main(int ac, const char* av[])
cerr << "Cant parse tx_prove as bool. Using default value" << endl; cerr << "Cant parse tx_prove as bool. Using default value" << endl;
} }
myxmr::jsonresponse r{xmrblocks.json_outputs(tx_hash, address, viewkey, tx_prove)}; myxmr::jsonresponse r{xmrblocks.json_outputs(
remove_bad_chars(tx_hash),
remove_bad_chars(address),
remove_bad_chars(viewkey),
tx_prove)};
return r; return r;
}); });
@ -635,7 +650,11 @@ main(int ac, const char* av[])
cerr << "Cant parse tx_prove as bool. Using default value" << endl; cerr << "Cant parse tx_prove as bool. Using default value" << endl;
} }
myxmr::jsonresponse r{xmrblocks.json_outputsblocks(limit, address, viewkey, in_mempool_aswell)}; myxmr::jsonresponse r{xmrblocks.json_outputsblocks(
remove_bad_chars(limit),
remove_bad_chars(address),
remove_bad_chars(viewkey),
in_mempool_aswell)};
return r; return r;
}); });

@ -5458,7 +5458,7 @@ namespace xmreg
{"has_payment_id8" , txd.payment_id8 != null_hash8}, {"has_payment_id8" , txd.payment_id8 != null_hash8},
{"confirmations" , txd.no_confirmations}, {"confirmations" , txd.no_confirmations},
{"payment_id" , pid_str}, {"payment_id" , pid_str},
{"payment_id_as_ascii" , std::regex_replace(txd.payment_id_as_ascii, e, " ")}, {"payment_id_as_ascii" , remove_bad_chars(txd.payment_id_as_ascii)},
{"payment_id8" , pid8_str}, {"payment_id8" , pid8_str},
{"extra" , txd.get_extra_str()}, {"extra" , txd.get_extra_str()},
{"with_ring_signatures" , static_cast<bool>( {"with_ring_signatures" , static_cast<bool>(

@ -328,6 +328,17 @@ namespace xmreg
while(std::distance(chunk_begin,end) > 0); while(std::distance(chunk_begin,end) > 0);
} }
/*
* Remove all characters in in_str that match the given
* regular expression
*/
inline string
remove_bad_chars(string const& in_str, std::regex const& rgx = std::regex {"[^a-zA-Z0-9]"})
{
return std::regex_replace(in_str, rgx, "");
}
bool bool
make_tx_from_json(const string& json_str, transaction& tx); make_tx_from_json(const string& json_str, transaction& tx);

Loading…
Cancel
Save