From 25e0d2befdaaf816a065f756940559a1d94352ca Mon Sep 17 00:00:00 2001 From: woodser Date: Mon, 3 Jun 2019 17:08:28 -0400 Subject: [PATCH] MoneroUtils.json_to_binary -> jsonToBinary(), etc; MoneroTxRequest and MoneroTransferRequest do not extend struct; use pointers in structs where appropriate, prep for custom deserialization --- src/daemon/MoneroDaemon.h | 46 ++------------------------ src/utils/MoneroUtils.cpp | 18 +++++----- src/utils/MoneroUtils.h | 15 ++------- src/wallet/MoneroWallet.cpp | 2 -- src/wallet/MoneroWallet.h | 66 ++++++++++++++++++++++++++++--------- 5 files changed, 66 insertions(+), 81 deletions(-) diff --git a/src/daemon/MoneroDaemon.h b/src/daemon/MoneroDaemon.h index 8ed4b99..46872c3 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 { - MoneroBlock* block; + unique_ptr block; string id; string version; bool isCoinbase; @@ -70,51 +70,11 @@ namespace monero { string rctSigPrunable; // TODO: implement bool isKeptByBlock; bool isFailed; - uint32_t lastFailedHeight; + unique_ptr lastFailedHeight; string lastFailedId; - uint32_t maxUsedBlockHeight; + unique_ptr maxUsedBlockHeight; string maxUsedBlockId; vector signatures; - - BEGIN_KV_SERIALIZE_MAP() - KV_SERIALIZE(id) - KV_SERIALIZE(version) - KV_SERIALIZE(isCoinbase) - KV_SERIALIZE(paymentId) - KV_SERIALIZE(fee) - KV_SERIALIZE(mixin) - KV_SERIALIZE(doNotRelay) - KV_SERIALIZE(isRelayed) - KV_SERIALIZE(isConfirmed) - KV_SERIALIZE(inTxPool) - KV_SERIALIZE(numConfirmations) - KV_SERIALIZE(unlockTime) - KV_SERIALIZE(lastRelayedTimestamp) - KV_SERIALIZE(receivedTimestamp) - KV_SERIALIZE(isDoubleSpend) - KV_SERIALIZE(key) - KV_SERIALIZE(fullHex) - KV_SERIALIZE(prunedHex) - KV_SERIALIZE(prunableHex) - KV_SERIALIZE(prunableHash) - KV_SERIALIZE(size) - KV_SERIALIZE(weight) - KV_SERIALIZE(vins) - KV_SERIALIZE(vouts) - KV_SERIALIZE(outputIndices) - KV_SERIALIZE(metadata) - KV_SERIALIZE(commonTxSets) - KV_SERIALIZE(extra) - KV_SERIALIZE(rctSignatures) - KV_SERIALIZE(rctSigPrunable) - KV_SERIALIZE(isKeptByBlock) - KV_SERIALIZE(isFailed) - KV_SERIALIZE(lastFailedHeight) - KV_SERIALIZE(lastFailedId) - KV_SERIALIZE(maxUsedBlockHeight) - KV_SERIALIZE(maxUsedBlockId) - KV_SERIALIZE(signatures) - END_KV_SERIALIZE_MAP() }; /** diff --git a/src/utils/MoneroUtils.cpp b/src/utils/MoneroUtils.cpp index 9fd1c79..f46292f 100644 --- a/src/utils/MoneroUtils.cpp +++ b/src/utils/MoneroUtils.cpp @@ -10,23 +10,23 @@ using namespace boost; using namespace cryptonote; using namespace MoneroUtils; -void MoneroUtils::json_to_binary(const std::string &buff_json, std::string &buff_bin) { +void MoneroUtils::jsonToBinary(const std::string &json, std::string &bin) { epee::serialization::portable_storage ps; - ps.load_from_json(buff_json); - ps.store_to_binary(buff_bin); + ps.load_from_json(json); + ps.store_to_binary(bin); } -void MoneroUtils::binary_to_json(const std::string &buff_bin, std::string &buff_json) { +void MoneroUtils::binaryToJson(const std::string &bin, std::string &json) { epee::serialization::portable_storage ps; - ps.load_from_binary(buff_bin); - ps.dump_as_json(buff_json); + ps.load_from_binary(bin); + ps.dump_as_json(json); } -void MoneroUtils::binary_blocks_to_json(const std::string &buff_bin, std::string &buff_json) { +void MoneroUtils::binaryBlocksToJson(const std::string &bin, std::string &json) { // load binary rpc response to struct cryptonote::COMMAND_RPC_GET_BLOCKS_BY_HEIGHT::response resp_struct; - epee::serialization::load_t_from_binary(resp_struct, buff_bin); + epee::serialization::load_t_from_binary(resp_struct, bin); // build property tree from deserialized blocks and transactions boost::property_tree::ptree root; @@ -71,5 +71,5 @@ void MoneroUtils::binary_blocks_to_json(const std::string &buff_bin, std::string // convert root to string // TODO: common utility with serial_bridge std::stringstream ss; boost::property_tree::write_json(ss, root, false/*pretty*/); - buff_json = ss.str(); + json = ss.str(); } diff --git a/src/utils/MoneroUtils.h b/src/utils/MoneroUtils.h index 3bcb837..9d51fdd 100644 --- a/src/utils/MoneroUtils.h +++ b/src/utils/MoneroUtils.h @@ -14,20 +14,11 @@ namespace MoneroUtils using namespace boost; using namespace cryptonote; - /** - * TODO. - */ - void json_to_binary(const std::string &buff_json, std::string &buff_bin); + void jsonToBinary(const std::string &json, std::string &bin); - /** - * TODO. - */ - void binary_to_json(const std::string &buff_bin, std::string &buff_json); + void binaryToJson(const std::string &bin, std::string &json); - /** - * TODO. - */ - void binary_blocks_to_json(const std::string &buff_bin, std::string &buff_json); + void binaryBlocksToJson(const std::string &bin, std::string &json); /** * Modified from core_rpc_server.cpp to return a string. diff --git a/src/wallet/MoneroWallet.cpp b/src/wallet/MoneroWallet.cpp index 8ad06c9..2232f52 100644 --- a/src/wallet/MoneroWallet.cpp +++ b/src/wallet/MoneroWallet.cpp @@ -439,8 +439,6 @@ namespace monero { vector MoneroWallet::getTxs(const MoneroTxRequest& request) const { cout << "getTxs(request)" << endl; - string reqStr = epee::serialization::store_t_to_json(request); - cout << "Tx request: " << reqStr << endl; throw runtime_error("Not implemented"); } diff --git a/src/wallet/MoneroWallet.h b/src/wallet/MoneroWallet.h index a9524b9..6dd755e 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 { - MoneroTxWallet* tx; + unique_ptr tx; uint64_t amount; uint32_t accountIndex; bool isIncoming; @@ -117,7 +117,7 @@ namespace monero { */ struct MoneroTxWallet : public MoneroTx { vector incomingTransfers; - MoneroOutgoingTransfer* outgoingTransfer; + unique_ptr outgoingTransfer; uint32_t numSuggestedConfirmations; string note; }; @@ -127,15 +127,17 @@ namespace monero { * * All transfers are returned except those that do not meet the criteria defined in this request. */ - struct MoneroTransferRequest : public MoneroTransfer { - bool isIncoming; + struct MoneroTransferRequest { + unique_ptr amount; + unique_ptr accountIndex; + unique_ptr isIncoming; string address; vector addresses; - uint32_t subaddressIndex; + unique_ptr subaddressIndex; vector subaddressIndices; vector destinations; - bool hasDestinations; - MoneroTxRequest* txRequest; + unique_ptr hasDestinations; + unique_ptr txRequest; }; /** @@ -143,16 +145,50 @@ namespace monero { * * All transactions are returned except those that do not meet the criteria defined in this request. */ - struct MoneroTxRequest : public MoneroTxWallet { - bool isOutgoing; // TODO: these are going to need to be pointers to indicate no preference - bool isIncoming; + struct MoneroTxRequest { + unique_ptr block; + string id; + string version; + unique_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; + string key; + string fullHex; + string prunedHex; + string prunableHex; + string prunableHash; + unique_ptr size; + unique_ptr weight; + vector vins; + vector vouts; + vector outputIndices; + string metadata; + unique_ptr isFailed; + + vector incomingTransfers; + unique_ptr outgoingTransfer; + unique_ptr numSuggestedConfirmations; + string note; + + unique_ptr isOutgoing; + unique_ptr isIncoming; vector txIds; - bool hasPaymentId; + unique_ptr hasPaymentId; vector paymentIds; - uint64_t minHeight; - uint64_t maxHeight; - bool includeOutputs; - MoneroTransferRequest* transferRequest; + unique_ptr minHeight; + unique_ptr maxHeight; + unique_ptr includeOutputs; + unique_ptr transferRequest; }; // --------------------------------- LISTENERS ------------------------------