mirror of
https://github.com/wownero/wownero-cpp.git
synced 2026-10-18 07:41:32 +02:00
added SerializableStruct which defines serialize() and toPropertyTree()
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
#include "utils/MoneroUtils.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <iostream>
|
||||
#include "mnemonics/electrum-words.h"
|
||||
#include "mnemonics/english.h"
|
||||
|
||||
using namespace cryptonote;
|
||||
using namespace epee;
|
||||
|
||||
/**
|
||||
* Public interface for libmonero-cpp library.
|
||||
*/
|
||||
namespace monero {
|
||||
|
||||
string SerializableStruct::serialize() {
|
||||
boost::property_tree::ptree node;
|
||||
toPropertyTree(node);
|
||||
return MoneroUtils::serialize(node);
|
||||
}
|
||||
|
||||
// ---------------------------- PRIVATE HELPERS -----------------------------
|
||||
|
||||
}
|
||||
@@ -1,6 +1,9 @@
|
||||
#include "utils/MoneroUtils.h"
|
||||
#include "include_base_utils.h"
|
||||
#include "common/util.h"
|
||||
#include "wallet/wallet2.h" // TODO: this is imported so BEGIN_KV_SERIALIZE_MAP works; more precise import?
|
||||
#include <boost/property_tree/ptree.hpp>
|
||||
#include <boost/property_tree/json_parser.hpp>
|
||||
|
||||
using namespace std;
|
||||
|
||||
@@ -9,6 +12,26 @@ using namespace std;
|
||||
*/
|
||||
namespace monero {
|
||||
|
||||
/**
|
||||
* Base struct model which is serializable.
|
||||
*/
|
||||
struct SerializableStruct {
|
||||
|
||||
/**
|
||||
* Serializes the struct to a json string.
|
||||
*
|
||||
* @return the struct serialized to a json string
|
||||
*/
|
||||
string serialize();
|
||||
|
||||
/**
|
||||
* Initializes a property tree node from this struct.
|
||||
*
|
||||
* @param node is the node to initialize
|
||||
*/
|
||||
virtual void toPropertyTree(boost::property_tree::ptree& node);
|
||||
};
|
||||
|
||||
/**
|
||||
* Enumerates Monero network types.
|
||||
*/
|
||||
|
||||
@@ -114,6 +114,12 @@ void MoneroUtils::binaryBlocksToJson(const std::string &bin, std::string &json)
|
||||
// throw runtime_error("deserializeOutputWallet(outputStr) not implemented");
|
||||
//}
|
||||
|
||||
string MoneroUtils::serialize(const boost::property_tree::ptree& node) {
|
||||
std::stringstream ss;
|
||||
boost::property_tree::write_json(ss, node, false);
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
boost::property_tree::ptree MoneroUtils::toPropertyTree(const MoneroAccount& account) {
|
||||
cout << "toPropertyTree(account)" << endl;
|
||||
boost::property_tree::ptree accountNode;
|
||||
|
||||
@@ -5,8 +5,6 @@
|
||||
#include "cryptonote_basic/cryptonote_basic.h"
|
||||
#include "serialization/keyvalue_serialization.h" // TODO: consolidate with other binary deps?
|
||||
#include "storages/portable_storage.h"
|
||||
#include <boost/property_tree/ptree.hpp>
|
||||
#include <boost/property_tree/json_parser.hpp>
|
||||
|
||||
/**
|
||||
* Collection of utilities for working with Monero's binary portable storage format.
|
||||
@@ -62,6 +60,8 @@ namespace MoneroUtils
|
||||
// return str;
|
||||
// }
|
||||
|
||||
string serialize(const boost::property_tree::ptree& node);
|
||||
|
||||
boost::property_tree::ptree toPropertyTree(const MoneroAccount& account);
|
||||
|
||||
boost::property_tree::ptree toPropertyTree(const MoneroSubaddress& subaddress);
|
||||
|
||||
Reference in New Issue
Block a user