Update our model of the wallet incrementally, to synchronize our model of the wallet with that of the core. Call with transaction that was added, removed or changed. */
| 92 | Call with transaction that was added, removed or changed. |
| 93 | */ |
| 94 | void updateWallet(interfaces::Wallet& wallet, const uint256 &hash, int status, bool showTransaction) |
| 95 | { |
| 96 | qDebug() << "TransactionTablePriv::updateWallet: " + QString::fromStdString(hash.ToString()) + " " + QString::number(status); |
| 97 | |
| 98 | // Find bounds of this transaction in model |
| 99 | QList<TransactionRecord>::iterator lower = qLowerBound( |
| 100 | cachedWallet.begin(), cachedWallet.end(), hash, TxLessThan()); |
| 101 | QList<TransactionRecord>::iterator upper = qUpperBound( |
| 102 | cachedWallet.begin(), cachedWallet.end(), hash, TxLessThan()); |
| 103 | int lowerIndex = (lower - cachedWallet.begin()); |
| 104 | int upperIndex = (upper - cachedWallet.begin()); |
| 105 | bool inModel = (lower != upper); |
| 106 | |
| 107 | if(status == CT_UPDATED) |
| 108 | { |
| 109 | if(showTransaction && !inModel) |
| 110 | status = CT_NEW; /* Not in model, but want to show, treat as new */ |
| 111 | if(!showTransaction && inModel) |
| 112 | status = CT_DELETED; /* In model, but want to hide, treat as deleted */ |
| 113 | } |
| 114 | |
| 115 | qDebug() << " inModel=" + QString::number(inModel) + |
| 116 | " Index=" + QString::number(lowerIndex) + "-" + QString::number(upperIndex) + |
| 117 | " showTransaction=" + QString::number(showTransaction) + " derivedStatus=" + QString::number(status); |
| 118 | |
| 119 | switch(status) |
| 120 | { |
| 121 | case CT_NEW: |
| 122 | if(inModel) |
| 123 | { |
| 124 | qWarning() << "TransactionTablePriv::updateWallet: Warning: Got CT_NEW, but transaction is already in model"; |
| 125 | break; |
| 126 | } |
| 127 | if(showTransaction) |
| 128 | { |
| 129 | // Find transaction in wallet |
| 130 | interfaces::WalletTx wtx = wallet.getWalletTx(hash); |
| 131 | if(!wtx.tx) |
| 132 | { |
| 133 | qWarning() << "TransactionTablePriv::updateWallet: Warning: Got CT_NEW, but transaction is not in wallet"; |
| 134 | break; |
| 135 | } |
| 136 | // Added -- insert at the right position |
| 137 | QList<TransactionRecord> toInsert = |
| 138 | TransactionRecord::decomposeTransaction(wtx); |
| 139 | if(!toInsert.isEmpty()) /* only if something to insert */ |
| 140 | { |
| 141 | parent->beginInsertRows(QModelIndex(), lowerIndex, lowerIndex+toInsert.size()-1); |
| 142 | int insert_idx = lowerIndex; |
| 143 | for (const TransactionRecord &rec : toInsert) |
| 144 | { |
| 145 | cachedWallet.insert(insert_idx, rec); |
| 146 | insert_idx += 1; |
| 147 | } |
| 148 | parent->endInsertRows(); |
| 149 | } |
| 150 | } |
| 151 | break; |
no test coverage detected