From f5fd35be54b77fd6385d96bfc7f0bfca55c7c57e Mon Sep 17 00:00:00 2001 From: woodser Date: Fri, 7 Jun 2019 11:51:56 -0400 Subject: [PATCH] compiling with SerializedStruct and refactored dependencies --- CMakeLists.txt | 1 + src/daemon/MoneroDaemon.cpp | 20 +++++++++++--------- src/daemon/MoneroDaemon.h | 17 ++++++++--------- src/wallet/MoneroWallet.cpp | 13 ++++++++++++- src/wallet/MoneroWallet.h | 8 +++++++- 5 files changed, 39 insertions(+), 20 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9889a0f..1fe8685 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -292,6 +292,7 @@ target_link_libraries(scratchpad set( LIBRARY_SRC_FILES + src/daemon/MoneroDaemon.cpp src/wallet/MoneroWallet.cpp src/utils/MoneroUtils.cpp ) diff --git a/src/daemon/MoneroDaemon.cpp b/src/daemon/MoneroDaemon.cpp index 87d807d..390b665 100644 --- a/src/daemon/MoneroDaemon.cpp +++ b/src/daemon/MoneroDaemon.cpp @@ -1,24 +1,26 @@ +#include "MoneroDaemon.h" + #include "utils/MoneroUtils.h" - -#include -#include -#include "mnemonics/electrum-words.h" -#include "mnemonics/english.h" - -using namespace cryptonote; -using namespace epee; +#include "include_base_utils.h" +#include "common/util.h" /** * Public interface for libmonero-cpp library. */ namespace monero { - string SerializableStruct::serialize() { + // -------------------------- MODEL SERIALIZATION --------------------------- + + string SerializableStruct::serialize() const { boost::property_tree::ptree node; toPropertyTree(node); return MoneroUtils::serialize(node); } + void MoneroTx::toPropertyTree(boost::property_tree::ptree& node) const { + throw runtime_error("Not implemented"); + } + // ---------------------------- PRIVATE HELPERS ----------------------------- } diff --git a/src/daemon/MoneroDaemon.h b/src/daemon/MoneroDaemon.h index 08b6a63..650679b 100644 --- a/src/daemon/MoneroDaemon.h +++ b/src/daemon/MoneroDaemon.h @@ -1,7 +1,5 @@ -#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? +#pragma once + #include #include @@ -13,7 +11,7 @@ using namespace std; namespace monero { /** - * Base struct model which is serializable. + * Base struct which can be serialized. */ struct SerializableStruct { @@ -22,14 +20,14 @@ namespace monero { * * @return the struct serialized to a json string */ - string serialize(); + string serialize() const; /** * Initializes a property tree node from this struct. * * @param node is the node to initialize */ - virtual void toPropertyTree(boost::property_tree::ptree& node); + virtual void toPropertyTree(boost::property_tree::ptree& node) const = 0; }; /** @@ -44,7 +42,7 @@ namespace monero { /** * Models a connection to a daemon. * - * TODO: boost::optional? + * TODO: switch to boost::optional */ struct MoneroRpcConnection { string uri; @@ -61,7 +59,7 @@ namespace monero { /** * Models a Monero transaction on the blockchain. */ - struct MoneroTx { + struct MoneroTx : public SerializableStruct { boost::optional> block; boost::optional id; boost::optional version; @@ -100,6 +98,7 @@ namespace monero { boost::optional maxUsedBlockHeight; boost::optional maxUsedBlockId; vector signatures; + virtual void toPropertyTree(boost::property_tree::ptree& node) const; }; /** diff --git a/src/wallet/MoneroWallet.cpp b/src/wallet/MoneroWallet.cpp index e71bc1f..08f4d62 100644 --- a/src/wallet/MoneroWallet.cpp +++ b/src/wallet/MoneroWallet.cpp @@ -1,5 +1,6 @@ -#include "utils/MoneroUtils.h" +#include "wallet/MoneroWallet.h" +#include "utils/MoneroUtils.h" #include #include #include "mnemonics/electrum-words.h" @@ -13,6 +14,16 @@ using namespace epee; */ namespace monero { + // -------------------------- MODEL SERIALIZATION --------------------------- + + void MoneroTxWallet::toPropertyTree(boost::property_tree::ptree& node) const { + throw runtime_error("Not implemented"); + } + + void MoneroTxRequest::toPropertyTree(boost::property_tree::ptree& node) const { + throw runtime_error("Not implemented"); + } + // ---------------------------- PRIVATE HELPERS ----------------------------- bool boolEquals(bool val, const boost::optional& optVal) { diff --git a/src/wallet/MoneroWallet.h b/src/wallet/MoneroWallet.h index 5cb3fdd..34acb04 100644 --- a/src/wallet/MoneroWallet.h +++ b/src/wallet/MoneroWallet.h @@ -1,8 +1,11 @@ +#pragma once + #include "daemon/MoneroDaemon.h" +#include "wallet/wallet2.h" using namespace std; -using namespace monero; using namespace crypto; +using namespace monero; /** * Public interface for libmonero-cpp library. @@ -129,6 +132,8 @@ namespace monero { boost::optional outgoingTransfer; boost::optional numSuggestedConfirmations; boost::optional note; + + virtual void toPropertyTree(boost::property_tree::ptree& node) const; }; /** @@ -169,6 +174,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; }; /**