From f3be910e776fe3c87a3c4e37b6bf09398997d23e Mon Sep 17 00:00:00 2001 From: woodser Date: Tue, 18 Jun 2019 09:47:46 -0400 Subject: [PATCH] filter on subaddress indices and having destinations --- src/wallet/MoneroWalletModel.cpp | 39 +++++++++++++++++++------------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/src/wallet/MoneroWalletModel.cpp b/src/wallet/MoneroWalletModel.cpp index 8f69c3b..c306f7c 100644 --- a/src/wallet/MoneroWalletModel.cpp +++ b/src/wallet/MoneroWalletModel.cpp @@ -159,22 +159,29 @@ namespace monero { if (!intersects) 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; + // filter on subaddress indices + if (subaddressIndex != boost::none && (outTransfer->subaddressIndices.empty() || find(outTransfer->subaddressIndices.begin(), outTransfer->subaddressIndices.end(), subaddressIndex) == outTransfer->subaddressIndices.end())) return false; // TODO: will filter all transfers if they don't contain subaddress indices + if (!subaddressIndices.empty()) { + bool intersects = false; + for (const uint32_t& subaddressIndexReq : subaddressIndices) { + for (const uint32_t& subaddressIndex : outTransfer->subaddressIndices) { + if (subaddressIndexReq == subaddressIndex) { + intersects = true; + break; + } + } + } + if (!intersects) return false; // must have overlapping subaddress indices + } + + // filter on having destinations + if (hasDestinations != boost::none) { + if (*hasDestinations && outTransfer->destinations.empty()) return false; + if (!*hasDestinations && !outTransfer->destinations.empty()) return false; + } + + // filter on destinations TODO: start with test for this + // if (this.getDestionations() != null && this.getDestionations() != transfer.getDestionations()) return false; }