mirror of
https://git.wownero.com/wownero/onion-wownero-blockchain-explorer.git
synced 2024-08-15 00:33:12 +00:00
myxmr::jsonresponse class added
This commit is contained in:
parent
4a5f2d993f
commit
f5f9916b93
1 changed files with 25 additions and 33 deletions
58
main.cpp
58
main.cpp
|
@ -13,6 +13,21 @@ using boost::filesystem::path;
|
|||
|
||||
using namespace std;
|
||||
|
||||
namespace myxmr
|
||||
{
|
||||
struct jsonresponse: crow::response
|
||||
{
|
||||
jsonresponse(const nlohmann::json& _body) : crow::response {_body.dump()}
|
||||
{
|
||||
add_header("Access-Control-Allow-Origin", "*");
|
||||
add_header("Access-Control-Allow-Headers", "Content-Type");
|
||||
add_header("Content-Type", "application/json");
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
||||
int main(int ac, const char* av[]) {
|
||||
|
||||
// get command line options
|
||||
|
@ -343,11 +358,7 @@ int main(int ac, const char* av[]) {
|
|||
CROW_ROUTE(app, "/api/transaction/<string>")
|
||||
([&](const crow::request &req, string tx_hash) {
|
||||
|
||||
crow::response r{xmrblocks.json_transaction(tx_hash).dump()};
|
||||
|
||||
r.add_header("Access-Control-Allow-Origin", "*");
|
||||
r.add_header("Access-Control-Allow-Headers", "Content-Type");
|
||||
r.add_header("Content-Type", "application/json");
|
||||
myxmr::jsonresponse r{xmrblocks.json_transaction(tx_hash)};
|
||||
|
||||
return r;
|
||||
});
|
||||
|
@ -355,11 +366,7 @@ int main(int ac, const char* av[]) {
|
|||
CROW_ROUTE(app, "/api/block/<string>")
|
||||
([&](const crow::request &req, string block_no_or_hash) {
|
||||
|
||||
crow::response r{xmrblocks.json_block(block_no_or_hash).dump()};
|
||||
|
||||
r.add_header("Access-Control-Allow-Origin", "*");
|
||||
r.add_header("Access-Control-Allow-Headers", "Content-Type");
|
||||
r.add_header("Content-Type", "application/json");
|
||||
myxmr::jsonresponse r{xmrblocks.json_block(block_no_or_hash)};
|
||||
|
||||
return r;
|
||||
});
|
||||
|
@ -374,11 +381,7 @@ int main(int ac, const char* av[]) {
|
|||
string limit = regex_search(req.raw_url, regex {"limit=\\d+"}) ?
|
||||
req.url_params.get("limit") : "25";
|
||||
|
||||
crow::response r{xmrblocks.json_transactions(page, limit).dump()};
|
||||
|
||||
r.add_header("Access-Control-Allow-Origin", "*");
|
||||
r.add_header("Access-Control-Allow-Headers", "Content-Type");
|
||||
r.add_header("Content-Type", "application/json");
|
||||
myxmr::jsonresponse r{xmrblocks.json_transactions(page, limit)};
|
||||
|
||||
return r;
|
||||
});
|
||||
|
@ -386,11 +389,7 @@ int main(int ac, const char* av[]) {
|
|||
CROW_ROUTE(app, "/api/mempool")
|
||||
([&](const crow::request &req) {
|
||||
|
||||
crow::response r{xmrblocks.json_mempool().dump()};
|
||||
|
||||
r.add_header("Access-Control-Allow-Origin", "*");
|
||||
r.add_header("Access-Control-Allow-Headers", "Content-Type");
|
||||
r.add_header("Content-Type", "application/json");
|
||||
myxmr::jsonresponse r{xmrblocks.json_mempool()};
|
||||
|
||||
return r;
|
||||
});
|
||||
|
@ -398,11 +397,7 @@ int main(int ac, const char* av[]) {
|
|||
CROW_ROUTE(app, "/api/search/<string>")
|
||||
([&](const crow::request &req, string search_value) {
|
||||
|
||||
crow::response r{xmrblocks.json_search(search_value).dump()};
|
||||
|
||||
r.add_header("Access-Control-Allow-Origin", "*");
|
||||
r.add_header("Access-Control-Allow-Headers", "Content-Type");
|
||||
r.add_header("Content-Type", "application/json");
|
||||
myxmr::jsonresponse r{xmrblocks.json_search(search_value)};
|
||||
|
||||
return r;
|
||||
});
|
||||
|
@ -421,21 +416,18 @@ int main(int ac, const char* av[]) {
|
|||
|
||||
bool tx_prove{false};
|
||||
|
||||
try {
|
||||
try
|
||||
{
|
||||
tx_prove = regex_search(req.raw_url, regex {"txprove=[01]"}) ?
|
||||
boost::lexical_cast<bool>(req.url_params.get("txprove")) :
|
||||
false;
|
||||
}
|
||||
catch (const boost::bad_lexical_cast &e) {
|
||||
catch (const boost::bad_lexical_cast &e)
|
||||
{
|
||||
cerr << "Cant parse tx_prove as bool. Using default value" << endl;
|
||||
}
|
||||
|
||||
crow::response r{xmrblocks.json_outputs(
|
||||
tx_hash, address, viewkey, tx_prove).dump()};
|
||||
|
||||
r.add_header("Access-Control-Allow-Origin", "*");
|
||||
r.add_header("Access-Control-Allow-Headers", "Content-Type");
|
||||
r.add_header("Content-Type", "application/json");
|
||||
myxmr::jsonresponse r{xmrblocks.json_outputs(tx_hash, address, viewkey, tx_prove)};
|
||||
|
||||
return r;
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue