diff --git a/src/daemon/MoneroDaemonModel.cpp b/src/daemon/MoneroDaemonModel.cpp index c66b020..635fb5a 100644 --- a/src/daemon/MoneroDaemonModel.cpp +++ b/src/daemon/MoneroDaemonModel.cpp @@ -175,7 +175,8 @@ namespace monero { // ------------------------------- MONERO TX -------------------------------- - shared_ptr MoneroTx::copy(const shared_ptr& self) const { + shared_ptr MoneroTx::copy(const shared_ptr& src, const shared_ptr& tgt) const { + MTRACE("MoneroTx::copy(const shared_ptr& src, const shared_ptr& tgt)"); throw runtime_error("MoneroTx::copy() not implemented"); } @@ -370,7 +371,7 @@ namespace monero { // ------------------------------ MONERO OUTPUT ----------------------------- - shared_ptr MoneroOutput::copy(const shared_ptr& self) const { + shared_ptr MoneroOutput::copy(const shared_ptr& src, const shared_ptr& tgt) const { throw runtime_error("MoneroOutput::copy() not implemented"); } diff --git a/src/daemon/MoneroDaemonModel.h b/src/daemon/MoneroDaemonModel.h index 3c4d498..d3b1f87 100644 --- a/src/daemon/MoneroDaemonModel.h +++ b/src/daemon/MoneroDaemonModel.h @@ -192,7 +192,7 @@ namespace monero { boost::optional maxUsedBlockId; vector signatures; - shared_ptr copy(const shared_ptr& self) const; + shared_ptr copy(const shared_ptr& src, const shared_ptr& tgt) const; boost::property_tree::ptree toPropertyTree() const; virtual void merge(const shared_ptr& self, const shared_ptr& other); boost::optional getHeight() const; @@ -220,7 +220,7 @@ namespace monero { vector ringOutputIndices; boost::optional stealthPublicKey; - shared_ptr copy(const shared_ptr& self) const; + shared_ptr copy(const shared_ptr& src, const shared_ptr& tgt) const; boost::property_tree::ptree toPropertyTree() const; virtual void merge(const shared_ptr& self, const shared_ptr& other); }; diff --git a/src/wallet/MoneroWallet.cpp b/src/wallet/MoneroWallet.cpp index 37abe12..b884318 100644 --- a/src/wallet/MoneroWallet.cpp +++ b/src/wallet/MoneroWallet.cpp @@ -1391,20 +1391,38 @@ namespace monero { } // copy and normalize request + MTRACE("initializing shared pointer"); shared_ptr req; - if (request.txRequest == boost::none) req = request.copy(make_shared(request)); + if (request.txRequest == boost::none) { + MTRACE("copying transfer request"); + req = request.copy(make_shared(request), shared_ptr()); + MTRACE("done copying request!!!"); + } else { - shared_ptr txReq = request.txRequest.get()->copy(request.txRequest.get()); - if (request.txRequest.get()->transferRequest.get().get() == &request) req = txReq->transferRequest.get(); + MTRACE("copying tx request"); + shared_ptr txReq = request.txRequest.get()->copy(request.txRequest.get(), shared_ptr()); + MTRACE("1"); + if (request.txRequest.get()->transferRequest.get().get() == &request) { + req = txReq->transferRequest.get(); + MTRACE("2"); + } else { + MTRACE("3"); if (request.txRequest.get()->transferRequest != boost::none) throw new runtime_error("Transfer request's tx request must be a circular reference or null"); - req = request.copy(make_shared(request)); + MTRACE("4"); + req = request.copy(make_shared(request), shared_ptr()); + MTRACE("5"); req->txRequest = txReq; + MTRACE("6"); } } + MTRACE("7"); if (req->txRequest == boost::none) req->txRequest = shared_ptr(); + MTRACE("8"); shared_ptr txReq = req->txRequest.get(); + MTRACE("9"); txReq->transferRequest = boost::none; // break circular link for meetsCriteria() + MTRACE("10"); // // copy and normalize request // MoneroTransferRequest req; diff --git a/src/wallet/MoneroWalletModel.cpp b/src/wallet/MoneroWalletModel.cpp index 6694dc6..05d7e43 100644 --- a/src/wallet/MoneroWalletModel.cpp +++ b/src/wallet/MoneroWalletModel.cpp @@ -105,11 +105,17 @@ namespace monero { // --------------------------- MONERO TX WALLET ----------------------------- - shared_ptr MoneroTxWallet::copy(const shared_ptr& self) const { - throw runtime_error("MoneroOutputWallet::copy(tx) not implemented"); + shared_ptr MoneroTxWallet::copy(const shared_ptr& src, const shared_ptr& tgt) const { + return MoneroTxWallet::copy(static_pointer_cast(src), static_pointer_cast(tgt)); }; - shared_ptr MoneroTxWallet::copy(const shared_ptr& self) const { + shared_ptr MoneroTxWallet::copy(const shared_ptr& src, const shared_ptr& tgt) const { + MTRACE("MoneroTxWallet::copy(const shared_ptr& src, const shared_ptr& tgt)"); + if (this != src.get()) throw runtime_error("this != src"); + + // copy base class + MoneroTx::copy(static_pointer_cast(src), static_pointer_cast(tgt)); + throw runtime_error("MoneroTxWallet::copy(txWallet) not implemented"); }; @@ -161,15 +167,22 @@ namespace monero { // -------------------------- MONERO TX REQUEST ----------------------------- - shared_ptr MoneroTxRequest::copy(const shared_ptr& self) const { - throw runtime_error("MoneroOutputWallet::copy(tx) not implemented"); + shared_ptr MoneroTxRequest::copy(const shared_ptr& src, const shared_ptr& tgt) const { + return copy(static_pointer_cast(src), static_pointer_cast(tgt)); }; - shared_ptr MoneroTxRequest::copy(const shared_ptr& self) const { - throw runtime_error("MoneroTxRequest::copy(txWallet) not implemented"); + shared_ptr MoneroTxRequest::copy(const shared_ptr& src, const shared_ptr& tgt) const { + return copy(static_pointer_cast(src), static_pointer_cast(tgt)); }; - shared_ptr MoneroTxRequest::copy(const shared_ptr& self) const { + shared_ptr MoneroTxRequest::copy(const shared_ptr& src, const shared_ptr& tgt) const { + MTRACE("MoneroTxRequest::copy(const shared_ptr& src, const shared_ptr& tgt)"); + if (this != src.get()) throw runtime_error("this != src"); + + // copy base class + MTRACE("copying base"); + MoneroTxWallet::copy(static_pointer_cast(src), static_pointer_cast(tgt)); + throw runtime_error("MoneroTxRequest::copy(txRequest) not implemented"); }; @@ -250,9 +263,9 @@ namespace monero { // ---------------------------- MONERO TRANSFER ----------------------------- -// shared_ptr MoneroTransfer::copy(const shared_ptr& self) const { -// throw runtime_error("MoneroTransfer::copy() not implemented"); -// }; + shared_ptr MoneroTransfer::copy(const shared_ptr& src, const shared_ptr& tgt) const { + throw runtime_error("MoneroTransfer::copy() not implemented"); + }; boost::property_tree::ptree MoneroTransfer::toPropertyTree() const { boost::property_tree::ptree node; @@ -288,11 +301,11 @@ namespace monero { // ----------------------- MONERO INCOMING TRANSFER ------------------------- - shared_ptr MoneroIncomingTransfer::copy(const shared_ptr& self) const { + shared_ptr MoneroIncomingTransfer::copy(const shared_ptr& src, const shared_ptr& tgt) const { throw runtime_error("MoneroIncomingTransfer::copy(transfer) not implemented"); }; - shared_ptr MoneroIncomingTransfer::copy(const shared_ptr& self) const { + shared_ptr MoneroIncomingTransfer::copy(const shared_ptr& src, const shared_ptr& tgt) const { throw runtime_error("MoneroIncomingTransfer::copy(inTransfer) not implemented"); }; @@ -318,11 +331,11 @@ namespace monero { // ----------------------- MONERO OUTGOING TRANSFER ------------------------- - shared_ptr MoneroOutgoingTransfer::copy(const shared_ptr& self) const { + shared_ptr MoneroOutgoingTransfer::copy(const shared_ptr& src, const shared_ptr& tgt) const { throw runtime_error("MoneroOutgoingTransfer::copy(transfer) not implemented"); }; - shared_ptr MoneroOutgoingTransfer::copy(const shared_ptr& self) const { + shared_ptr MoneroOutgoingTransfer::copy(const shared_ptr& src, const shared_ptr& tgt) const { throw runtime_error("MoneroOutgoingTransfer::copy(outTransfer) not implemented"); }; @@ -350,11 +363,13 @@ namespace monero { // ----------------------- MONERO TRANSFER REQUEST -------------------------- - shared_ptr MoneroTransferRequest::copy(const shared_ptr& self) const { + shared_ptr MoneroTransferRequest::copy(const shared_ptr& src, const shared_ptr& tgt) const { + MTRACE("MoneroTransferRequest::copy(const shared_ptr& src, const shared_ptr& tgt"); throw runtime_error("MoneroTransferRequest::copy(transfer) not implemented"); }; - shared_ptr MoneroTransferRequest::copy(const shared_ptr& self) const { + shared_ptr MoneroTransferRequest::copy(const shared_ptr& src, const shared_ptr& tgt) const { + MTRACE("MoneroTransferRequest::copy(const shared_ptr& src, const shared_ptr& tgt)"); throw runtime_error("MoneroTransferRequest::copy(request) not implemented"); }; @@ -446,11 +461,18 @@ namespace monero { // ------------------------- MONERO OUTPUT WALLET --------------------------- - shared_ptr MoneroOutputWallet::copy(const shared_ptr& self) const { - throw runtime_error("MoneroOutputWallet::copy(output) not implemented"); + shared_ptr MoneroOutputWallet::copy(const shared_ptr& src, const shared_ptr& tgt) const { + MTRACE("MoneroOutputWallet::copy(output)"); + return MoneroOutputWallet::copy(static_pointer_cast(src), static_pointer_cast(tgt)); }; - shared_ptr MoneroOutputWallet::copy(const shared_ptr& self) const { + shared_ptr MoneroOutputWallet::copy(const shared_ptr& src, const shared_ptr& tgt) const { + MTRACE("MoneroOutputWallet::copy(outputWallet)"); + if (this != src.get()) throw runtime_error("this != src"); + + // copy base class + MoneroOutputWallet::copy(static_pointer_cast(src), static_pointer_cast(tgt)); + throw runtime_error("MoneroOutputWallet::copy(outputWallet) not implemented"); }; @@ -474,15 +496,15 @@ namespace monero { // ------------------------ MONERO OUTPUT REQUEST --------------------------- - shared_ptr MoneroOutputRequest::copy(const shared_ptr& self) const { + shared_ptr MoneroOutputRequest::copy(const shared_ptr& src, const shared_ptr& tgt) const { throw runtime_error("MoneroOutputRequest::copy(output) not implemented"); }; - shared_ptr MoneroOutputRequest::copy(const shared_ptr& self) const { + shared_ptr MoneroOutputRequest::copy(const shared_ptr& src, const shared_ptr& tgt) const { throw runtime_error("MoneroOutputRequest::copy(outputWallet) not implemented"); }; - shared_ptr MoneroOutputRequest::copy(const shared_ptr& self) const { + shared_ptr MoneroOutputRequest::copy(const shared_ptr& src, const shared_ptr& tgt) const { throw runtime_error("MoneroOutputRequest::copy(outputRequest) not implemented"); }; diff --git a/src/wallet/MoneroWalletModel.h b/src/wallet/MoneroWalletModel.h index a8fea09..879f196 100644 --- a/src/wallet/MoneroWalletModel.h +++ b/src/wallet/MoneroWalletModel.h @@ -148,9 +148,7 @@ namespace monero { boost::optional numSuggestedConfirmations; virtual boost::optional getIsIncoming() const = 0; // derived class must implement - shared_ptr copy(const shared_ptr& self) const { // not virtual in order for subclasses to return shared_ptr of derived types - throw runtime_error("Subclasses must implement"); - }; + shared_ptr copy(const shared_ptr& src, const shared_ptr& tgt) const; boost::optional getIsOutgoing() const { if (getIsIncoming() == boost::none) return boost::none; return !(*getIsIncoming()); @@ -166,8 +164,8 @@ namespace monero { boost::optional subaddressIndex; boost::optional address; - shared_ptr copy(const shared_ptr& self) const; - shared_ptr copy(const shared_ptr& self) const; + shared_ptr copy(const shared_ptr& src, const shared_ptr& tgt) const; + shared_ptr copy(const shared_ptr& src, const shared_ptr& tgt) const; boost::optional getIsIncoming() const; boost::property_tree::ptree toPropertyTree() const; void merge(const shared_ptr& self, const shared_ptr& other); @@ -182,8 +180,8 @@ namespace monero { vector addresses; vector> destinations; - shared_ptr copy(const shared_ptr& self) const; - shared_ptr copy(const shared_ptr& self) const; + shared_ptr copy(const shared_ptr& src, const shared_ptr& tgt) const; + shared_ptr copy(const shared_ptr& src, const shared_ptr& tgt) const; boost::optional getIsIncoming() const; boost::property_tree::ptree toPropertyTree() const; void merge(const shared_ptr& self, const shared_ptr& other); @@ -205,8 +203,8 @@ namespace monero { boost::optional hasDestinations; boost::optional> txRequest; - shared_ptr copy(const shared_ptr& self) const; - shared_ptr copy(const shared_ptr& self) const; + shared_ptr copy(const shared_ptr& src, const shared_ptr& tgt) const; + shared_ptr copy(const shared_ptr& src, const shared_ptr& tgt) const; boost::optional getIsIncoming() const; boost::property_tree::ptree toPropertyTree() const; bool meetsCriteria(MoneroTransfer* transfer) const; @@ -222,8 +220,8 @@ namespace monero { boost::optional isUnlocked; boost::optional isFrozen; - shared_ptr copy(const shared_ptr& self) const; - shared_ptr copy(const shared_ptr& self) const; + shared_ptr copy(const shared_ptr& src, const shared_ptr& tgt) const; + shared_ptr copy(const shared_ptr& src, const shared_ptr& tgt) const; boost::property_tree::ptree toPropertyTree() const; void merge(const shared_ptr& self, const shared_ptr& other); void merge(const shared_ptr& self, const shared_ptr& other); @@ -240,9 +238,9 @@ namespace monero { boost::optional> txRequest; // TODO: necessary to override all super classes? - shared_ptr copy(const shared_ptr& self) const; - shared_ptr copy(const shared_ptr& self) const; - shared_ptr copy(const shared_ptr& self) const; + shared_ptr copy(const shared_ptr& src, const shared_ptr& tgt) const; + shared_ptr copy(const shared_ptr& src, const shared_ptr& tgt) const; + shared_ptr copy(const shared_ptr& src, const shared_ptr& tgt) const; boost::property_tree::ptree toPropertyTree() const; bool meetsCriteria(MoneroOutputWallet* output) const; }; @@ -255,8 +253,8 @@ namespace monero { boost::optional> outgoingTransfer; boost::optional note; - shared_ptr copy(const shared_ptr& self) const; - shared_ptr copy(const shared_ptr& self) const; + shared_ptr copy(const shared_ptr& src, const shared_ptr& tgt) const; + shared_ptr copy(const shared_ptr& src, const shared_ptr& tgt) const; bool getIsIncoming() const; bool getIsOutgoing() const; boost::property_tree::ptree toPropertyTree() const; @@ -283,9 +281,9 @@ namespace monero { boost::optional> outputRequest; // TODO: necessary to override all super classes? - shared_ptr copy(const shared_ptr& self) const; - shared_ptr copy(const shared_ptr& self) const; - shared_ptr copy(const shared_ptr& self) const; + shared_ptr copy(const shared_ptr& src, const shared_ptr& tgt) const; + shared_ptr copy(const shared_ptr& src, const shared_ptr& tgt) const; + shared_ptr copy(const shared_ptr& src, const shared_ptr& tgt) const; boost::property_tree::ptree toPropertyTree() const; bool meetsCriteria(MoneroTxWallet* tx) const; };