From 8584dbeca9adea70878d573adb5c45125ba78ca2 Mon Sep 17 00:00:00 2001 From: woodser Date: Mon, 24 Jun 2019 17:59:04 -0400 Subject: [PATCH] finish getTxs() impl first pass --- src/wallet/MoneroWallet.cpp | 49 +++++++++++++++++++++++++++++++------ 1 file changed, 41 insertions(+), 8 deletions(-) diff --git a/src/wallet/MoneroWallet.cpp b/src/wallet/MoneroWallet.cpp index a745612..a22864f 100644 --- a/src/wallet/MoneroWallet.cpp +++ b/src/wallet/MoneroWallet.cpp @@ -558,6 +558,13 @@ namespace monero { } } + // cache types into maps for merging and lookup + map> txMap; + map> blockMap; + for (const shared_ptr& tx : txs) { + mergeTx(tx, txMap, blockMap, false); + } + // fetch and merge outputs if requested MoneroOutputRequest tempOutputReq; tempOutputReq.txRequest = shared_ptr(&request); @@ -566,13 +573,6 @@ namespace monero { // fetch outputs vector> outputs = getOutputs(tempOutputReq); - // build types for merging - map> txMap; - map> blockMap; - for (const shared_ptr& tx : txs) { - mergeTx(tx, txMap, blockMap, false); - } - // merge output txs one time while retaining order unordered_set> outputTxs; for (const shared_ptr& output : outputs) { @@ -585,9 +585,42 @@ namespace monero { } // filter txs that don't meet transfer request + request.transferRequest = transferRequest; + vector> txsRequested; + for (const shared_ptr& tx : txs) { + if (request.meetsCriteria(tx.get())) txsRequested.push_back(tx); + } + txs = txsRequested; + // verify all specified tx ids found + if (!request.txIds.empty()) { + for (const string& txId : request.txIds) { + bool found = false; + for (const shared_ptr& tx : txs) { + if (txId == *tx->id) { + found = true; + break; + } + } + if (!found) throw runtime_error("Tx not found in wallet: " + txId); + } + } - throw runtime_error("getTxs() not implemented"); + // special case: re-fetch txs if inconsistency caused by needing to make multiple wallet calls + for (const shared_ptr& tx : txs) { + if (*tx->isConfirmed && tx->block == boost::none) return getTxs(request); + } + + // otherwise order txs if tx ids given then return + if (!request.txIds.empty()) { + vector> orderedTxs; + for (const string& txId : request.txIds) { + map>::const_iterator txIter = txMap.find(txId); + orderedTxs.push_back(txIter->second); + } + txs = orderedTxs; + } + return txs; } vector> MoneroWallet::getTransfers(const MoneroTransferRequest& request) const {