mirror of
https://github.com/monero-project/monero.git
synced 2025-08-05 19:14:19 -04:00
Various improvements to the ZMQ JSON-RPC handling:
- Finding handling function in ZMQ JSON-RPC now uses binary search - Temporary `std::vector`s in JSON output now use `epee::span` to prevent allocations. - Binary -> hex in JSON output no longer allocates temporary buffer - C++ structs -> JSON skips intermediate DOM creation, and instead write directly to an output stream.
This commit is contained in:
parent
b4e1dc83d2
commit
0f78b06e8c
12 changed files with 832 additions and 1029 deletions
|
@ -3,6 +3,8 @@
|
|||
#include <boost/range/adaptor/indexed.hpp>
|
||||
#include <gtest/gtest.h>
|
||||
#include <rapidjson/document.h>
|
||||
#include <rapidjson/stringbuffer.h>
|
||||
#include <rapidjson/writer.h>
|
||||
#include <vector>
|
||||
|
||||
#include "crypto/hash.h"
|
||||
|
@ -80,6 +82,27 @@ namespace
|
|||
|
||||
return tx;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
T test_json(const T& value)
|
||||
{
|
||||
rapidjson::StringBuffer buffer;
|
||||
{
|
||||
rapidjson::Writer<rapidjson::StringBuffer> dest{buffer};
|
||||
cryptonote::json::toJsonValue(dest, value);
|
||||
}
|
||||
|
||||
rapidjson::Document doc;
|
||||
doc.Parse(buffer.GetString());
|
||||
if (doc.HasParseError() || !doc.IsObject())
|
||||
{
|
||||
throw cryptonote::json::PARSE_FAIL();
|
||||
}
|
||||
|
||||
T out{};
|
||||
cryptonote::json::fromJsonValue(doc, out);
|
||||
return out;
|
||||
}
|
||||
} // anonymous
|
||||
|
||||
TEST(JsonSerialization, MinerTransaction)
|
||||
|
@ -91,11 +114,7 @@ TEST(JsonSerialization, MinerTransaction)
|
|||
crypto::hash tx_hash{};
|
||||
ASSERT_TRUE(cryptonote::get_transaction_hash(miner_tx, tx_hash));
|
||||
|
||||
rapidjson::Document doc;
|
||||
cryptonote::json::toJsonValue(doc, miner_tx, doc);
|
||||
|
||||
cryptonote::transaction miner_tx_copy;
|
||||
cryptonote::json::fromJsonValue(doc, miner_tx_copy);
|
||||
cryptonote::transaction miner_tx_copy = test_json(miner_tx);
|
||||
|
||||
crypto::hash tx_copy_hash{};
|
||||
ASSERT_TRUE(cryptonote::get_transaction_hash(miner_tx_copy, tx_copy_hash));
|
||||
|
@ -126,11 +145,7 @@ TEST(JsonSerialization, RegularTransaction)
|
|||
crypto::hash tx_hash{};
|
||||
ASSERT_TRUE(cryptonote::get_transaction_hash(tx, tx_hash));
|
||||
|
||||
rapidjson::Document doc;
|
||||
cryptonote::json::toJsonValue(doc, tx, doc);
|
||||
|
||||
cryptonote::transaction tx_copy;
|
||||
cryptonote::json::fromJsonValue(doc, tx_copy);
|
||||
cryptonote::transaction tx_copy = test_json(tx);
|
||||
|
||||
crypto::hash tx_copy_hash{};
|
||||
ASSERT_TRUE(cryptonote::get_transaction_hash(tx_copy, tx_copy_hash));
|
||||
|
@ -161,11 +176,7 @@ TEST(JsonSerialization, RingctTransaction)
|
|||
crypto::hash tx_hash{};
|
||||
ASSERT_TRUE(cryptonote::get_transaction_hash(tx, tx_hash));
|
||||
|
||||
rapidjson::Document doc;
|
||||
cryptonote::json::toJsonValue(doc, tx, doc);
|
||||
|
||||
cryptonote::transaction tx_copy;
|
||||
cryptonote::json::fromJsonValue(doc, tx_copy);
|
||||
cryptonote::transaction tx_copy = test_json(tx);
|
||||
|
||||
crypto::hash tx_copy_hash{};
|
||||
ASSERT_TRUE(cryptonote::get_transaction_hash(tx_copy, tx_copy_hash));
|
||||
|
@ -196,11 +207,7 @@ TEST(JsonSerialization, BulletproofTransaction)
|
|||
crypto::hash tx_hash{};
|
||||
ASSERT_TRUE(cryptonote::get_transaction_hash(tx, tx_hash));
|
||||
|
||||
rapidjson::Document doc;
|
||||
cryptonote::json::toJsonValue(doc, tx, doc);
|
||||
|
||||
cryptonote::transaction tx_copy;
|
||||
cryptonote::json::fromJsonValue(doc, tx_copy);
|
||||
cryptonote::transaction tx_copy = test_json(tx);
|
||||
|
||||
crypto::hash tx_copy_hash{};
|
||||
ASSERT_TRUE(cryptonote::get_transaction_hash(tx_copy, tx_copy_hash));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue