From 6df3ac1a0ab51405eacec351c228e1abbce0a94a Mon Sep 17 00:00:00 2001 From: woodser Date: Mon, 3 Jun 2019 17:32:42 -0400 Subject: [PATCH] add MoneroUtils.serialize(vector); model unique_ptr -> shared_ptr; --- src/daemon/MoneroDaemon.h | 6 ++-- src/utils/MoneroUtils.cpp | 52 ++++++++++++++++-------------- src/utils/MoneroUtils.h | 3 ++ src/wallet/MoneroWallet.h | 66 +++++++++++++++++++-------------------- 4 files changed, 67 insertions(+), 60 deletions(-) diff --git a/src/daemon/MoneroDaemon.h b/src/daemon/MoneroDaemon.h index 46872c3..311118d 100644 --- a/src/daemon/MoneroDaemon.h +++ b/src/daemon/MoneroDaemon.h @@ -37,7 +37,7 @@ namespace monero { * Models a Monero transaction on the blockchain. */ struct MoneroTx { - unique_ptr block; + shared_ptr block; string id; string version; bool isCoinbase; @@ -70,9 +70,9 @@ namespace monero { string rctSigPrunable; // TODO: implement bool isKeptByBlock; bool isFailed; - unique_ptr lastFailedHeight; + shared_ptr lastFailedHeight; string lastFailedId; - unique_ptr maxUsedBlockHeight; + shared_ptr maxUsedBlockHeight; string maxUsedBlockId; vector signatures; }; diff --git a/src/utils/MoneroUtils.cpp b/src/utils/MoneroUtils.cpp index f46292f..0e47615 100644 --- a/src/utils/MoneroUtils.cpp +++ b/src/utils/MoneroUtils.cpp @@ -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 blocks) { + throw runtime_error("Not implemented"); +} diff --git a/src/utils/MoneroUtils.h b/src/utils/MoneroUtils.h index 9d51fdd..7bf026e 100644 --- a/src/utils/MoneroUtils.h +++ b/src/utils/MoneroUtils.h @@ -1,6 +1,7 @@ #ifndef MoneroUtils_h #define MoneroUtils_h +#include "wallet/MoneroWallet.h" #include "cryptonote_basic/cryptonote_basic.h" #include "serialization/keyvalue_serialization.h" // TODO: consolidate with other binary deps? #include "storages/portable_storage.h" @@ -20,6 +21,8 @@ namespace MoneroUtils void binaryBlocksToJson(const std::string &bin, std::string &json); + string serialize(vector blocks); + /** * Modified from core_rpc_server.cpp to return a string. */ diff --git a/src/wallet/MoneroWallet.h b/src/wallet/MoneroWallet.h index 6dd755e..6c14dc2 100644 --- a/src/wallet/MoneroWallet.h +++ b/src/wallet/MoneroWallet.h @@ -89,7 +89,7 @@ namespace monero { * Models a base transfer of funds to or from the wallet. */ struct MoneroTransfer { - unique_ptr tx; + shared_ptr tx; uint64_t amount; uint32_t accountIndex; bool isIncoming; @@ -117,7 +117,7 @@ namespace monero { */ struct MoneroTxWallet : public MoneroTx { vector incomingTransfers; - unique_ptr outgoingTransfer; + shared_ptr outgoingTransfer; uint32_t numSuggestedConfirmations; string note; }; @@ -128,16 +128,16 @@ namespace monero { * All transfers are returned except those that do not meet the criteria defined in this request. */ struct MoneroTransferRequest { - unique_ptr amount; - unique_ptr accountIndex; - unique_ptr isIncoming; + shared_ptr amount; + shared_ptr accountIndex; + shared_ptr isIncoming; string address; vector addresses; - unique_ptr subaddressIndex; + shared_ptr subaddressIndex; vector subaddressIndices; vector destinations; - unique_ptr hasDestinations; - unique_ptr txRequest; + shared_ptr hasDestinations; + shared_ptr txRequest; }; /** @@ -146,49 +146,49 @@ namespace monero { * All transactions are returned except those that do not meet the criteria defined in this request. */ struct MoneroTxRequest { - unique_ptr block; + shared_ptr block; string id; string version; - unique_ptr isCoinbase; + shared_ptr isCoinbase; string paymentId; - unique_ptr fee; - unique_ptr mixin; - unique_ptr doNotRelay; - unique_ptr isRelayed; - unique_ptr isConfirmed; - unique_ptr inTxPool; - unique_ptr numConfirmations; - unique_ptr unlockTime; - unique_ptr lastRelayedTimestamp; - unique_ptr receivedTimestamp; - unique_ptr isDoubleSpend; + shared_ptr fee; + shared_ptr mixin; + shared_ptr doNotRelay; + shared_ptr isRelayed; + shared_ptr isConfirmed; + shared_ptr inTxPool; + shared_ptr numConfirmations; + shared_ptr unlockTime; + shared_ptr lastRelayedTimestamp; + shared_ptr receivedTimestamp; + shared_ptr isDoubleSpend; string key; string fullHex; string prunedHex; string prunableHex; string prunableHash; - unique_ptr size; - unique_ptr weight; + shared_ptr size; + shared_ptr weight; vector vins; vector vouts; vector outputIndices; string metadata; - unique_ptr isFailed; + shared_ptr isFailed; vector incomingTransfers; - unique_ptr outgoingTransfer; - unique_ptr numSuggestedConfirmations; + shared_ptr outgoingTransfer; + shared_ptr numSuggestedConfirmations; string note; - unique_ptr isOutgoing; - unique_ptr isIncoming; + shared_ptr isOutgoing; + shared_ptr isIncoming; vector txIds; - unique_ptr hasPaymentId; + shared_ptr hasPaymentId; vector paymentIds; - unique_ptr minHeight; - unique_ptr maxHeight; - unique_ptr includeOutputs; - unique_ptr transferRequest; + shared_ptr minHeight; + shared_ptr maxHeight; + shared_ptr includeOutputs; + shared_ptr transferRequest; }; // --------------------------------- LISTENERS ------------------------------