mirror of
https://github.com/wownero/wownero-cpp.git
synced 2026-10-23 10:08:33 +02:00
serializing accounts manually;
testGetAccountsWithoutSubaddresse passing
This commit is contained in:
+40
-16
@@ -72,22 +72,46 @@ void MoneroUtils::binaryBlocksToJson(const std::string &bin, std::string &json)
|
||||
json = ss.str();
|
||||
}
|
||||
|
||||
//string MoneroUtils::serialize(const MoneroAccount& account) {
|
||||
//
|
||||
// // build property tree from account
|
||||
// boost::property_tree::ptree accountNode;
|
||||
// addNode(accountNode, string("index"), account.index);
|
||||
//
|
||||
// // convert root to string
|
||||
// std::stringstream ss;
|
||||
// boost::property_tree::write_json(ss, accountNode, false);
|
||||
// return ss.str();
|
||||
//}
|
||||
//
|
||||
//string MoneroUtils::serialize(const MoneroSubaddress& subaddress) {
|
||||
// throw runtime_error("serialize(subaddress) not implemented");
|
||||
//}
|
||||
//
|
||||
boost::property_tree::ptree MoneroUtils::toPropertyTree(const MoneroAccount& account) {
|
||||
cout << "toPropertyTree(account)" << endl;
|
||||
boost::property_tree::ptree accountNode;
|
||||
if (account.index != nullptr) accountNode.put("index", *account.index);
|
||||
if (account.primaryAddress != nullptr) accountNode.put("primaryAddress", *account.primaryAddress);
|
||||
if (account.balance != nullptr) accountNode.put("balance", *account.balance);
|
||||
if (account.unlockedBalance != nullptr) accountNode.put("unlockedBalance", *account.unlockedBalance);
|
||||
if (!account.subaddresses.empty()) {
|
||||
boost::property_tree::ptree subaddressesNode;
|
||||
for (const auto& subaddress : account.subaddresses) {
|
||||
subaddressesNode.push_back(std::make_pair("", toPropertyTree(subaddress)));
|
||||
}
|
||||
accountNode.add_child("subaddresses", subaddressesNode);
|
||||
}
|
||||
return accountNode;
|
||||
}
|
||||
|
||||
boost::property_tree::ptree MoneroUtils::toPropertyTree(const MoneroSubaddress& subaddress) {
|
||||
cout << "toPropertyTree(subaddress)" << endl;
|
||||
throw runtime_error("Not implemented");
|
||||
}
|
||||
|
||||
string MoneroUtils::serialize(const MoneroAccount& account) {
|
||||
cout << "serialize(account)" << endl;
|
||||
|
||||
// build property tree from account
|
||||
boost::property_tree::ptree accountNode;
|
||||
//addNode(accountNode, string("index"), account.index);
|
||||
|
||||
// convert root to string
|
||||
std::stringstream ss;
|
||||
boost::property_tree::write_json(ss, accountNode, false);
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
string MoneroUtils::serialize(const MoneroSubaddress& subaddress) {
|
||||
cout << "serialize(subaddress)" << endl;
|
||||
throw runtime_error("serialize(subaddress) not implemented");
|
||||
}
|
||||
|
||||
//string MoneroUtils::serialize(const MoneroBlock& block) {
|
||||
// throw runtime_error("serialize(block) not implemented");
|
||||
//}
|
||||
|
||||
+35
-9
@@ -23,20 +23,14 @@ namespace MoneroUtils
|
||||
|
||||
void binaryBlocksToJson(const std::string &bin, std::string &json);
|
||||
|
||||
// // TODO: template implementation here, could move to MoneroUtils.hpp per https://stackoverflow.com/questions/3040480/c-template-function-compiles-in-header-but-not-implementation
|
||||
// template <class T> string serialize(const vector<T> types) {
|
||||
// cout << "serialize(types)" << endl;
|
||||
// throw runtime_error("Not implemented");
|
||||
// }
|
||||
//
|
||||
// void addNode(boost::property_tree::ptree root, const string& key, shared_ptr<void> ptr) {
|
||||
// cout << "addNode(...)" << endl;
|
||||
// throw runtime_error("Not implemented");
|
||||
// }
|
||||
//
|
||||
// string serialize(const MoneroAccount& account);
|
||||
//
|
||||
// string serialize(const MoneroSubaddress& subaddress);
|
||||
string serialize(const MoneroAccount& account);
|
||||
|
||||
string serialize(const MoneroSubaddress& subaddress);
|
||||
//
|
||||
// string serialize(const MoneroBlock& block);
|
||||
//
|
||||
@@ -50,6 +44,38 @@ namespace MoneroUtils
|
||||
//
|
||||
// void deserializeOutputWallet(const string& outputStr, MoneroOutputWallet& output);
|
||||
|
||||
boost::property_tree::ptree toPropertyTree(const MoneroAccount& account);
|
||||
|
||||
boost::property_tree::ptree toPropertyTree(const MoneroSubaddress& subaddress);
|
||||
|
||||
template <class T> boost::property_tree::ptree toPropertyTree(const vector<T> types) {
|
||||
cout << "toPropertyTree(types)" << endl;
|
||||
boost::property_tree::ptree typeNodes;
|
||||
for (const auto& type : types) {
|
||||
typeNodes.push_back(std::make_pair("", toPropertyTree(type)));
|
||||
}
|
||||
return typeNodes;
|
||||
}
|
||||
|
||||
// TODO: template implementation here, could move to MoneroUtils.hpp per https://stackoverflow.com/questions/3040480/c-template-function-compiles-in-header-but-not-implementation
|
||||
template <class T> string serialize(const vector<T> types) {
|
||||
cout << "serialize(types)" << endl;
|
||||
boost::property_tree::ptree root;
|
||||
boost::property_tree::ptree typesNode;
|
||||
for (const auto& type : types) {
|
||||
boost::property_tree::ptree typeNode;
|
||||
typeNode.put("", serialize(type));
|
||||
typesNode.push_back(std::make_pair("", typeNode));
|
||||
}
|
||||
root.add_child("types", typesNode);
|
||||
|
||||
// serialize property tree to json
|
||||
std::stringstream ss;
|
||||
boost::property_tree::write_json(ss, root, false);
|
||||
string str = ss.str();
|
||||
return str;
|
||||
}
|
||||
|
||||
/**
|
||||
* Modified from core_rpc_server.cpp to return a string.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user