Skip to content

Commit 58c3781

Browse files
committed
[GUI][Model] Dashboard, P2CS contract transaction connected.
[GUI][Model] Dashboard, P2CS contract transaction connected.
1 parent 52f29ee commit 58c3781

11 files changed

+113
-15
lines changed

src/Makefile.qt.include

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -580,6 +580,7 @@ RES_ICONS = \
580580
qt/pivx/res/img/ic-check-box-liliac-indeterminate.svg \
581581
qt/pivx/res/img/ic-transaction-stake-delegated.svg \
582582
qt/pivx/res/img/ic-transaction-stake-hot.svg \
583+
qt/pivx/res/img/ic-transaction-cs-contract.svg \
583584
qt/pivx/res/img/ic-check-box-indeterminate.svg \
584585
qt/pivx/res/img/ani-loading-dark.gif \
585586
qt/pivx/res/img/ani-loading.gif

src/qt/pivx.qrc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,5 +307,7 @@
307307
<file alias="ic-pending">pivx/res/img/ic-pending.svg</file>
308308
<file alias="ic-transaction-stake-delegated">pivx/res/img/ic-transaction-stake-delegated.svg</file>
309309
<file alias="ic-transaction-stake-hot">pivx/res/img/ic-transaction-stake-hot.svg</file>
310+
<file alias="ic-transaction-cs-contract">pivx/res/img/ic-transaction-cs-contract.svg</file>
311+
310312
</qresource>
311313
</RCC>

src/qt/pivx/dashboardwidget.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,9 @@ DashboardWidget::DashboardWidget(PIVXGUI* parent) :
110110
ui->comboBoxSortType->addItem(tr("Minted"), TransactionFilterProxy::TYPE(TransactionRecord::StakeMint));
111111
ui->comboBoxSortType->addItem(tr("MN reward"), TransactionFilterProxy::TYPE(TransactionRecord::MNReward));
112112
ui->comboBoxSortType->addItem(tr("To yourself"), TransactionFilterProxy::TYPE(TransactionRecord::SendToSelf));
113+
ui->comboBoxSortType->addItem(tr("Cold stakes"), TransactionFilterProxy::TYPE(TransactionRecord::StakeDelegated));
114+
ui->comboBoxSortType->addItem(tr("Hot stakes"), TransactionFilterProxy::TYPE(TransactionRecord::StakeHot));
115+
ui->comboBoxSortType->addItem(tr("Delegations"), TransactionFilterProxy::TYPE(TransactionRecord::P2CSDelegation));
113116
ui->comboBoxSortType->setCurrentIndex(0);
114117
connect(ui->comboBoxSortType, SIGNAL(currentIndexChanged(const QString&)), this, SLOT(onSortTypeChanged(const QString&)));
115118

src/qt/pivx/forms/txrow.ui

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@
8787
</property>
8888
<property name="iconSize">
8989
<size>
90-
<width>24</width>
91-
<height>24</height>
90+
<width>28</width>
91+
<height>28</height>
9292
</size>
9393
</property>
9494
</widget>
@@ -99,7 +99,7 @@
9999
<number>3</number>
100100
</property>
101101
<property name="leftMargin">
102-
<number>12</number>
102+
<number>9</number>
103103
</property>
104104
<item>
105105
<widget class="QLabel" name="lblAddress">
Lines changed: 33 additions & 0 deletions
Loading

src/qt/pivx/txrow.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,11 @@ 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::P2CSDelegation:
96+
path = "://ic-transaction-cs-contract";
97+
css = "text-list-amount-unconfirmed";
98+
sameIcon = true;
99+
break;
95100
default:
96101
path = "://ic-pending";
97102
sameIcon = true;

src/qt/transactionfilterproxy.cpp

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ bool TransactionFilterProxy::filterAcceptsRow(int sourceRow, const QModelIndex&
6464
if (fOnlyStakes && !isStakeTx(type))
6565
return false;
6666

67+
if (fOnlyColdStaking && !isColdStake(type))
68+
return false;
69+
6770
return true;
6871
}
6972

@@ -117,16 +120,24 @@ void TransactionFilterProxy::setHideOrphans(bool fHide)
117120
invalidateFilter();
118121
}
119122

