55 #ifndef monero_utils_h
56 #define monero_utils_h
58 #include "wallet/monero_wallet_model.h"
59 #include "cryptonote_basic/cryptonote_basic.h"
60 #include "serialization/keyvalue_serialization.h"
61 #include "storages/portable_storage.h"
68 using namespace cryptonote;
72 static const int RING_SIZE = 12;
76 void json_to_binary(
const std::string &json, std::string &bin);
77 void binary_to_json(
const std::string &bin, std::string &json);
78 void binary_blocks_to_json(
const std::string &bin, std::string &json);
82 std::string serialize(
const rapidjson::Document& doc);
84 void addJsonMember(std::string key, uint8_t val, rapidjson::Document::AllocatorType& allocator, rapidjson::Value& root, rapidjson::Value& field);
85 void addJsonMember(std::string key, uint32_t val, rapidjson::Document::AllocatorType& allocator, rapidjson::Value& root, rapidjson::Value& field);
86 void addJsonMember(std::string key, uint64_t val, rapidjson::Document::AllocatorType& allocator, rapidjson::Value& root, rapidjson::Value& field);
87 void addJsonMember(std::string key, std::string val, rapidjson::Document::AllocatorType& allocator, rapidjson::Value& root, rapidjson::Value& field);
88 void addJsonMember(std::string key,
bool val, rapidjson::Document::AllocatorType& allocator, rapidjson::Value& root);
91 template <
class T> rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator,
const std::vector<std::shared_ptr<T>>& vals) {
92 rapidjson::Value value_arr(rapidjson::kArrayType);
93 for (
const auto& val : vals) {
94 value_arr.PushBack(val->to_rapidjson_val(allocator), allocator);
100 template <
class T> rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator,
const std::vector<T>& vals) {
101 rapidjson::Value value_arr(rapidjson::kArrayType);
102 for (
const auto& val : vals) {
103 value_arr.PushBack(val.to_rapidjson_val(allocator), allocator);
108 rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator,
const std::vector<std::string>& strs);
109 rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator,
const std::vector<uint8_t>& nums);
110 rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator,
const std::vector<uint32_t>& nums);
111 rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator,
const std::vector<uint64_t>& nums);
117 std::string serialize(
const boost::property_tree::ptree& node);
118 void deserialize(
const std::string& json, boost::property_tree::ptree& root);
136 std::shared_ptr<monero_block>
cn_block_to_block(
const cryptonote::block& cn_block);
145 std::shared_ptr<monero_tx>
cn_tx_to_tx(
const cryptonote::transaction& cn_tx,
bool init_as_tx_wallet =
false);
152 static std::string get_pruned_tx_json(cryptonote::transaction &tx)
154 std::stringstream ss;
155 json_archive<true> ar(ss);
156 bool r = tx.serialize_base(ar);
157 CHECK_AND_ASSERT_MES(r, std::string(),
"Failed to serialize rct signatures base");
166 static void free(std::shared_ptr<monero_block> block) {
167 for (std::shared_ptr<monero_tx>& tx : block->m_txs) {
170 if (tx_wallet !=
nullptr) {
171 if (tx_wallet->m_outgoing_transfer != boost::none) tx_wallet->m_outgoing_transfer.get()->m_tx.reset();
172 for (std::shared_ptr<monero_transfer> transfer : tx_wallet->m_incoming_transfers) transfer->m_tx.reset();
173 for (std::shared_ptr<monero_output> output : tx_wallet->m_outputs) output->m_tx.reset();
174 for (std::shared_ptr<monero_output> input : tx_wallet->m_inputs) {
175 input->m_key_image.reset();
188 static void free(std::vector<std::shared_ptr<monero_block>> blocks) {
189 for (std::shared_ptr<monero_block>& block : blocks) monero_utils::free(block);