Merge pull request #130 from moneroexamples/tx_full_details_json_call
Adding detailedtransaction json api call
This commit is contained in:
commit
6948392191
|
@ -6,9 +6,7 @@ set(PROJECT_NAME
|
||||||
|
|
||||||
project(${PROJECT_NAME})
|
project(${PROJECT_NAME})
|
||||||
|
|
||||||
set(CMAKE_CXX_FLAGS
|
set(CMAKE_CXX_STANDARD 14)
|
||||||
"${CMAKE_CXX_FLAGS} -std=c++14")
|
|
||||||
|
|
||||||
|
|
||||||
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")
|
||||||
|
|
19501
ext/json.hpp
19501
ext/json.hpp
File diff suppressed because it is too large
Load Diff
8
main.cpp
8
main.cpp
|
@ -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) {
|
||||||
|
|
||||||
|
|
154
src/page.h
154
src/page.h
|
@ -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"
|
||||||
|
@ -66,7 +67,7 @@
|
||||||
#define JS_SHA3 TMPL_DIR "/js/sha3.js"
|
#define JS_SHA3 TMPL_DIR "/js/sha3.js"
|
||||||
|
|
||||||
#define ONIONEXPLORER_RPC_VERSION_MAJOR 1
|
#define ONIONEXPLORER_RPC_VERSION_MAJOR 1
|
||||||
#define ONIONEXPLORER_RPC_VERSION_MINOR 0
|
#define ONIONEXPLORER_RPC_VERSION_MINOR 1
|
||||||
#define MAKE_ONIONEXPLORER_RPC_VERSION(major,minor) (((major)<<16)|(minor))
|
#define MAKE_ONIONEXPLORER_RPC_VERSION(major,minor) (((major)<<16)|(minor))
|
||||||
#define ONIONEXPLORER_RPC_VERSION \
|
#define ONIONEXPLORER_RPC_VERSION \
|
||||||
MAKE_ONIONEXPLORER_RPC_VERSION(ONIONEXPLORER_RPC_VERSION_MAJOR, ONIONEXPLORER_RPC_VERSION_MINOR)
|
MAKE_ONIONEXPLORER_RPC_VERSION(ONIONEXPLORER_RPC_VERSION_MAJOR, ONIONEXPLORER_RPC_VERSION_MINOR)
|
||||||
|
@ -113,6 +114,70 @@ namespace std
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* visitor to produce json representations of
|
||||||
|
* values stored in mstch::node
|
||||||
|
*/
|
||||||
|
class mstch_node_to_json: public boost::static_visitor<nlohmann::json> {
|
||||||
|
public:
|
||||||
|
|
||||||
|
|
||||||
|
// enabled for numeric types
|
||||||
|
template<typename T>
|
||||||
|
std::enable_if_t<std::is_arithmetic<T>::value, nlohmann::json>
|
||||||
|
operator()(T const& value) const {
|
||||||
|
return nlohmann::json {value};
|
||||||
|
}
|
||||||
|
|
||||||
|
nlohmann::json operator()(std::string const& value) const {
|
||||||
|
return nlohmann::json {value};
|
||||||
|
}
|
||||||
|
|
||||||
|
nlohmann::json operator()(mstch::map const& n_map) const
|
||||||
|
{
|
||||||
|
nlohmann::json j;
|
||||||
|
|
||||||
|
for (auto const& kv: n_map)
|
||||||
|
j[kv.first] = boost::apply_visitor(mstch_node_to_json(), kv.second);
|
||||||
|
|
||||||
|
return j;
|
||||||
|
}
|
||||||
|
|
||||||
|
nlohmann::json operator()(mstch::array const& n_array) const
|
||||||
|
{
|
||||||
|
nlohmann::json j;
|
||||||
|
|
||||||
|
for (auto const& v: n_array)
|
||||||
|
j.push_back(boost::apply_visitor(mstch_node_to_json(), v));
|
||||||
|
|
||||||
|
return j;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// catch other types that are non-numeric and not listed above
|
||||||
|
template<typename T>
|
||||||
|
std::enable_if_t<!std::is_arithmetic<T>::value, nlohmann::json>
|
||||||
|
operator()(const T&) const {
|
||||||
|
return nlohmann::json {};
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
namespace mstch
|
||||||
|
{
|
||||||
|
namespace internal
|
||||||
|
{
|
||||||
|
// add conversion from mstch::map to nlohmann::json
|
||||||
|
void
|
||||||
|
to_json(nlohmann::json& j, mstch::map const &m)
|
||||||
|
{
|
||||||
|
for (auto const& kv: m)
|
||||||
|
j[kv.first] = boost::apply_visitor(mstch_node_to_json(), kv.second);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
namespace xmreg
|
namespace xmreg
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -124,6 +189,8 @@ using namespace std;
|
||||||
using epee::string_tools::pod_to_hex;
|
using epee::string_tools::pod_to_hex;
|
||||||
using epee::string_tools::hex_to_pod;
|
using epee::string_tools::hex_to_pod;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief The tx_details struct
|
* @brief The tx_details struct
|
||||||
*
|
*
|
||||||
|
@ -2663,7 +2730,7 @@ public:
|
||||||
"Its prefix is: {:s}",
|
"Its prefix is: {:s}",
|
||||||
data_prefix);
|
data_prefix);
|
||||||
|
|
||||||
cout << msg << endl;
|
cerr << msg << endl;
|
||||||
|
|
||||||
return string(msg);
|
return string(msg);
|
||||||
}
|
}
|
||||||
|
@ -2672,6 +2739,11 @@ public:
|
||||||
crypto::hash tx_prefix_hash_from_blob;
|
crypto::hash tx_prefix_hash_from_blob;
|
||||||
cryptonote::transaction tx_from_blob;
|
cryptonote::transaction tx_from_blob;
|
||||||
|
|
||||||
|
// std::stringstream ss;
|
||||||
|
// ss << tx_data_blob;
|
||||||
|
// binary_archive<false> ba(ss);
|
||||||
|
// serialization::serialize(ba, tx_from_blob);
|
||||||
|
|
||||||
if (!cryptonote::parse_and_validate_tx_from_blob(tx_data_blob,
|
if (!cryptonote::parse_and_validate_tx_from_blob(tx_data_blob,
|
||||||
tx_from_blob,
|
tx_from_blob,
|
||||||
tx_hash_from_blob,
|
tx_hash_from_blob,
|
||||||
|
@ -3971,6 +4043,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 +4294,56 @@ 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
// get detailed tx information
|
||||||
|
mstch::map tx_context = construct_tx_context(tx, 1 /*full detailed */);
|
||||||
|
|
||||||
|
// remove some page specific and html stuff
|
||||||
|
tx_context.erase("timescales");
|
||||||
|
tx_context.erase("tx_json");
|
||||||
|
tx_context.erase("tx_json_raw");
|
||||||
|
tx_context.erase("enable_mixins_details");
|
||||||
|
tx_context.erase("with_ring_signatures");
|
||||||
|
tx_context.erase("show_part_of_inputs");
|
||||||
|
tx_context.erase("show_more_details_link");
|
||||||
|
tx_context.erase("max_no_of_inputs_to_show");
|
||||||
|
tx_context.erase("inputs_xmr_sum_not_zero");
|
||||||
|
tx_context.erase("have_raw_tx");
|
||||||
|
tx_context.erase("have_any_unknown_amount");
|
||||||
|
tx_context.erase("has_error");
|
||||||
|
tx_context.erase("error_msg");
|
||||||
|
tx_context.erase("server_time");
|
||||||
|
tx_context.erase("construction_time");
|
||||||
|
|
||||||
|
j_data = tx_context;
|
||||||
|
|
||||||
|
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 +6270,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)
|
||||||
|
|
|
@ -370,6 +370,7 @@ calc_median(It it_begin, It it_end)
|
||||||
void
|
void
|
||||||
pause_execution(uint64_t no_seconds, const string& text = "now");
|
pause_execution(uint64_t no_seconds, const string& text = "now");
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif //XMREG01_TOOLS_H
|
#endif //XMREG01_TOOLS_H
|
Loading…
Reference in New Issue