MCPcopy Create free account
hub / github.com/BTCGPU/BTCGPU / updateWallet

Method updateWallet

src/qt/transactiontablemodel.cpp:94–172  ·  view source on GitHub ↗

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. */

Source from the content-addressed store, hash-verified

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;

Callers 1

updateTransactionMethod · 0.80

Calls 9

TxLessThanClass · 0.85
getWalletTxMethod · 0.80
QModelIndexClass · 0.70
ToStringMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
sizeMethod · 0.45
insertMethod · 0.45
eraseMethod · 0.45

Tested by

no test coverage detected