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. */
| 127 | Call with transaction that was added, removed or changed. |
| 128 | */ |
| 129 | void updateWallet(interfaces::Wallet& wallet, const Txid& hash, int status, bool showTransaction) |
| 130 | { |
| 131 | qDebug() << "TransactionTablePriv::updateWallet: " + QString::fromStdString(hash.ToString()) + " " + QString::number(status); |
| 132 | |
| 133 | // Find bounds of this transaction in model |
| 134 | QList<TransactionRecord>::iterator lower = std::lower_bound( |
| 135 | cachedWallet.begin(), cachedWallet.end(), hash, TxLessThan()); |
| 136 | QList<TransactionRecord>::iterator upper = std::upper_bound( |
| 137 | cachedWallet.begin(), cachedWallet.end(), hash, TxLessThan()); |
| 138 | int lowerIndex = (lower - cachedWallet.begin()); |
| 139 | int upperIndex = (upper - cachedWallet.begin()); |
| 140 | bool inModel = (lower != upper); |
| 141 | |
| 142 | if(status == CT_UPDATED) |
| 143 | { |
| 144 | if(showTransaction && !inModel) |
| 145 | status = CT_NEW; /* Not in model, but want to show, treat as new */ |
| 146 | if(!showTransaction && inModel) |
| 147 | status = CT_DELETED; /* In model, but want to hide, treat as deleted */ |
| 148 | } |
| 149 | |
| 150 | qDebug() << " inModel=" + QString::number(inModel) + |
| 151 | " Index=" + QString::number(lowerIndex) + "-" + QString::number(upperIndex) + |
| 152 | " showTransaction=" + QString::number(showTransaction) + " derivedStatus=" + QString::number(status); |
| 153 | |
| 154 | switch(status) |
| 155 | { |
| 156 | case CT_NEW: |
| 157 | if(inModel) |
| 158 | { |
| 159 | qWarning() << "TransactionTablePriv::updateWallet: Warning: Got CT_NEW, but transaction is already in model"; |
| 160 | break; |
| 161 | } |
| 162 | if(showTransaction) |
| 163 | { |
| 164 | // Find transaction in wallet |
| 165 | interfaces::WalletTx wtx = wallet.getWalletTx(hash); |
| 166 | if(!wtx.tx) |
| 167 | { |
| 168 | qWarning() << "TransactionTablePriv::updateWallet: Warning: Got CT_NEW, but transaction is not in wallet"; |
| 169 | break; |
| 170 | } |
| 171 | // Added -- insert at the right position |
| 172 | QList<TransactionRecord> toInsert = |
| 173 | TransactionRecord::decomposeTransaction(wtx); |
| 174 | if(!toInsert.isEmpty()) /* only if something to insert */ |
| 175 | { |
| 176 | parent->beginInsertRows(QModelIndex(), lowerIndex, lowerIndex+toInsert.size()-1); |
| 177 | int insert_idx = lowerIndex; |
| 178 | for (const TransactionRecord &rec : toInsert) |
| 179 | { |
| 180 | cachedWallet.insert(insert_idx, rec); |
| 181 | insert_idx += 1; |
| 182 | } |
| 183 | parent->endInsertRows(); |
| 184 | } |
| 185 | } |
| 186 | break; |
no test coverage detected