Skip to content

Commit e8a9f21

Browse files
committed
[GUI][Model] * P2CS records, P2CSDelegationSent type created for spendable.
* ColdStaking, Staker screen not showing P2CSDelegationSent stake/blacklist options. * Dashboard filter by delegated txs [Trivial] Missing .h include
1 parent ba8c1c0 commit e8a9f21

11 files changed

+59
-24
lines changed

src/addressbook.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Distributed under the MIT software license, see the accompanying
33
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
44

5+
#include "addressbook.h"
56
#include <string>
67

78
namespace AddressBook {

src/qt/pivx/coldstakingmodel.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ ColdStakingModel::ColdStakingModel(WalletModel* _model,
1717
}
1818

1919
void ColdStakingModel::updateCSList(){
20-
emit dataChanged(index(0, 0, QModelIndex()), index(tableModel->csRowCount(), 6, QModelIndex()) );
20+
emit dataChanged(index(0, 0, QModelIndex()), index(tableModel->csRowCount(), 7, QModelIndex()) );
2121
}
2222

2323
int ColdStakingModel::rowCount(const QModelIndex &parent) const
@@ -31,7 +31,7 @@ int ColdStakingModel::columnCount(const QModelIndex &parent) const
3131
{
3232
if (parent.isValid())
3333
return 0;
34-
return 6;
34+
return 7;
3535
}
3636

3737

@@ -56,6 +56,8 @@ QVariant ColdStakingModel::data(const QModelIndex &index, int role) const
5656
return GUIUtil::formatBalance(rec.cachedTotalAmount);
5757
case TOTAL_STACKEABLE_AMOUNT:
5858
return qint64(rec.cachedTotalAmount);
59+
case IS_RECEIVED_DELEGATION:
60+
return !rec.isSpendable;
5961
}
6062
}
6163

@@ -68,7 +70,7 @@ bool ColdStakingModel::whitelist(const QModelIndex& modelIndex) {
6870
beginRemoveRows(QModelIndex(), idx, idx);
6971
bool ret = model->whitelistAddressFromColdStaking(address);
7072
endRemoveRows();
71-
emit dataChanged(index(idx, 0, QModelIndex()), index(idx, 6, QModelIndex()) );
73+
emit dataChanged(index(idx, 0, QModelIndex()), index(idx, 7, QModelIndex()) );
7274
return ret;
7375
}
7476

@@ -78,6 +80,6 @@ bool ColdStakingModel::blacklist(const QModelIndex& modelIndex) {
7880
beginRemoveRows(QModelIndex(), idx, idx);
7981
bool ret = model->blacklistAddressFromColdStaking(address);
8082
endRemoveRows();
81-
emit dataChanged(index(idx, 0, QModelIndex()), index(idx, 6, QModelIndex()) );
83+
emit dataChanged(index(idx, 0, QModelIndex()), index(idx, 7, QModelIndex()) );
8284
return ret;
8385
}

src/qt/pivx/coldstakingmodel.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ class ColdStakingModel : public QAbstractTableModel
2525
IS_WHITELISTED_STRING = 3,
2626
DELEGATED_UTXO_IDS = 4,
2727
TOTAL_STACKEABLE_AMOUNT_STR = 5,
28-
TOTAL_STACKEABLE_AMOUNT = 6
28+
TOTAL_STACKEABLE_AMOUNT = 6,
29+
IS_RECEIVED_DELEGATION = 7
2930
};
3031

3132
int rowCount(const QModelIndex &parent = QModelIndex()) const override;

src/qt/pivx/coldstakingwidget.cpp

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -299,11 +299,26 @@ void ColdStakingWidget::onSendClicked(){
299299
}
300300

