started work on detailed info

master
moneroexamples 7 years ago
parent 9905e916e4
commit ebe4bb7765

@ -603,6 +603,14 @@ main(int ac, const char* av[])
return r; return r;
}); });
CROW_ROUTE(app, "/api/detailedtransaction/<string>")
([&](const crow::request &req, string tx_hash) {
myxmr::jsonresponse r{xmrblocks.json_detailedtransaction(remove_bad_chars(tx_hash))};
return r;
});
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) {

@ -30,6 +30,7 @@
#include <limits> #include <limits>
#include <ctime> #include <ctime>
#include <future> #include <future>
#include <visitor/render_node.hpp>
#define TMPL_DIR "./templates" #define TMPL_DIR "./templates"
@ -3971,6 +3972,8 @@ public:
} }
/* /*
* Lets use this json api convention for success and error * Lets use this json api convention for success and error
* https://labs.omniti.com/labs/jsend * https://labs.omniti.com/labs/jsend
@ -4220,6 +4223,55 @@ public:
return j_response; return j_response;
} }
json
json_detailedtransaction(string tx_hash_str)
{
json j_response {
{"status", "fail"},
{"data" , json {}}
};
json& j_data = j_response["data"];
transaction tx;
bool found_in_mempool {false};
uint64_t tx_timestamp {0};
string error_message;
if (!find_tx_for_json(tx_hash_str, tx, found_in_mempool, tx_timestamp, error_message))
{
j_data["title"] = error_message;
return j_response;
}
mstch::map tx_context = construct_tx_context(tx, 1 /*full detailed */);
std::string view{"{{#bold}}{{yay}} :){{/bold}}"};
for (auto const& kv: tx_context)
{
//j_data[kv.first] = boost::apply_visitor(render_node2(), kv.second);
mstch::map context{
{"yay", kv.second},
{"bold", mstch::lambda{[](const std::string& text) -> mstch::node {
return "<b>" + text + "</b>";
}}}
};
cout << mstch::render(view, context) << endl;
}
j_response["status"] = "success";
return j_response;
}
/* /*
* Lets use this json api convention for success and error * Lets use this json api convention for success and error
* https://labs.omniti.com/labs/jsend * https://labs.omniti.com/labs/jsend
@ -6146,6 +6198,32 @@ private:
} }
bool
find_tx_for_json(
string const& tx_hash_str,
transaction& tx,
bool& found_in_mempool,
uint64_t& tx_timestamp,
string& error_message)
{
// parse tx hash string to hash object
crypto::hash tx_hash;
if (!xmreg::parse_str_secret_key(tx_hash_str, tx_hash))
{
error_message = fmt::format("Cant parse tx hash: {:s}", tx_hash_str);
return false;
}
if (!find_tx(tx_hash, tx, found_in_mempool, tx_timestamp))
{
error_message = fmt::format("Cant find tx hash: {:s}", tx_hash_str);
return false;
}
return true;
}
bool bool
search_mempool(crypto::hash tx_hash, search_mempool(crypto::hash tx_hash,
vector<MempoolStatus::mempool_tx>& found_txs) vector<MempoolStatus::mempool_tx>& found_txs)

Loading…
Cancel
Save