diff --git a/src/utils/MoneroUtils.cpp b/src/utils/MoneroUtils.cpp index 472e5df..a56464f 100644 --- a/src/utils/MoneroUtils.cpp +++ b/src/utils/MoneroUtils.cpp @@ -72,69 +72,24 @@ void MoneroUtils::binaryBlocksToJson(const std::string &bin, std::string &json) json = ss.str(); } -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; - boost::property_tree::ptree subaddressNode; - if (subaddress.accountIndex != nullptr) subaddressNode.put("accountIndex", *subaddress.accountIndex); - if (subaddress.index != nullptr) subaddressNode.put("index", *subaddress.index); - if (subaddress.address != nullptr) subaddressNode.put("address", *subaddress.address); - if (subaddress.label != nullptr) subaddressNode.put("label", *subaddress.label); - if (subaddress.balance != nullptr) subaddressNode.put("balance", *subaddress.balance); - if (subaddress.unlockedBalance != nullptr) subaddressNode.put("unlockedBalance", *subaddress.unlockedBalance); - if (subaddress.numUnspentOutputs != nullptr) subaddressNode.put("numUnspentOutputs", *subaddress.numUnspentOutputs); - if (subaddress.isUsed != nullptr) subaddressNode.put("isUsed", *subaddress.isUsed); - if (subaddress.numBlocksToUnlock != nullptr) subaddressNode.put("numBlocksToUnlock", *subaddress.numBlocksToUnlock); - return subaddressNode; -} - -void MoneroUtils::toModel(const boost::property_tree::ptree& node, MoneroTxWallet& tx) { - cout << "toModel(txWallet)" << endl; - for (boost::property_tree::ptree::const_iterator it = node.begin(); it != node.end(); ++it) { - string key = it->first; - if (key == string("height")) { - cout << "Setting height!" << endl; - MoneroBlock block; - block.height = std::shared_ptr(std::make_shared((uint64_t) 7)); - tx.block = std::shared_ptr(std::make_shared(block)); - } - } -} - -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 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"); //} @@ -158,3 +113,35 @@ string MoneroUtils::serialize(const MoneroSubaddress& subaddress) { //void MoneroUtils::deserializeOutputWallet(const string& outputStr, MoneroOutputWallet& output) { // throw runtime_error("deserializeOutputWallet(outputStr) 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; + boost::property_tree::ptree subaddressNode; + if (subaddress.accountIndex != nullptr) subaddressNode.put("accountIndcd ex", *subaddress.accountIndex); + if (subaddress.index != nullptr) subaddressNode.put("index", *subaddress.index); + if (subaddress.address != nullptr) subaddressNode.put("address", *subaddress.address); + if (subaddress.label != nullptr) subaddressNode.put("label", *subaddress.label); + if (subaddress.balance != nullptr) subaddressNode.put("balance", *subaddress.balance); + if (subaddress.unlockedBalance != nullptr) subaddressNode.put("unlockedBalance", *subaddress.unlockedBalance); + if (subaddress.numUnspentOutputs != nullptr) subaddressNode.put("numUnspentOutputs", *subaddress.numUnspentOutputs); + if (subaddress.isUsed != nullptr) subaddressNode.put("isUsed", *subaddress.isUsed); + if (subaddress.numBlocksToUnlock != nullptr) subaddressNode.put("numBlocksToUnlock", *subaddress.numBlocksToUnlock); + return subaddressNode; +} diff --git a/src/utils/MoneroUtils.h b/src/utils/MoneroUtils.h index 0378c40..8da5a10 100644 --- a/src/utils/MoneroUtils.h +++ b/src/utils/MoneroUtils.h @@ -28,9 +28,9 @@ namespace MoneroUtils // 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); // @@ -44,12 +44,29 @@ namespace MoneroUtils // // void deserializeOutputWallet(const string& outputStr, MoneroOutputWallet& output); + // template string serialize(const vector 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; + // } + boost::property_tree::ptree toPropertyTree(const MoneroAccount& account); boost::property_tree::ptree toPropertyTree(const MoneroSubaddress& subaddress); - void toModel(const boost::property_tree::ptree& node, MoneroTxWallet& tx); - + // // 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 boost::property_tree::ptree toPropertyTree(const vector types) { cout << "toPropertyTree(types)" << endl; boost::property_tree::ptree typeNodes; @@ -59,25 +76,6 @@ namespace MoneroUtils 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 string serialize(const vector 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. * diff --git a/src/wallet/MoneroWallet.h b/src/wallet/MoneroWallet.h index 6a0907a..76139d9 100644 --- a/src/wallet/MoneroWallet.h +++ b/src/wallet/MoneroWallet.h @@ -137,9 +137,7 @@ namespace monero { * * All transfers are returned except those that do not meet the criteria defined in this request. */ - struct MoneroTransferRequest { - shared_ptr amount; - shared_ptr accountIndex; + struct MoneroTransferRequest : public MoneroTransfer { shared_ptr isIncoming; shared_ptr address; vector addresses; @@ -167,6 +165,17 @@ namespace monero { shared_ptr transferRequest; }; + /** + * Configures a request to retrieve wallet outputs (i.e. outputs that the wallet has or had the + * ability to spend). + * + * All outputs are returned except those that do not meet the criteria defined in this request. + */ + struct MoneroOutputRequest : public MoneroOutput { + vector subaddressIndices; + shared_ptr txRequest; + }; + // --------------------------------- LISTENERS ------------------------------ // class i_wallet2_callback