add MoneroUtils.serialize(vector<MoneroBlock>);

model unique_ptr -> shared_ptr;
This commit is contained in:
woodser
2019-06-03 17:32:42 -04:00
parent 25e0d2befd
commit 6df3ac1a0a
4 changed files with 67 additions and 60 deletions
+28 -24
View File
@@ -34,34 +34,34 @@ void MoneroUtils::binaryBlocksToJson(const std::string &bin, std::string &json)
boost::property_tree::ptree txsNodes; // array of txs per block (array of array)
for (int blockIdx = 0; blockIdx < resp_struct.blocks.size(); blockIdx++) {
// parse and validate block
cryptonote::block block;
if (cryptonote::parse_and_validate_block_from_blob(resp_struct.blocks[blockIdx].block, block)) {
// parse and validate block
cryptonote::block block;
if (cryptonote::parse_and_validate_block_from_blob(resp_struct.blocks[blockIdx].block, block)) {
// add block node to blocks node
boost::property_tree::ptree blockNode;
blockNode.put("", cryptonote::obj_to_json_str(block)); // TODO: no pretty print
blocksNode.push_back(std::make_pair("", blockNode));
// add block node to blocks node
boost::property_tree::ptree blockNode;
blockNode.put("", cryptonote::obj_to_json_str(block)); // TODO: no pretty print
blocksNode.push_back(std::make_pair("", blockNode));
} else {
throw std::runtime_error("failed to parse block blob at index " + std::to_string(blockIdx));
}
// parse and validate txs
boost::property_tree::ptree txsNode;
for (int txIdx = 0; txIdx < resp_struct.blocks[blockIdx].txs.size(); txIdx++) {
cryptonote::transaction tx;
if (cryptonote::parse_and_validate_tx_from_blob(resp_struct.blocks[blockIdx].txs[txIdx], tx)) {
// add tx node to txs node
boost::property_tree::ptree txNode;
//std::cout << "PRUNED:\n" << MoneroUtils::get_pruned_tx_json(tx) << "\n";
txNode.put("", MoneroUtils::get_pruned_tx_json(tx)); // TODO: no pretty print
txsNode.push_back(std::make_pair("", txNode));
} else {
throw std::runtime_error("failed to parse block blob at index " + std::to_string(blockIdx));
}
// parse and validate txs
boost::property_tree::ptree txsNode;
for (int txIdx = 0; txIdx < resp_struct.blocks[blockIdx].txs.size(); txIdx++) {
cryptonote::transaction tx;
if (cryptonote::parse_and_validate_tx_from_blob(resp_struct.blocks[blockIdx].txs[txIdx], tx)) {
// add tx node to txs node
boost::property_tree::ptree txNode;
//std::cout << "PRUNED:\n" << MoneroUtils::get_pruned_tx_json(tx) << "\n";
txNode.put("", MoneroUtils::get_pruned_tx_json(tx)); // TODO: no pretty print
txsNode.push_back(std::make_pair("", txNode));
} else {
throw std::runtime_error("failed to parse tx blob at index " + std::to_string(txIdx));
}
}
txsNodes.push_back(std::make_pair("", txsNode)); // array of array of transactions, one array per block
}
txsNodes.push_back(std::make_pair("", txsNode)); // array of array of transactions, one array per block
}
root.add_child("blocks", blocksNode);
root.add_child("txs", txsNodes);
@@ -73,3 +73,7 @@ void MoneroUtils::binaryBlocksToJson(const std::string &bin, std::string &json)
boost::property_tree::write_json(ss, root, false/*pretty*/);
json = ss.str();
}
string MoneroUtils::serialize(vector<MoneroBlock> blocks) {
throw runtime_error("Not implemented");
}