From ce86e0934ab2a459d456d25ab54fc7ecfa1d2d15 Mon Sep 17 00:00:00 2001 From: woodser Date: Fri, 7 Jun 2019 14:39:37 -0400 Subject: [PATCH] partial serialization of tx wallet and transfer --- src/wallet/MoneroWallet.cpp | 48 ++++++++++++++++++++++++++++++------- src/wallet/MoneroWallet.h | 8 ++++++- 2 files changed, 47 insertions(+), 9 deletions(-) diff --git a/src/wallet/MoneroWallet.cpp b/src/wallet/MoneroWallet.cpp index 1afec20..54675b0 100644 --- a/src/wallet/MoneroWallet.cpp +++ b/src/wallet/MoneroWallet.cpp @@ -24,13 +24,14 @@ namespace monero { 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 MoneroSubaddress& subaddress : subaddresses) { - subaddressesNode.push_back(std::make_pair("", subaddress.toPropertyTree())); - } - node.add_child("subaddresses", subaddressesNode); - } + if (!subaddresses.empty()) node.add_child("subaddresses", MoneroUtils::toPropertyTree(subaddresses)); +// if (!subaddresses.empty()) { +// boost::property_tree::ptree subaddressesNode; +// for (const MoneroSubaddress& subaddress : subaddresses) { +// subaddressesNode.push_back(std::make_pair("", subaddress.toPropertyTree())); +// } +// node.add_child("subaddresses", subaddressesNode); +// } return node; } @@ -51,7 +52,13 @@ namespace monero { boost::property_tree::ptree MoneroTxWallet::toPropertyTree() const { cout << "MoneroTxWallet::toPropertyTree(node)" << endl; - throw runtime_error("Not implemented"); + boost::property_tree::ptree node = MoneroTx::toPropertyTree(); + if (!vouts.empty()) throw runtime_error("vouts not implemented"); + if (!incomingTransfers.empty()) MoneroUtils::toPropertyTree(incomingTransfers); + if (outgoingTransfer != boost::none) throw runtime_error("outgoingTransfers not implemented"); + if (numSuggestedConfirmations != boost::none) node.put("numSuggestedConfirmations", *numSuggestedConfirmations); + if (note != boost::none) node.put("note", *note); + return node; } boost::property_tree::ptree MoneroTxRequest::toPropertyTree() const { @@ -59,6 +66,31 @@ namespace monero { throw runtime_error("Not implemented"); } + boost::property_tree::ptree MoneroTransfer::toPropertyTree() const { + cout << "MoneroTransfer::toPropertyTree(node)" << endl; + boost::property_tree::ptree node; + if (amount != boost::none) node.put("amount", *amount); + if (accountIndex != boost::none) node.put("accountIndex", *accountIndex); + return node; + } + + boost::property_tree::ptree MoneroIncomingTransfer::toPropertyTree() const { + cout << "MoneroIncomingTransfer::toPropertyTree(node)" << endl; + boost::property_tree::ptree node; + if (subaddressIndex != boost::none) node.put("subaddressIndex", *subaddressIndex); + if (address != boost::none) node.put("address", *address); + return node; + } + + boost::property_tree::ptree MoneroOutgoingTransfer::toPropertyTree() const { + cout << "MoneroOutgoingTransfer::toPropertyTree(node)" << endl; + boost::property_tree::ptree node; + if (!subaddressIndices.empty()) throw runtime_error("subaddressIndices not implemented"); + if (!addresses.empty()) throw runtime_error("addresses not implemented"); + if (!destinations.empty()) throw runtime_error("destinations not implemented"); + return node; + } + //boost::property_tree::ptree MoneroUtils::txWalletToPropertyTree(const MoneroTxWallet& tx) { // cout << "txWalletToPropertyTree(tx)" << endl; // boost::property_tree::ptree txNode = txToPropertyTree(tx); diff --git a/src/wallet/MoneroWallet.h b/src/wallet/MoneroWallet.h index 087fc9e..d487234 100644 --- a/src/wallet/MoneroWallet.h +++ b/src/wallet/MoneroWallet.h @@ -93,11 +93,13 @@ namespace monero { /** * Models a base transfer of funds to or from the wallet. */ - struct MoneroTransfer { + struct MoneroTransfer : SerializableStruct { shared_ptr tx; boost::optional amount; boost::optional accountIndex; boost::optional isIncoming; + + boost::property_tree::ptree toPropertyTree() const; }; /** @@ -106,6 +108,8 @@ namespace monero { struct MoneroIncomingTransfer : public MoneroTransfer { boost::optional subaddressIndex; boost::optional address; + + boost::property_tree::ptree toPropertyTree() const; }; /** @@ -115,6 +119,8 @@ namespace monero { vector subaddressIndices; vector addresses; vector destinations; + + boost::property_tree::ptree toPropertyTree() const; }; /**