copy() takes src and tgt shared_ptrs like merge()

This commit is contained in:
woodser
2019-07-29 21:04:24 -04:00
parent b36873e40f
commit a887772177
5 changed files with 89 additions and 50 deletions
+3 -2
View File
@@ -175,7 +175,8 @@ namespace monero {
// ------------------------------- MONERO TX --------------------------------
shared_ptr<MoneroTx> MoneroTx::copy(const shared_ptr<MoneroTx>& self) const {
shared_ptr<MoneroTx> MoneroTx::copy(const shared_ptr<MoneroTx>& src, const shared_ptr<MoneroTx>& tgt) const {
MTRACE("MoneroTx::copy(const shared_ptr<MoneroTx>& src, const shared_ptr<MoneroTx>& tgt)");
throw runtime_error("MoneroTx::copy() not implemented");
}
@@ -370,7 +371,7 @@ namespace monero {
// ------------------------------ MONERO OUTPUT -----------------------------
shared_ptr<MoneroOutput> MoneroOutput::copy(const shared_ptr<MoneroOutput>& self) const {
shared_ptr<MoneroOutput> MoneroOutput::copy(const shared_ptr<MoneroOutput>& src, const shared_ptr<MoneroOutput>& tgt) const {
throw runtime_error("MoneroOutput::copy() not implemented");
}
+2 -2
View File
@@ -192,7 +192,7 @@ namespace monero {
boost::optional<string> maxUsedBlockId;
vector<string> signatures;
shared_ptr<MoneroTx> copy(const shared_ptr<MoneroTx>& self) const;
shared_ptr<MoneroTx> copy(const shared_ptr<MoneroTx>& src, const shared_ptr<MoneroTx>& tgt) const;
boost::property_tree::ptree toPropertyTree() const;
virtual void merge(const shared_ptr<MoneroTx>& self, const shared_ptr<MoneroTx>& other);
boost::optional<uint64_t> getHeight() const;
@@ -220,7 +220,7 @@ namespace monero {
vector<uint32_t> ringOutputIndices;
boost::optional<string> stealthPublicKey;
shared_ptr<MoneroOutput> copy(const shared_ptr<MoneroOutput>& self) const;
shared_ptr<MoneroOutput> copy(const shared_ptr<MoneroOutput>& src, const shared_ptr<MoneroOutput>& tgt) const;
boost::property_tree::ptree toPropertyTree() const;
virtual void merge(const shared_ptr<MoneroOutput>& self, const shared_ptr<MoneroOutput>& other);
};
+22 -4
View File
@@ -1391,20 +1391,38 @@ namespace monero {
}
// copy and normalize request
MTRACE("initializing shared pointer");
shared_ptr<MoneroTransferRequest> req;
if (request.txRequest == boost::none) req = request.copy(make_shared<MoneroTransferRequest>(request));
if (request.txRequest == boost::none) {
MTRACE("copying transfer request");
req = request.copy(make_shared<MoneroTransferRequest>(request), shared_ptr<MoneroTransferRequest>());
MTRACE("done copying request!!!");
}
else {
shared_ptr<MoneroTxRequest> 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<MoneroTxRequest> txReq = request.txRequest.get()->copy(request.txRequest.get(), shared_ptr<MoneroTxRequest>());
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<MoneroTransferRequest>(request));
MTRACE("4");
req = request.copy(make_shared<MoneroTransferRequest>(request), shared_ptr<MoneroTransferRequest>());
MTRACE("5");
req->txRequest = txReq;
MTRACE("6");
}
}
MTRACE("7");
if (req->txRequest == boost::none) req->txRequest = shared_ptr<MoneroTxRequest>();
MTRACE("8");
shared_ptr<MoneroTxRequest> txReq = req->txRequest.get();
MTRACE("9");
txReq->transferRequest = boost::none; // break circular link for meetsCriteria()
MTRACE("10");
// // copy and normalize request
// MoneroTransferRequest req;
+45 -23
View File
@@ -105,11 +105,17 @@ namespace monero {
// --------------------------- MONERO TX WALLET -----------------------------
shared_ptr<MoneroTxWallet> MoneroTxWallet::copy(const shared_ptr<MoneroTx>& self) const {
throw runtime_error("MoneroOutputWallet::copy(tx) not implemented");
shared_ptr<MoneroTxWallet> MoneroTxWallet::copy(const shared_ptr<MoneroTx>& src, const shared_ptr<MoneroTx>& tgt) const {
return MoneroTxWallet::copy(static_pointer_cast<MoneroTxWallet>(src), static_pointer_cast<MoneroTxWallet>(tgt));
};
shared_ptr<MoneroTxWallet> MoneroTxWallet::copy(const shared_ptr<MoneroTxWallet>& self) const {
shared_ptr<MoneroTxWallet> MoneroTxWallet::copy(const shared_ptr<MoneroTxWallet>& src, const shared_ptr<MoneroTxWallet>& tgt) const {
MTRACE("MoneroTxWallet::copy(const shared_ptr<MoneroTxWallet>& src, const shared_ptr<MoneroTxWallet>& tgt)");
if (this != src.get()) throw runtime_error("this != src");
// copy base class
MoneroTx::copy(static_pointer_cast<MoneroTx>(src), static_pointer_cast<MoneroTx>(tgt));
throw runtime_error("MoneroTxWallet::copy(txWallet) not implemented");
};
@@ -161,15 +167,22 @@ namespace monero {
// -------------------------- MONERO TX REQUEST -----------------------------
shared_ptr<MoneroTxRequest> MoneroTxRequest::copy(const shared_ptr<MoneroTx>& self) const {
throw runtime_error("MoneroOutputWallet::copy(tx) not implemented");
shared_ptr<MoneroTxRequest> MoneroTxRequest::copy(const shared_ptr<MoneroTx>& src, const shared_ptr<MoneroTx>& tgt) const {
return copy(static_pointer_cast<MoneroTxRequest>(src), static_pointer_cast<MoneroTxRequest>(tgt));
};
shared_ptr<MoneroTxRequest> MoneroTxRequest::copy(const shared_ptr<MoneroTxWallet>& self) const {
throw runtime_error("MoneroTxRequest::copy(txWallet) not implemented");
shared_ptr<MoneroTxRequest> MoneroTxRequest::copy(const shared_ptr<MoneroTxWallet>& src, const shared_ptr<MoneroTxWallet>& tgt) const {
return copy(static_pointer_cast<MoneroTxRequest>(src), static_pointer_cast<MoneroTxRequest>(tgt));
};
shared_ptr<MoneroTxRequest> MoneroTxRequest::copy(const shared_ptr<MoneroTxRequest>& self) const {
shared_ptr<MoneroTxRequest> MoneroTxRequest::copy(const shared_ptr<MoneroTxRequest>& src, const shared_ptr<MoneroTxRequest>& tgt) const {
MTRACE("MoneroTxRequest::copy(const shared_ptr<MoneroTxRequest>& src, const shared_ptr<MoneroTxRequest>& tgt)");
if (this != src.get()) throw runtime_error("this != src");
// copy base class
MTRACE("copying base");
MoneroTxWallet::copy(static_pointer_cast<MoneroTx>(src), static_pointer_cast<MoneroTx>(tgt));
throw runtime_error("MoneroTxRequest::copy(txRequest) not implemented");
};
@@ -250,9 +263,9 @@ namespace monero {
// ---------------------------- MONERO TRANSFER -----------------------------
// shared_ptr<MoneroTransfer> MoneroTransfer::copy(const shared_ptr<MoneroTransfer>& self) const {
// throw runtime_error("MoneroTransfer::copy() not implemented");
// };
shared_ptr<MoneroTransfer> MoneroTransfer::copy(const shared_ptr<MoneroTransfer>& src, const shared_ptr<MoneroTransfer>& 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> MoneroIncomingTransfer::copy(const shared_ptr<MoneroTransfer>& self) const {
shared_ptr<MoneroIncomingTransfer> MoneroIncomingTransfer::copy(const shared_ptr<MoneroTransfer>& src, const shared_ptr<MoneroTransfer>& tgt) const {
throw runtime_error("MoneroIncomingTransfer::copy(transfer) not implemented");
};
shared_ptr<MoneroIncomingTransfer> MoneroIncomingTransfer::copy(const shared_ptr<MoneroIncomingTransfer>& self) const {
shared_ptr<MoneroIncomingTransfer> MoneroIncomingTransfer::copy(const shared_ptr<MoneroIncomingTransfer>& src, const shared_ptr<MoneroIncomingTransfer>& tgt) const {
throw runtime_error("MoneroIncomingTransfer::copy(inTransfer) not implemented");
};
@@ -318,11 +331,11 @@ namespace monero {
// ----------------------- MONERO OUTGOING TRANSFER -------------------------
shared_ptr<MoneroOutgoingTransfer> MoneroOutgoingTransfer::copy(const shared_ptr<MoneroTransfer>& self) const {
shared_ptr<MoneroOutgoingTransfer> MoneroOutgoingTransfer::copy(const shared_ptr<MoneroTransfer>& src, const shared_ptr<MoneroTransfer>& tgt) const {
throw runtime_error("MoneroOutgoingTransfer::copy(transfer) not implemented");
};
shared_ptr<MoneroOutgoingTransfer> MoneroOutgoingTransfer::copy(const shared_ptr<MoneroOutgoingTransfer>& self) const {
shared_ptr<MoneroOutgoingTransfer> MoneroOutgoingTransfer::copy(const shared_ptr<MoneroOutgoingTransfer>& src, const shared_ptr<MoneroOutgoingTransfer>& tgt) const {
throw runtime_error("MoneroOutgoingTransfer::copy(outTransfer) not implemented");
};
@@ -350,11 +363,13 @@ namespace monero {
// ----------------------- MONERO TRANSFER REQUEST --------------------------
shared_ptr<MoneroTransferRequest> MoneroTransferRequest::copy(const shared_ptr<MoneroTransfer>& self) const {
shared_ptr<MoneroTransferRequest> MoneroTransferRequest::copy(const shared_ptr<MoneroTransfer>& src, const shared_ptr<MoneroTransfer>& tgt) const {
MTRACE("MoneroTransferRequest::copy(const shared_ptr<MoneroTransfer>& src, const shared_ptr<MoneroTransfer>& tgt");
throw runtime_error("MoneroTransferRequest::copy(transfer) not implemented");
};
shared_ptr<MoneroTransferRequest> MoneroTransferRequest::copy(const shared_ptr<MoneroTransferRequest>& self) const {
shared_ptr<MoneroTransferRequest> MoneroTransferRequest::copy(const shared_ptr<MoneroTransferRequest>& src, const shared_ptr<MoneroTransferRequest>& tgt) const {
MTRACE("MoneroTransferRequest::copy(const shared_ptr<MoneroTransferRequest>& src, const shared_ptr<MoneroTransferRequest>& tgt)");
throw runtime_error("MoneroTransferRequest::copy(request) not implemented");
};
@@ -446,11 +461,18 @@ namespace monero {
// ------------------------- MONERO OUTPUT WALLET ---------------------------
shared_ptr<MoneroOutputWallet> MoneroOutputWallet::copy(const shared_ptr<MoneroOutput>& self) const {
throw runtime_error("MoneroOutputWallet::copy(output) not implemented");
shared_ptr<MoneroOutputWallet> MoneroOutputWallet::copy(const shared_ptr<MoneroOutput>& src, const shared_ptr<MoneroOutput>& tgt) const {
MTRACE("MoneroOutputWallet::copy(output)");
return MoneroOutputWallet::copy(static_pointer_cast<MoneroOutputWallet>(src), static_pointer_cast<MoneroOutputWallet>(tgt));
};
shared_ptr<MoneroOutputWallet> MoneroOutputWallet::copy(const shared_ptr<MoneroOutputWallet>& self) const {
shared_ptr<MoneroOutputWallet> MoneroOutputWallet::copy(const shared_ptr<MoneroOutputWallet>& src, const shared_ptr<MoneroOutputWallet>& tgt) const {
MTRACE("MoneroOutputWallet::copy(outputWallet)");
if (this != src.get()) throw runtime_error("this != src");
// copy base class
MoneroOutputWallet::copy(static_pointer_cast<MoneroOutput>(src), static_pointer_cast<MoneroOutput>(tgt));
throw runtime_error("MoneroOutputWallet::copy(outputWallet) not implemented");
};
@@ -474,15 +496,15 @@ namespace monero {
// ------------------------ MONERO OUTPUT REQUEST ---------------------------
shared_ptr<MoneroOutputRequest> MoneroOutputRequest::copy(const shared_ptr<MoneroOutput>& self) const {
shared_ptr<MoneroOutputRequest> MoneroOutputRequest::copy(const shared_ptr<MoneroOutput>& src, const shared_ptr<MoneroOutput>& tgt) const {
throw runtime_error("MoneroOutputRequest::copy(output) not implemented");
};
shared_ptr<MoneroOutputRequest> MoneroOutputRequest::copy(const shared_ptr<MoneroOutputWallet>& self) const {
shared_ptr<MoneroOutputRequest> MoneroOutputRequest::copy(const shared_ptr<MoneroOutputWallet>& src, const shared_ptr<MoneroOutputWallet>& tgt) const {
throw runtime_error("MoneroOutputRequest::copy(outputWallet) not implemented");
};
shared_ptr<MoneroOutputRequest> MoneroOutputRequest::copy(const shared_ptr<MoneroOutputRequest>& self) const {
shared_ptr<MoneroOutputRequest> MoneroOutputRequest::copy(const shared_ptr<MoneroOutputRequest>& src, const shared_ptr<MoneroOutputRequest>& tgt) const {
throw runtime_error("MoneroOutputRequest::copy(outputRequest) not implemented");
};
+17 -19
View File
@@ -148,9 +148,7 @@ namespace monero {
boost::optional<uint32_t> numSuggestedConfirmations;
virtual boost::optional<bool> getIsIncoming() const = 0; // derived class must implement
shared_ptr<MoneroTransfer> copy(const shared_ptr<MoneroTransfer>& self) const { // not virtual in order for subclasses to return shared_ptr of derived types
throw runtime_error("Subclasses must implement");
};
shared_ptr<MoneroTransfer> copy(const shared_ptr<MoneroTransfer>& src, const shared_ptr<MoneroTransfer>& tgt) const;
boost::optional<bool> getIsOutgoing() const {
if (getIsIncoming() == boost::none) return boost::none;
return !(*getIsIncoming());
@@ -166,8 +164,8 @@ namespace monero {
boost::optional<uint32_t> subaddressIndex;
boost::optional<string> address;
shared_ptr<MoneroIncomingTransfer> copy(const shared_ptr<MoneroTransfer>& self) const;
shared_ptr<MoneroIncomingTransfer> copy(const shared_ptr<MoneroIncomingTransfer>& self) const;
shared_ptr<MoneroIncomingTransfer> copy(const shared_ptr<MoneroTransfer>& src, const shared_ptr<MoneroTransfer>& tgt) const;
shared_ptr<MoneroIncomingTransfer> copy(const shared_ptr<MoneroIncomingTransfer>& src, const shared_ptr<MoneroIncomingTransfer>& tgt) const;
boost::optional<bool> getIsIncoming() const;
boost::property_tree::ptree toPropertyTree() const;
void merge(const shared_ptr<MoneroTransfer>& self, const shared_ptr<MoneroTransfer>& other);
@@ -182,8 +180,8 @@ namespace monero {
vector<string> addresses;
vector<shared_ptr<MoneroDestination>> destinations;
shared_ptr<MoneroOutgoingTransfer> copy(const shared_ptr<MoneroTransfer>& self) const;
shared_ptr<MoneroOutgoingTransfer> copy(const shared_ptr<MoneroOutgoingTransfer>& self) const;
shared_ptr<MoneroOutgoingTransfer> copy(const shared_ptr<MoneroTransfer>& src, const shared_ptr<MoneroTransfer>& tgt) const;
shared_ptr<MoneroOutgoingTransfer> copy(const shared_ptr<MoneroOutgoingTransfer>& src, const shared_ptr<MoneroOutgoingTransfer>& tgt) const;
boost::optional<bool> getIsIncoming() const;
boost::property_tree::ptree toPropertyTree() const;
void merge(const shared_ptr<MoneroTransfer>& self, const shared_ptr<MoneroTransfer>& other);
@@ -205,8 +203,8 @@ namespace monero {
boost::optional<bool> hasDestinations;
boost::optional<shared_ptr<MoneroTxRequest>> txRequest;
shared_ptr<MoneroTransferRequest> copy(const shared_ptr<MoneroTransfer>& self) const;
shared_ptr<MoneroTransferRequest> copy(const shared_ptr<MoneroTransferRequest>& self) const;
shared_ptr<MoneroTransferRequest> copy(const shared_ptr<MoneroTransfer>& src, const shared_ptr<MoneroTransfer>& tgt) const;
shared_ptr<MoneroTransferRequest> copy(const shared_ptr<MoneroTransferRequest>& src, const shared_ptr<MoneroTransferRequest>& tgt) const;
boost::optional<bool> getIsIncoming() const;
boost::property_tree::ptree toPropertyTree() const;
bool meetsCriteria(MoneroTransfer* transfer) const;
@@ -222,8 +220,8 @@ namespace monero {
boost::optional<bool> isUnlocked;
boost::optional<bool> isFrozen;
shared_ptr<MoneroOutputWallet> copy(const shared_ptr<MoneroOutput>& self) const;
shared_ptr<MoneroOutputWallet> copy(const shared_ptr<MoneroOutputWallet>& self) const;
shared_ptr<MoneroOutputWallet> copy(const shared_ptr<MoneroOutput>& src, const shared_ptr<MoneroOutput>& tgt) const;
shared_ptr<MoneroOutputWallet> copy(const shared_ptr<MoneroOutputWallet>& src, const shared_ptr<MoneroOutputWallet>& tgt) const;
boost::property_tree::ptree toPropertyTree() const;
void merge(const shared_ptr<MoneroOutput>& self, const shared_ptr<MoneroOutput>& other);
void merge(const shared_ptr<MoneroOutputWallet>& self, const shared_ptr<MoneroOutputWallet>& other);
@@ -240,9 +238,9 @@ namespace monero {
boost::optional<shared_ptr<MoneroTxRequest>> txRequest;
// TODO: necessary to override all super classes?
shared_ptr<MoneroOutputRequest> copy(const shared_ptr<MoneroOutput>& self) const;
shared_ptr<MoneroOutputRequest> copy(const shared_ptr<MoneroOutputWallet>& self) const;
shared_ptr<MoneroOutputRequest> copy(const shared_ptr<MoneroOutputRequest>& self) const;
shared_ptr<MoneroOutputRequest> copy(const shared_ptr<MoneroOutput>& src, const shared_ptr<MoneroOutput>& tgt) const;
shared_ptr<MoneroOutputRequest> copy(const shared_ptr<MoneroOutputWallet>& src, const shared_ptr<MoneroOutputWallet>& tgt) const;
shared_ptr<MoneroOutputRequest> copy(const shared_ptr<MoneroOutputRequest>& src, const shared_ptr<MoneroOutputRequest>& tgt) const;
boost::property_tree::ptree toPropertyTree() const;
bool meetsCriteria(MoneroOutputWallet* output) const;
};
@@ -255,8 +253,8 @@ namespace monero {
boost::optional<shared_ptr<MoneroOutgoingTransfer>> outgoingTransfer;
boost::optional<string> note;
shared_ptr<MoneroTxWallet> copy(const shared_ptr<MoneroTx>& self) const;
shared_ptr<MoneroTxWallet> copy(const shared_ptr<MoneroTxWallet>& self) const;
shared_ptr<MoneroTxWallet> copy(const shared_ptr<MoneroTx>& src, const shared_ptr<MoneroTx>& tgt) const;
shared_ptr<MoneroTxWallet> copy(const shared_ptr<MoneroTxWallet>& src, const shared_ptr<MoneroTxWallet>& tgt) const;
bool getIsIncoming() const;
bool getIsOutgoing() const;
boost::property_tree::ptree toPropertyTree() const;
@@ -283,9 +281,9 @@ namespace monero {
boost::optional<shared_ptr<MoneroOutputRequest>> outputRequest;
// TODO: necessary to override all super classes?
shared_ptr<MoneroTxRequest> copy(const shared_ptr<MoneroTx>& self) const;
shared_ptr<MoneroTxRequest> copy(const shared_ptr<MoneroTxWallet>& self) const;
shared_ptr<MoneroTxRequest> copy(const shared_ptr<MoneroTxRequest>& self) const;
shared_ptr<MoneroTxRequest> copy(const shared_ptr<MoneroTx>& src, const shared_ptr<MoneroTx>& tgt) const;
shared_ptr<MoneroTxRequest> copy(const shared_ptr<MoneroTxWallet>& src, const shared_ptr<MoneroTxWallet>& tgt) const;
shared_ptr<MoneroTxRequest> copy(const shared_ptr<MoneroTxRequest>& src, const shared_ptr<MoneroTxRequest>& tgt) const;
boost::property_tree::ptree toPropertyTree() const;
bool meetsCriteria(MoneroTxWallet* tx) const;
};