120-
void TransactionFilterProxy::setShowZcTxes(bool fOnlyZc){
123+
void TransactionFilterProxy::setShowZcTxes(bool fOnlyZc)
124+
{
121125
this->fOnlyZc = fOnlyZc;
122126
invalidateFilter();
123127
}
124128

125-
void TransactionFilterProxy::setOnlyStakes(bool fOnlyStakes){
129+
void TransactionFilterProxy::setOnlyStakes(bool fOnlyStakes)
130+
{
126131
this->fOnlyStakes = fOnlyStakes;
127132
invalidateFilter();
128133
}
129134

135+
void TransactionFilterProxy::setOnlyColdStakes(bool fOnlyColdStakes)
136+
{
137+
this->fOnlyColdStaking = fOnlyColdStakes;
138+
invalidateFilter();
139+
}
140+
130141
int TransactionFilterProxy::rowCount(const QModelIndex& parent) const
131142
{
132143
if (limitRows != -1) {
@@ -152,6 +163,10 @@ bool TransactionFilterProxy::isStakeTx(int type) const {
152163
return (type == TransactionRecord::StakeMint || type == TransactionRecord::Generated || type == TransactionRecord::StakeZPIV);
153164
}
154165

166+
bool TransactionFilterProxy::isColdStake(int type) const {
167+
return (type == TransactionRecord::P2CSDelegation || type == TransactionRecord::StakeDelegated || type == TransactionRecord::StakeHot);
168+
}
169+
155170
/*QVariant TransactionFilterProxy::dataFromSourcePos(int sourceRow, int role) const {
156171
QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent);
157172
return index.data(index, role);

src/qt/transactionfilterproxy.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ class TransactionFilterProxy : public QSortFilterProxyModel
6565
/** Only stakes txes **/
6666
void setOnlyStakes(bool fOnlyStakes);
6767

68+
/** Shows only p2cs-p2cs && xxx-p2cs **/
69+
void setOnlyColdStakes(bool fOnlyColdStakes);
70+
6871
int rowCount(const QModelIndex& parent = QModelIndex()) const;
6972
static bool isOrphan(const int status, const int type);
7073

@@ -85,9 +88,11 @@ class TransactionFilterProxy : public QSortFilterProxyModel
8588
bool fHideOrphans = true;
8689
bool fOnlyZc = false;
8790
bool fOnlyStakes = false;
91+
bool fOnlyColdStaking = false;
8892

8993
bool isZcTx(int type) const;
9094
bool isStakeTx(int type) const;
95+
bool isColdStake(int type) const;
9196
};
9297

9398
#endif // BITCOIN_QT_TRANSACTIONFILTERPROXY_H

src/qt/transactionrecord.cpp

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ QList<TransactionRecord> TransactionRecord::decomposeTransaction(const CWallet*
5353
TransactionRecord sub(hash, nTime, wtx.GetTotalSize());
5454
// Check for cold stakes.
5555
if (wtx.HasP2CSOutputs()) {
56-
loadHotOrColdStake(wallet, wtx, sub);
56+
loadHotOrColdStakeOrContract(wallet, wtx, sub);
5757
parts.append(sub);
5858
return parts;
5959
}
@@ -156,6 +156,13 @@ QList<TransactionRecord> TransactionRecord::decomposeTransaction(const CWallet*
156156
sub.idx = parts.size();
157157
parts.append(sub);
158158
}
159+
} else if (wtx.HasP2CSOutputs()) {
160+
// Delegate tx.
161+
// TODO: Think this well..
162+
TransactionRecord sub(hash, nTime, wtx.GetTotalSize());
163+
loadHotOrColdStakeOrContract(wallet, wtx, sub, true);
164+
parts.append(sub);
165+
return parts;
159166
} else if (nNet > 0 || wtx.IsCoinBase()) {
160167
//
161168
// Credit
@@ -322,17 +329,40 @@ QList<TransactionRecord> TransactionRecord::decomposeTransaction(const CWallet*
322329
return parts;
323330
}
324331

325-
void TransactionRecord::loadHotOrColdStake(const CWallet* wallet, const CWalletTx& wtx, TransactionRecord& record)
332+
void TransactionRecord::loadHotOrColdStakeOrContract(const CWallet* wallet, const CWalletTx& wtx, TransactionRecord& record, bool isContract)
326333
{
327334
record.involvesWatchAddress = false;
328-
CTxOut p2csUtxo = wtx.vout[1];
335+
336+
// Get the p2cs
337+
CTxOut p2csUtxo;
338+
for (unsigned int nOut = 0; nOut < wtx.vout.size(); nOut++) {
339+
const CTxOut &txout = wtx.vout[nOut];
340+
if (txout.scriptPubKey.IsPayToColdStaking()) {
341+
p2csUtxo = txout;
342+
break;
343+
}
344+
}
329345
bool isSpendable = wallet->IsMine(p2csUtxo) & ISMINE_SPENDABLE_DELEGATED;
330-
if (isSpendable) {
331-
record.type = TransactionRecord::StakeDelegated;
346+
347+
if (isContract) {
348+
record.type = TransactionRecord::P2CSDelegation;
349+
record.debit = wtx.nDelegatedDebitCached;
332350
record.credit = wtx.nDelegatedCreditCached;
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+
333356
} else {
334-
record.type = TransactionRecord::StakeHot;
335-
record.credit = wtx.nColdCreditCached;
357+
// Stake
358+
if (isSpendable) {
359+
record.type = TransactionRecord::StakeDelegated;
360+
record.credit = wtx.nDelegatedCreditCached;
361+
record.debit = wtx.nDelegatedDebitCached;
362+
} else {
363+
record.type = TransactionRecord::StakeHot;
364+
record.credit = wtx.nColdCreditCached;
365+
}
336366
}
337367

338368
CTxDestination address;

src/qt/transactionrecord.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,9 @@ class TransactionRecord
9595
ObfuscationMakeCollaterals,
9696
ObfuscationCreateDenominations,
9797
Obfuscated,
98-
StakeDelegated, // Received cold stake
99-
StakeHot // Staked via a delegated P2CS.
98+
StakeDelegated, // Received cold stake (owner)
99+
StakeHot, // Staked via a delegated P2CS.
100+
P2CSDelegation
100101
};
101102

102103
/** Number of confirmation recommended for accepting a transaction */
@@ -169,7 +170,7 @@ class TransactionRecord
169170

170171

171172
private:
172-
static void loadHotOrColdStake(const CWallet* wallet, const CWalletTx& wtx, TransactionRecord& record);
173+
static void loadHotOrColdStakeOrContract(const CWallet* wallet, const CWalletTx& wtx, TransactionRecord& record, bool isContract = false);
173174
};
174175

175176
#endif // BITCOIN_QT_TRANSACTIONRECORD_H

0 commit comments

Comments
 (0)