301301
QString inputOwner = ui->lineEditOwnerAddress->text();
302-
if (!inputOwner.isEmpty() && !walletModel->validateAddress(inputOwner)) {
302+
bool isOwnerEmpty = inputOwner.isEmpty();
303+
if (!isOwnerEmpty && !walletModel->validateAddress(inputOwner)) {
303304
inform(tr("Owner address invalid"));
304305
return;
305306
}
306307

308+
309+
bool isStakingAddressFromThisWallet = walletModel->isMine(dest.address);
310+
bool isOwnerAddressFromThisWallet = isOwnerEmpty;
311+
312+
if (!isOwnerAddressFromThisWallet) {
313+
isOwnerAddressFromThisWallet = walletModel->isMine(inputOwner);
314+
}
315+
316+
// Don't try to delegate the balance if both addresses are from this wallet
317+
if (isStakingAddressFromThisWallet && isOwnerAddressFromThisWallet) {
318+
inform(tr("Staking address corresponds to this wallet, change it to an external node"));
319+
return;
320+
}
321+
307322
dest.ownerAddress = inputOwner;
308323
QList<SendCoinsRecipient> recipients;
309324
recipients.append(dest);
@@ -421,9 +436,20 @@ void ColdStakingWidget::handleAddressClicked(const QModelIndex &rIndex){
421436

422437
this->index = rIndex;
423438

424-
bool isWhitelisted = rIndex.sibling(rIndex.row(), ColdStakingModel::IS_WHITELISTED).data(Qt::DisplayRole).toBool();
425-
this->menu->setDeleteBtnVisible(isWhitelisted);
426-
this->menu->setEditBtnVisible(!isWhitelisted);
439+
bool isReceivedDelegation = rIndex.sibling(rIndex.row(), ColdStakingModel::IS_RECEIVED_DELEGATION).data(Qt::DisplayRole).toBool();
440+
441+
if (isReceivedDelegation) {
442+
bool isWhitelisted = rIndex.sibling(rIndex.row(), ColdStakingModel::IS_WHITELISTED).data(
443+
Qt::DisplayRole).toBool();
444+
this->menu->setDeleteBtnVisible(isWhitelisted);
445+
this->menu->setEditBtnVisible(!isWhitelisted);
446+
this->menu->setMinimumHeight(75);
447+
} else {
448+
// owner side
449+
this->menu->setDeleteBtnVisible(false);
450+
this->menu->setEditBtnVisible(false);
451+
this->menu->setMinimumHeight(60);
452+
}
427453
if (adjustSize) this->menu->adjustSize();
428454

429455
menu->move(pos);

src/qt/pivx/dashboardwidget.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ DashboardWidget::DashboardWidget(PIVXGUI* parent) :
112112
ui->comboBoxSortType->addItem(tr("To yourself"), TransactionFilterProxy::TYPE(TransactionRecord::SendToSelf));
113113
ui->comboBoxSortType->addItem(tr("Cold stakes"), TransactionFilterProxy::TYPE(TransactionRecord::StakeDelegated));
114114
ui->comboBoxSortType->addItem(tr("Hot stakes"), TransactionFilterProxy::TYPE(TransactionRecord::StakeHot));
115+
ui->comboBoxSortType->addItem(tr("Delegated"), TransactionFilterProxy::TYPE(TransactionRecord::P2CSDelegationSent));
115116
ui->comboBoxSortType->addItem(tr("Delegations"), TransactionFilterProxy::TYPE(TransactionRecord::P2CSDelegation));
116117
ui->comboBoxSortType->setCurrentIndex(0);
117118
connect(ui->comboBoxSortType, SIGNAL(currentIndexChanged(const QString&)), this, SLOT(onSortTypeChanged(const QString&)));

src/qt/pivx/txrow.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ void TxRow::setType(bool isLightTheme, int type, bool isConfirmed){
9292
path = "://ic-transaction-stake-hot";
9393
css = "text-list-amount-unconfirmed";
9494
break;
95+
case TransactionRecord::P2CSDelegationSent:
9596
case TransactionRecord::P2CSDelegation:
9697
path = "://ic-transaction-cs-contract";
9798
css = "text-list-amount-unconfirmed";

src/qt/transactionfilterproxy.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ bool TransactionFilterProxy::isStakeTx(int type) const {
166166
}
167167

168168
bool TransactionFilterProxy::isColdStake(int type) const {
169-
return (type == TransactionRecord::P2CSDelegation || type == TransactionRecord::StakeDelegated || type == TransactionRecord::StakeHot);
169+
return (type == TransactionRecord::P2CSDelegation || type == TransactionRecord::P2CSDelegationSent || type == TransactionRecord::StakeDelegated || type == TransactionRecord::StakeHot);
170170
}
171171

172172
/*QVariant TransactionFilterProxy::dataFromSourcePos(int sourceRow, int role) const {

src/qt/transactionrecord.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -345,14 +345,9 @@ void TransactionRecord::loadHotOrColdStakeOrContract(const CWallet* wallet, cons
345345
bool isSpendable = wallet->IsMine(p2csUtxo) & ISMINE_SPENDABLE_DELEGATED;
346346

347347
if (isContract) {
348-
record.type = TransactionRecord::P2CSDelegation;
348+
record.type = (isSpendable ? TransactionRecord::P2CSDelegationSent : TransactionRecord::P2CSDelegation);
349349
record.debit = wtx.nDelegatedDebitCached;
350350
record.credit = wtx.GetStakeDelegationCredit();
351-
if (isSpendable) {
352-
// Means that this wallet can redeem the p2cs, this was a send to yourself..
353-
// TODO: add some way to represent this..
354-
}
355-
356351
} else {
357352
// Stake
358353
if (isSpendable) {
@@ -362,6 +357,7 @@ void TransactionRecord::loadHotOrColdStakeOrContract(const CWallet* wallet, cons
362357
} else {
363358
record.type = TransactionRecord::StakeHot;
364359
record.credit = wtx.GetColdStakingCredit();
360+
record.debit = wtx.nColdDebitCached;
365361
}
366362
}
367363

src/qt/transactionrecord.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ class TransactionRecord
9797
Obfuscated,
9898
StakeDelegated, // Received cold stake (owner)
9999
StakeHot, // Staked via a delegated P2CS.
100-
P2CSDelegation
100+
P2CSDelegation, // Non-spendable P2CS, staker side.
101+
P2CSDelegationSent // Spendable P2CS delegated utxo. (coin-owner)
101102
};
102103

103104
/** Number of confirmation recommended for accepting a transaction */

src/qt/transactiontablemodel.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ class TransactionTablePriv
151151
}
152152

153153
// Check for delegations
154-
if (record.type == TransactionRecord::P2CSDelegation) {
154+
if (record.type == TransactionRecord::P2CSDelegation || record.type == TransactionRecord::P2CSDelegationSent) {
155155
checkForDelegations(record, cachedDelegations);
156156
}
157157
}
@@ -168,14 +168,15 @@ class TransactionTablePriv
168168

169169
static void checkForDelegations(const TransactionRecord& record, QList<CSDelegation>& cachedDelegations) {
170170
CSDelegation delegation(false, record.address);
171-
delegation.cachedTotalAmount += record.credit;
172171
int index = cachedDelegations.indexOf(delegation);
173172
if (index == -1) {
173+
delegation.cachedTotalAmount += record.credit + record.debit;
174+
delegation.isSpendable = record.type == TransactionRecord::P2CSDelegationSent;
174175
cachedDelegations.append(delegation);
175176
} else {
176177
CSDelegation del = cachedDelegations[index];
177178
del.delegatedUtxo.append(record.getTxID());
178-
del.cachedTotalAmount += record.credit;
179+
del.cachedTotalAmount += record.credit + record.debit;
179180
}
180181

181182
}
@@ -241,10 +242,10 @@ class TransactionTablePriv
241242
cachedWallet.insert(insert_idx, rec);
242243
if (!hasZcTxes) hasZcTxes = HasZcTxesIfNeeded(rec);
243244

244-
// Check for delegations
245-
if (rec.type == TransactionRecord::P2CSDelegation) {
246-
checkForDelegations(rec, cachedDelegations);
247-
}
245+
// Check for delegations
246+
if (rec.type == TransactionRecord::P2CSDelegation || rec.type == TransactionRecord::P2CSDelegationSent) {
247+
checkForDelegations(rec, cachedDelegations);
248+
}
248249

249250
insert_idx += 1;
250251
// Return record
@@ -486,6 +487,7 @@ QString TransactionTableModel::formatTxType(const TransactionRecord* wtx) const
486487
return tr("zPIV Stake");
487488
case TransactionRecord::StakeHot:
488489
return tr("PIV Stake in behalf of");
490+
case TransactionRecord::P2CSDelegationSent:
489491
case TransactionRecord::P2CSDelegation:
490492
return tr("Stake delegation");
491493
case TransactionRecord::Generated:

0 commit comments

Comments
 (0)