Skip to content

Commit 5101902

Browse files
committed
[Model] * TransactionTableModel, update cachedDelegations when new p2cs output is received.
* WalletModel, isDelegatedToMe method created.
1 parent 090daee commit 5101902

File tree

3 files changed

+40
-10
lines changed

3 files changed

+40
-10
lines changed

src/qt/transactiontablemodel.cpp

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -152,16 +152,7 @@ class TransactionTablePriv
152152

153153
// Check for delegations
154154
if (record.type == TransactionRecord::P2CSDelegation) {
155-
CSDelegation delegation(false, record.address);
156-
delegation.cachedTotalAmount += record.credit;
157-
int index = cachedDelegations.indexOf(delegation);
158-
if (index == -1) {
159-
cachedDelegations.append(delegation);
160-
} else {
161-
CSDelegation del = cachedDelegations[index];
162-
del.delegatedUtxo.append(record.getTxID());
163-
del.cachedTotalAmount += record.credit;
164-
}
155+
checkForDelegations(record, cachedDelegations);
165156
}
166157
}
167158

@@ -175,6 +166,20 @@ class TransactionTablePriv
175166
return std::make_pair(cachedWallet, cachedDelegations);
176167
}
177168

169+
static void checkForDelegations(const TransactionRecord& record, QList<CSDelegation>& cachedDelegations) {
170+
CSDelegation delegation(false, record.address);
171+
delegation.cachedTotalAmount += record.credit;
172+
int index = cachedDelegations.indexOf(delegation);
173+
if (index == -1) {
174+
cachedDelegations.append(delegation);
175+
} else {
176+
CSDelegation del = cachedDelegations[index];
177+
del.delegatedUtxo.append(record.getTxID());
178+
del.cachedTotalAmount += record.credit;
179+
}
180+
181+
}
182+
178183
static bool HasZcTxesIfNeeded(const TransactionRecord& record) {
179184
return (record.type == TransactionRecord::ZerocoinMint ||
180185
record.type == TransactionRecord::ZerocoinSpend ||
@@ -235,6 +240,12 @@ class TransactionTablePriv
235240
for (const TransactionRecord& rec : toInsert) {
236241
cachedWallet.insert(insert_idx, rec);
237242
if (!hasZcTxes) hasZcTxes = HasZcTxesIfNeeded(rec);
243+
244+
// Check for delegations
245+
if (rec.type == TransactionRecord::P2CSDelegation) {
246+
checkForDelegations(rec, cachedDelegations);
247+
}
248+
238249
insert_idx += 1;
239250
// Return record
240251
ret = rec;

src/qt/walletmodel.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,20 @@ const CWalletTx* WalletModel::getTx(uint256 id){
506506
return wallet->GetWalletTx(id);
507507
}
508508

509+
bool WalletModel::isDelegatedToMe(QString id) {
510+
uint256 hashTx;
511+
hashTx.SetHex(id.toStdString());
512+
const CWalletTx* tx = getTx(hashTx);
513+
if (tx && tx->HasP2CSOutputs()) {
514+
for (auto out : tx->vout) {
515+
if (wallet->IsMine(out) & ISMINE_COLD) {
516+
return true;
517+
}
518+
}
519+
}
520+
return false;
521+
}
522+
509523
bool WalletModel::mintCoins(CAmount value, CCoinControl* coinControl ,std::string &strError){
510524
CWalletTx wtx;
511525
std::vector<CDeterministicMint> vMints;

src/qt/walletmodel.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,11 @@ class WalletModel : public QObject
277277
*/
278278
PairResult getNewStakingAddress(CBitcoinAddress& ret, std::string label = "") const;
279279

280+
/**
281+
* If the wallet has the tx and it was a stakes delegation to this wallet
282+
*/
283+
bool isDelegatedToMe(QString txId);
284+
280285
bool whitelistAddressFromColdStaking(const QString &addressStr);
281286
bool blacklistAddressFromColdStaking(const QString &address);
282287
bool updateAddressBookPurpose(const QString &addressStr, const std::string& purpose);

0 commit comments

Comments
 (0)