Supress showing change receives in the transactions table.

This commit is contained in:
Aditya Kulkarni
2018-10-23 17:12:06 -07:00
parent 9694ab7439
commit dd256bd304
3 changed files with 33 additions and 23 deletions

View File

@@ -333,7 +333,7 @@ void RPC::getBatchRPC(
}
/// Batch RPC methods
void RPC::getReceivedZTrans(QList<QString> zaddrs) {
void RPC::refreshReceivedZTrans(QList<QString> zaddrs, QList<QString> txidFilter) {
// 1. For each z-Addr, get list of received txs
getBatchRPC(zaddrs,
[=] (QString zaddr) {
@@ -376,16 +376,20 @@ void RPC::getReceivedZTrans(QList<QString> zaddrs) {
auto zaddr = it.key();
auto txid = QString::fromStdString(i["txid"].get<json::string_t>());
// 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<json::number_unsigned_t>();
auto amount = i["amount"].get<json::number_float_t>();
auto confirmations = txidInfo["confirmations"].get<json::number_unsigned_t>();
// And then find the values
auto timestamp = txidInfo["time"].get<json::number_unsigned_t>();
auto amount = i["amount"].get<json::number_float_t>();
auto confirmations = txidInfo["confirmations"].get<json::number_unsigned_t>();
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<QString> zaddresses) {
auto sentZTxs = SentTxStore::readSentTxFile();
QList<QString> 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) {

View File

@@ -50,8 +50,10 @@ private:
void doSendRPC (const json& payload, const std::function<void(json)>& cb);
void refreshBalances();
void refreshTransactions();
void refreshZSentTransactions();
void refreshSentZTrans (QList<QString> zaddresses);
void refreshReceivedZTrans (QList<QString> zaddrs, QList<QString> txidFilter);
bool processUnspent (const json& reply);
void updateUI (bool anyUnconfirmed);
@@ -69,7 +71,6 @@ private:
void handleTxError (const QString& error);
// Batch
void getReceivedZTrans(QList<QString> zaddrs);
void getBatchRPC(const QList<QString>& payloads,
std::function<json(QString)> payloadGenerator,
std::function<void(QMap<QString, json>*)> cb);

View File

@@ -37,18 +37,21 @@ void TxTableModel::addTData(const QList<TransactionItem>& data) {
updateAllData();
}
void TxTableModel::updateAllData() {
delete modeldata;
modeldata = new QList<TransactionItem>();
void TxTableModel::updateAllData() {
auto newmodeldata = new QList<TransactionItem>();
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();