From 313f60be2aff296d9db2ebeec0bfce88a8d200b2 Mon Sep 17 00:00:00 2001 From: woodser Date: Mon, 17 Jun 2019 17:09:02 -0400 Subject: [PATCH] meets criteria uses reference instead of pointer --- src/wallet/MoneroWallet.cpp | 4 +-- src/wallet/MoneroWalletModel.cpp | 62 ++++++++++++++++++++++++++++++-- src/wallet/MoneroWalletModel.h | 2 +- 3 files changed, 62 insertions(+), 6 deletions(-) diff --git a/src/wallet/MoneroWallet.cpp b/src/wallet/MoneroWallet.cpp index c7df347..881159b 100644 --- a/src/wallet/MoneroWallet.cpp +++ b/src/wallet/MoneroWallet.cpp @@ -599,9 +599,9 @@ namespace monero { // filter and return transfers vector> transfers; for (const shared_ptr& tx : txs) { - if (tx->outgoingTransfer != boost::none && request.meetsCriteria((*tx->outgoingTransfer).get())) transfers.push_back(*tx->outgoingTransfer); + if (tx->outgoingTransfer != boost::none && request.meetsCriteria(**tx->outgoingTransfer)) transfers.push_back(*tx->outgoingTransfer); for (const shared_ptr& incomingTransfer : tx->incomingTransfers) { - if (request.meetsCriteria(incomingTransfer.get())) transfers.push_back(incomingTransfer); // TODO: replace this with e.g. incomingTransfer.get() + if (request.meetsCriteria(*incomingTransfer)) transfers.push_back(incomingTransfer); // TODO: replace this with e.g. incomingTransfer.get() } } return transfers; diff --git a/src/wallet/MoneroWalletModel.cpp b/src/wallet/MoneroWalletModel.cpp index 52f5db0..99b3d1e 100644 --- a/src/wallet/MoneroWalletModel.cpp +++ b/src/wallet/MoneroWalletModel.cpp @@ -120,8 +120,64 @@ namespace monero { // --------------------------------- REQUESTS ------------------------------- - bool MoneroTransferRequest::meetsCriteria(const MoneroTransfer* transfer) const { - //return true; // TODO - return false; + bool MoneroTransferRequest::meetsCriteria(const MoneroTransfer& transfer) const { + + throw runtime_error("Not implemented"); + + +// if (transfer == null) return false; +// +// // filter on common fields +// if (this.getIsIncoming() != null && this.getIsIncoming() != transfer.getIsIncoming()) return false; +// if (this.getIsOutgoing() != null && this.getIsOutgoing() != transfer.getIsOutgoing()) return false; +// if (this.getAmount() != null && this.getAmount().compareTo(transfer.getAmount()) != 0) return false; +// if (this.getAccountIndex() != null && !this.getAccountIndex().equals(transfer.getAccountIndex())) return false; +// +// // filter on incoming fields +// if (transfer instanceof MoneroIncomingTransfer) { +// if (Boolean.TRUE.equals(this.getHasDestinations())) return false; +// MoneroIncomingTransfer inTransfer = (MoneroIncomingTransfer) transfer; +// if (this.getAddress() != null && !this.getAddress().equals(inTransfer.getAddress())) return false; +// if (this.getAddresses() != null && !this.getAddresses().contains(inTransfer.getAddress())) return false; +// if (this.getSubaddressIndex() != null && !this.getSubaddressIndex().equals(inTransfer.getSubaddressIndex())) return false; +// if (this.getSubaddressIndices() != null && !this.getSubaddressIndices().contains(inTransfer.getSubaddressIndex())) return false; +// } +// +// // filter on outgoing fields +// else if (transfer instanceof MoneroOutgoingTransfer) { +// MoneroOutgoingTransfer outTransfer = (MoneroOutgoingTransfer) transfer; +// +// // filter on addresses +// if (this.getAddress() != null && (outTransfer.getAddresses() == null || !outTransfer.getAddresses().contains(this.getAddress()))) return false; // TODO: will filter all transfers if they don't contain addresses +// if (this.getAddresses() != null) { +// List intersections = new ArrayList(this.getAddresses()); +// intersections.retainAll(outTransfer.getAddresses()); +// if (intersections.isEmpty()) return false; // must have overlapping addresses +// } +// +// // filter on subaddress indices +// if (this.getSubaddressIndex() != null && (outTransfer.getSubaddressIndices() == null || !outTransfer.getSubaddressIndices().contains(this.getSubaddressIndex()))) return false; +// if (this.getSubaddressIndices() != null) { +// List intersections = new ArrayList(this.getSubaddressIndices()); +// intersections.retainAll(outTransfer.getSubaddressIndices()); +// if (intersections.isEmpty()) return false; // must have overlapping subaddress indices +// } +// +// // filter on having destinations +// if (this.getHasDestinations() != null) { +// if (this.getHasDestinations() && outTransfer.getDestinations() == null) return false; +// if (!this.getHasDestinations() && outTransfer.getDestinations() != null) return false; +// } +// +// // filter on destinations TODO: start with test for this +//// if (this.getDestionations() != null && this.getDestionations() != transfer.getDestionations()) return false; +// } +// +// // otherwise invalid type +// else throw new RuntimeException("Transfer must be MoneroIncomingTransfer or MoneroOutgoingTransfer"); +// +// // filter with tx filter +// if (this.getTxRequest() != null && !this.getTxRequest().meetsCriteria(transfer.getTx())) return false; +// return true; } } diff --git a/src/wallet/MoneroWalletModel.h b/src/wallet/MoneroWalletModel.h index c4db8d3..f0fa350 100644 --- a/src/wallet/MoneroWalletModel.h +++ b/src/wallet/MoneroWalletModel.h @@ -159,7 +159,7 @@ namespace monero { vector> destinations; boost::optional hasDestinations; boost::optional> txRequest; - bool meetsCriteria(const MoneroTransfer* transfer) const; + bool meetsCriteria(const MoneroTransfer& transfer) const; }; /**