From e5fb07e2fc4fd9ee4c3c972a666c90d0689cc929 Mon Sep 17 00:00:00 2001 From: woodser Date: Fri, 7 Jun 2019 12:35:37 -0400 Subject: [PATCH] compiling with toPropertyTree() overrides --- src/daemon/MoneroDaemon.cpp | 18 ++++++++---------- src/daemon/MoneroDaemon.h | 15 ++++----------- src/wallet/MoneroWallet.cpp | 15 +++++++++------ src/wallet/MoneroWallet.h | 8 ++++---- 4 files changed, 25 insertions(+), 31 deletions(-) diff --git a/src/daemon/MoneroDaemon.cpp b/src/daemon/MoneroDaemon.cpp index ca994ce..fe5e80f 100644 --- a/src/daemon/MoneroDaemon.cpp +++ b/src/daemon/MoneroDaemon.cpp @@ -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> 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 ----------------------------- diff --git a/src/daemon/MoneroDaemon.h b/src/daemon/MoneroDaemon.h index c482b83..a2b2d1f 100644 --- a/src/daemon/MoneroDaemon.h +++ b/src/daemon/MoneroDaemon.h @@ -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 maxUsedBlockId; vector signatures; - void toPropertyTree(boost::property_tree::ptree& node) const; + boost::property_tree::ptree toPropertyTree() const; }; /** @@ -131,7 +124,7 @@ namespace monero { boost::optional prevId; boost::optional reward; - void toPropertyTree(boost::property_tree::ptree& node) const; + boost::property_tree::ptree toPropertyTree() const; }; /** @@ -143,7 +136,7 @@ namespace monero { vector> txs; vector txIds; - void toPropertyTree(boost::property_tree::ptree& node) const; + boost::property_tree::ptree toPropertyTree() const; }; /** diff --git a/src/wallet/MoneroWallet.cpp b/src/wallet/MoneroWallet.cpp index c0beb94..14f94b6 100644 --- a/src/wallet/MoneroWallet.cpp +++ b/src/wallet/MoneroWallet.cpp @@ -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"); } diff --git a/src/wallet/MoneroWallet.h b/src/wallet/MoneroWallet.h index b597bde..087fc9e 100644 --- a/src/wallet/MoneroWallet.h +++ b/src/wallet/MoneroWallet.h @@ -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 numSuggestedConfirmations; boost::optional note; - virtual void toPropertyTree(boost::property_tree::ptree& node) const; + boost::property_tree::ptree toPropertyTree() const; }; /** @@ -178,7 +178,7 @@ namespace monero { boost::optional transferRequest; boost::optional getHeight() { return block == boost::none ? boost::none : (*block)->height; } - virtual void toPropertyTree(boost::property_tree::ptree& node) const; + boost::property_tree::ptree toPropertyTree() const; }; /**