define MoneroTransferRequest MoneroOutputRequest

remove deserialization since jni is only use case currently
This commit is contained in:
woodser
2019-06-05 10:19:05 -04:00
parent 975278f7cf
commit 12fa13d3c1
3 changed files with 84 additions and 90 deletions
+50 -63
View File
@@ -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<uint64_t>(std::make_shared<uint64_t>((uint64_t) 7));
tx.block = std::shared_ptr<MoneroBlock>(std::make_shared<MoneroBlock>(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;
}
+22 -24
View File
@@ -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 <class T> string serialize(const vector<T> 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 <class T> boost::property_tree::ptree toPropertyTree(const vector<T> 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 <class T> string serialize(const vector<T> 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.
*
+12 -3
View File
@@ -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<uint64_t> amount;
shared_ptr<uint32_t> accountIndex;
struct MoneroTransferRequest : public MoneroTransfer {
shared_ptr<bool> isIncoming;
shared_ptr<string> address;
vector<string> addresses;
@@ -167,6 +165,17 @@ namespace monero {
shared_ptr<MoneroTransferRequest> 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<uint32_t> subaddressIndices;
shared_ptr<MoneroTxRequest> txRequest;
};
// --------------------------------- LISTENERS ------------------------------
// class i_wallet2_callback