compiling with toPropertyTree() overrides

This commit is contained in:
woodser
2019-06-07 12:35:37 -04:00
parent 628bcf330f
commit e5fb07e2fc
4 changed files with 25 additions and 31 deletions
+8 -10
View File
@@ -12,28 +12,25 @@ namespace monero {
// -------------------------- MODEL SERIALIZATION ---------------------------
string SerializableStruct::serialize() const {
return MoneroUtils::serialize(toPropertyTree2());
return MoneroUtils::serialize(toPropertyTree());
}
boost::property_tree::ptree SerializableStruct::toPropertyTree2() const {
boost::property_tree::ptree node;
toPropertyTree(node);
return node;
}
void MoneroBlockHeader::toPropertyTree(boost::property_tree::ptree& node) const {
boost::property_tree::ptree MoneroBlockHeader::toPropertyTree() const {
cout << "MoneroBlockHeader::toPropertyTree(block)" << endl;
throw runtime_error("not implemented");
}
void MoneroBlock::toPropertyTree(boost::property_tree::ptree& node) const {
boost::property_tree::ptree MoneroBlock::toPropertyTree() const {
cout << "MoneroBlock::toPropertyTree(block)" << endl;
boost::property_tree::ptree node;
if (height != boost::none) node.put("height", *height); // TODO: finish this, add txs
//node.add_child("txs", toPropertyTree(txs)); // TODO: txs is vector<shared_ptr<MoneroTx>> so need to handle
return node;
}
void MoneroTx::toPropertyTree(boost::property_tree::ptree& node) const {
boost::property_tree::ptree MoneroTx::toPropertyTree() const {
cout << "MoneroTx::txToPropertyTree(tx)" << endl;
boost::property_tree::ptree node;
if (id != boost::none) node.put("id", *id);
if (version != boost::none) node.put("version", *version);
if (isCoinbase != boost::none) node.put("isCoinbase", *isCoinbase);
@@ -71,6 +68,7 @@ namespace monero {
if (maxUsedBlockHeight != boost::none) node.put("maxUsedBlockHeight", *maxUsedBlockHeight);
if (maxUsedBlockId != boost::none) node.put("maxUsedBlockId", *maxUsedBlockId);
if (!signatures.empty()) throw runtime_error("not implemented");
return node;
}
// ---------------------------- PRIVATE HELPERS -----------------------------
+4 -11
View File
@@ -27,14 +27,7 @@ namespace monero {
*
* @return the converted property tree
*/
boost::property_tree::ptree toPropertyTree2() const;
/**
* Convert the struct to a property tree.
*
* @param node is the property tree node to initialize from the struct
*/
virtual void toPropertyTree(boost::property_tree::ptree& node) const = 0;
virtual boost::property_tree::ptree toPropertyTree() const = 0;
};
/**
@@ -106,7 +99,7 @@ namespace monero {
boost::optional<string> maxUsedBlockId;
vector<string> signatures;
void toPropertyTree(boost::property_tree::ptree& node) const;
boost::property_tree::ptree toPropertyTree() const;
};
/**
@@ -131,7 +124,7 @@ namespace monero {
boost::optional<string> prevId;
boost::optional<uint64_t> reward;
void toPropertyTree(boost::property_tree::ptree& node) const;
boost::property_tree::ptree toPropertyTree() const;
};
/**
@@ -143,7 +136,7 @@ namespace monero {
vector<shared_ptr<MoneroTx>> txs;
vector<string> txIds;
void toPropertyTree(boost::property_tree::ptree& node) const;
boost::property_tree::ptree toPropertyTree() const;
};
/**
+9 -6
View File
@@ -16,23 +16,26 @@ namespace monero {
// -------------------------- MODEL SERIALIZATION ---------------------------
void MoneroAccount::toPropertyTree(boost::property_tree::ptree& node) const {
boost::property_tree::ptree MoneroAccount::toPropertyTree() const {
cout << "MoneroAccount::toPropertyTree(node)" << endl;
boost::property_tree::ptree node;
if (index != boost::none) node.put("index", *index);
if (primaryAddress != boost::none) node.put("primaryAddress", *primaryAddress);
if (balance != boost::none) node.put("balance", *balance);
if (unlockedBalance != boost::none) node.put("unlockedBalance", *unlockedBalance);
if (!subaddresses.empty()) {
boost::property_tree::ptree subaddressesNode;
for (const auto& subaddress : subaddresses) {
subaddressesNode.push_back(std::make_pair("", subaddress.toPropertyTree2()));
for (const MoneroSubaddress& subaddress : subaddresses) {
subaddressesNode.push_back(std::make_pair("", subaddress.toPropertyTree()));
}
node.add_child("subaddresses", subaddressesNode);
}
return node;
}
void MoneroSubaddress::toPropertyTree(boost::property_tree::ptree& node) const {
boost::property_tree::ptree MoneroSubaddress::toPropertyTree() const {
cout << "MoneroSubaddress::toPropertyTree(node)" << endl;
boost::property_tree::ptree node;
if (accountIndex != boost::none) node.put("accountIndex", *accountIndex);
if (index != boost::none) node.put("index", *index);
if (address != boost::none) node.put("address", *address);
@@ -44,11 +47,11 @@ namespace monero {
if (numBlocksToUnlock != boost::none) node.put("numBlocksToUnlock", *numBlocksToUnlock);
}
void MoneroTxWallet::toPropertyTree(boost::property_tree::ptree& node) const {
boost::property_tree::ptree MoneroTxWallet::toPropertyTree() const {
throw runtime_error("Not implemented");
}
void MoneroTxRequest::toPropertyTree(boost::property_tree::ptree& node) const {
boost::property_tree::ptree MoneroTxRequest::toPropertyTree() const {
throw runtime_error("Not implemented");
}
+4 -4
View File
@@ -51,7 +51,7 @@ namespace monero {
// KV_SERIALIZE(numBlocksToUnlock)
// END_KV_SERIALIZE_MAP()
void toPropertyTree(boost::property_tree::ptree& node) const;
boost::property_tree::ptree toPropertyTree() const;
};
/**
@@ -75,7 +75,7 @@ namespace monero {
// KV_SERIALIZE(subaddresses)
// END_KV_SERIALIZE_MAP()
void toPropertyTree(boost::property_tree::ptree& node) const;
boost::property_tree::ptree toPropertyTree() const;
};
// forward declarations
@@ -137,7 +137,7 @@ namespace monero {
boost::optional<uint32_t> numSuggestedConfirmations;
boost::optional<string> note;
virtual void toPropertyTree(boost::property_tree::ptree& node) const;
boost::property_tree::ptree toPropertyTree() const;
};
/**
@@ -178,7 +178,7 @@ namespace monero {
boost::optional<MoneroTransferRequest> transferRequest;
boost::optional<uint64_t> getHeight() { return block == boost::none ? boost::none : (*block)->height; }
virtual void toPropertyTree(boost::property_tree::ptree& node) const;
boost::property_tree::ptree toPropertyTree() const;
};
/**