From 490f916d5f50106c3a46134d6b96730e4dd84938 Mon Sep 17 00:00:00 2001 From: woodser Date: Thu, 20 Jun 2019 22:33:01 -0400 Subject: [PATCH] assert MoneroTransferFilter and MoneroTxFilter do not reference each other --- src/wallet/MoneroWallet.cpp | 6 +++--- src/wallet/MoneroWalletModel.cpp | 6 ++++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/wallet/MoneroWallet.cpp b/src/wallet/MoneroWallet.cpp index ed44bfc..8765105 100644 --- a/src/wallet/MoneroWallet.cpp +++ b/src/wallet/MoneroWallet.cpp @@ -551,9 +551,9 @@ namespace monero { // print request cout << "Fetching transfers with request: "; - if (request.txRequest == boost::none) cout << request.serialize() << endl; - else if ((*request.txRequest)->block == boost::none) cout << (*request.txRequest)->serialize() << endl; - else cout << (*(*request.txRequest)->block)->serialize() << endl; + if (request.txRequest == boost::none) cout << "[transferRequest] " << request.serialize() << endl; + else if ((*request.txRequest)->block == boost::none) cout << "[txRequest] " << (*request.txRequest)->serialize() << endl; + else cout << "[block] " << (*(*request.txRequest)->block)->serialize() << endl; // normalize request // TODO: this will modify original request, construct copy? add test diff --git a/src/wallet/MoneroWalletModel.cpp b/src/wallet/MoneroWalletModel.cpp index 1a9f7ed..271f385 100644 --- a/src/wallet/MoneroWalletModel.cpp +++ b/src/wallet/MoneroWalletModel.cpp @@ -148,10 +148,10 @@ namespace monero { } // filter on remaining fields - boost::optional txHeight = tx->block == boost::none ? boost::none : (*tx->block)->height; + boost::optional txHeight = tx->getHeight(); if (!txIds.empty() && find(txIds.begin(), txIds.end(), *tx->id) == txIds.end()) return false; if (!paymentIds.empty() && find(paymentIds.begin(), paymentIds.end(), *tx->paymentId) == paymentIds.end()) return false; - if (getHeight() != boost::none && *txHeight != *getHeight()) return false; + if (getHeight() != boost::none && (txHeight == boost::none || *txHeight != *getHeight())) return false; if (minHeight != boost::none && (txHeight == boost::none || *txHeight < *minHeight)) return false; if (maxHeight != boost::none && (txHeight == boost::none || *txHeight > *maxHeight)) return false; @@ -238,6 +238,8 @@ namespace monero { } bool MoneroTransferRequest::meetsCriteria(MoneroTransfer* transfer) const { + if (transfer == nullptr) throw runtime_error("transfer is null"); // TODO: port to java/js + if (txRequest != boost::none && this == (*(*txRequest)->transferRequest).get()) throw runtime_error("MoneroTransferFilter and MoneroTxFilter must not reference each other"); // TODO: port to java/js // filter on common fields if (getIsIncoming() != boost::none && *getIsIncoming() != *transfer->getIsIncoming()) return false;