diff --git a/src/rpc.cpp b/src/rpc.cpp index 1f94ba2..debed9c 100644 --- a/src/rpc.cpp +++ b/src/rpc.cpp @@ -333,7 +333,7 @@ void RPC::getBatchRPC( } /// Batch RPC methods -void RPC::getReceivedZTrans(QList zaddrs) { +void RPC::refreshReceivedZTrans(QList zaddrs, QList txidFilter) { // 1. For each z-Addr, get list of received txs getBatchRPC(zaddrs, [=] (QString zaddr) { @@ -376,16 +376,20 @@ void RPC::getReceivedZTrans(QList zaddrs) { auto zaddr = it.key(); auto txid = QString::fromStdString(i["txid"].get()); - // Lookup txid in the map - auto txidInfo = txidDetails->value(txid); + // We're filter out all the txids from this list, so as to not show a "received" transaction for a change address. + // Note: the txidFilter is the list of all sent TxIDs + if (!txidFilter.contains(txid)) { + // Lookup txid in the map + auto txidInfo = txidDetails->value(txid); - // And then find the values - auto timestamp = txidInfo["time"].get(); - auto amount = i["amount"].get(); - auto confirmations = txidInfo["confirmations"].get(); + // And then find the values + auto timestamp = txidInfo["time"].get(); + auto amount = i["amount"].get(); + auto confirmations = txidInfo["confirmations"].get(); - TransactionItem tx{ QString("receive"), timestamp, zaddr, txid, amount, confirmations }; - txdata.push_front(tx); + TransactionItem tx{ QString("receive"), timestamp, zaddr, txid, amount, confirmations }; + txdata.push_front(tx); + } } } @@ -427,9 +431,8 @@ void RPC::getInfoThenRefresh() { // Refresh everything. refreshBalances(); - refreshAddresses(); + refreshAddresses(); // This calls refreshZSentTransactions() -> which calls refreshReceivedZTrans(0) refreshTransactions(); - refreshZSentTransactions(); // Call to see if the blockchain is syncing. json payload = { @@ -474,8 +477,8 @@ void RPC::refreshAddresses() { zaddresses->push_back(addr); } - // Temp - getReceivedZTrans(*zaddresses); + // Refresh the sent txs from all these zaddresses + refreshSentZTrans(*zaddresses); }); } @@ -579,7 +582,7 @@ void RPC::refreshTransactions() { } // Read sent Z transactions from the file. -void RPC::refreshZSentTransactions() { +void RPC::refreshSentZTrans(QList zaddresses) { auto sentZTxs = SentTxStore::readSentTxFile(); QList txids; @@ -587,6 +590,9 @@ void RPC::refreshZSentTransactions() { txids.push_back(sentTx.txid); } + // We need to filter out the sent txids from the zreceived list. + refreshReceivedZTrans(zaddresses, txids); + // Look up all the txids to get the confirmation count for them. getBatchRPC(txids, [=] (QString txid) { diff --git a/src/rpc.h b/src/rpc.h index 1acf0d6..3a9becb 100644 --- a/src/rpc.h +++ b/src/rpc.h @@ -50,8 +50,10 @@ private: void doSendRPC (const json& payload, const std::function& cb); void refreshBalances(); + void refreshTransactions(); - void refreshZSentTransactions(); + void refreshSentZTrans (QList zaddresses); + void refreshReceivedZTrans (QList zaddrs, QList txidFilter); bool processUnspent (const json& reply); void updateUI (bool anyUnconfirmed); @@ -69,7 +71,6 @@ private: void handleTxError (const QString& error); // Batch - void getReceivedZTrans(QList zaddrs); void getBatchRPC(const QList& payloads, std::function payloadGenerator, std::function*)> cb); diff --git a/src/txtablemodel.cpp b/src/txtablemodel.cpp index 3472dbd..ebabcef 100644 --- a/src/txtablemodel.cpp +++ b/src/txtablemodel.cpp @@ -37,18 +37,21 @@ void TxTableModel::addTData(const QList& data) { updateAllData(); } -void TxTableModel::updateAllData() { - delete modeldata; - modeldata = new QList(); +void TxTableModel::updateAllData() { + auto newmodeldata = new QList(); - if (tTrans != nullptr) std::copy( tTrans->begin(), tTrans->end(), std::back_inserter(*modeldata)); - if (zsTrans != nullptr) std::copy(zsTrans->begin(), zsTrans->end(), std::back_inserter(*modeldata)); - if (zrTrans != nullptr) std::copy(zrTrans->begin(), zrTrans->end(), std::back_inserter(*modeldata)); + if (tTrans != nullptr) std::copy( tTrans->begin(), tTrans->end(), std::back_inserter(*newmodeldata)); + if (zsTrans != nullptr) std::copy(zsTrans->begin(), zsTrans->end(), std::back_inserter(*newmodeldata)); + if (zrTrans != nullptr) std::copy(zrTrans->begin(), zrTrans->end(), std::back_inserter(*newmodeldata)); // Sort by reverse time - std::sort(modeldata->begin(), modeldata->end(), [=] (auto a, auto b) { + std::sort(newmodeldata->begin(), newmodeldata->end(), [=] (auto a, auto b) { return a.datetime > b.datetime; // reverse sort }); + + // And then swap out the modeldata with the new one. + delete modeldata; + modeldata = newmodeldata; dataChanged(index(0, 0), index(modeldata->size()-1, columnCount(index(0,0))-1)); layoutChanged();