Skip to content

Commit 7c927b5

Browse files
committed
[GUI] Update Staking Slider to be reflective of status
1 parent 2f83d92 commit 7c927b5

File tree

4 files changed

+68
-3
lines changed

4 files changed

+68
-3
lines changed

src/qt/bitcoingui.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -988,6 +988,8 @@ void BitcoinGUI::setNumBlocks(int count, const QDateTime& blockDate, double nVer
988988
tooltip += tr("Transactions after this will not yet be visible.");
989989
}
990990

991+
veilStatusBar->updateStakingCheckbox();
992+
991993
// Don't word-wrap this (fixed-width) tooltip
992994
tooltip = QString("<nobr>") + tooltip + QString("</nobr>");
993995

src/qt/veil/veilstatusbar.cpp

+58-3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <qt/walletmodel.h>
1111
#include <qt/veil/qtutils.h>
1212
#include <iostream>
13+
#include <timedata.h>
1314
#ifdef ENABLE_WALLET
1415
#include <wallet/wallet.h> // For DEFAULT_DISABLE_WALLET
1516
#endif
@@ -51,6 +52,7 @@ void VeilStatusBar::updateSyncIndicator(int height){
5152

5253
void VeilStatusBar::setSyncStatusVisible(bool fVisible) {
5354
ui->btnSync->setVisible(fVisible);
55+
syncFlag = fVisible;
5456
}
5557

5658
void VeilStatusBar::onBtnSyncClicked(){
@@ -59,6 +61,52 @@ void VeilStatusBar::onBtnSyncClicked(){
5961

6062
#ifdef ENABLE_WALLET
6163
bool fBlockNextStakeCheckSignal = false;
64+
void VeilStatusBar::setStakingText() {
65+
66+
// Determine if staking is recently active. Note that this is not immediate effect. Staking could be disabled and it could take some time (activeStakingMaxTime) update state.
67+
int64_t nTimeLastHashing = 0;
68+
if (!mapHashedBlocks.empty()) {
69+
auto pindexBest = chainActive.Tip();
70+
if (mapHashedBlocks.count(pindexBest->GetBlockHash())) {
71+
nTimeLastHashing = mapHashedBlocks.at(pindexBest->GetBlockHash());
72+
} else if (mapHashedBlocks.count(pindexBest->pprev->GetBlockHash())) {
73+
nTimeLastHashing = mapHashedBlocks.at(pindexBest->pprev->GetBlockHash());
74+
}
75+
}
76+
bool fStakingActive = false;
77+
if (nTimeLastHashing)
78+
fStakingActive = GetAdjustedTime() + MAX_FUTURE_BLOCK_TIME - nTimeLastHashing < ACTIVE_STAKING_MAX_TIME;
79+
80+
WalletModel::EncryptionStatus eStatus = this->walletModel->getEncryptionStatus();
81+
82+
if (syncFlag){
83+
ui->checkStaking->setText("Staking Disabled while Syncing");
84+
}else if (WalletModel::Locked == eStatus) {
85+
ui->checkStaking->setText("Unlock wallet for Staking");
86+
}else if (this->walletModel->isStakingEnabled()) {
87+
if (fStakingActive) {
88+
ui->checkStaking->setText("Staking Enabled");
89+
}else{
90+
91+
interfaces::Wallet& wallet = walletModel->wallet();
92+
interfaces::WalletBalances balances = wallet.getBalances();
93+
int64_t zerocoin_balance = balances.zerocoin_balance;
94+
95+
if (0.0 < zerocoin_balance) {
96+
ui->checkStaking->setText("Enabling...");
97+
}else{
98+
ui->checkStaking->setText("You need some zerocoin");
99+
}
100+
}
101+
}else{
102+
if (fStakingActive) {
103+
ui->checkStaking->setText("Disabling...");
104+
}else{
105+
ui->checkStaking->setText("Staking Disabled");
106+
}
107+
}
108+
}
109+
62110
void VeilStatusBar::onCheckStakingClicked(bool res) {
63111
if (gArgs.GetBoolArg("-disablewallet", DEFAULT_DISABLE_WALLET))
64112
return;
@@ -77,16 +125,19 @@ void VeilStatusBar::onCheckStakingClicked(bool res) {
77125
openToastDialog(dialogMsg, mainWindow);
78126
fBlockNextStakeCheckSignal = true;
79127
ui->checkStaking->setChecked(false);
128+
setStakingText();
80129
return;
81130
}else{
82131
this->walletModel->setStakingEnabled(true);
83132
mainWindow->updateWalletStatus();
84133
openToastDialog("Staking enabled", mainWindow);
134+
setStakingText();
85135
}
86136
} else {
87137
this->walletModel->setStakingEnabled(false);
88138
mainWindow->updateWalletStatus();
89-
openToastDialog("Staking disabled", mainWindow);
139+
openToastDialog("Staking disabled - this may a few minutes", mainWindow);
140+
setStakingText();
90141
}
91142

92143
}
@@ -192,11 +243,15 @@ void VeilStatusBar::updateStakingCheckbox()
192243

193244
if(walletModel) {
194245
WalletModel::EncryptionStatus lockState = walletModel->getEncryptionStatus();
195-
bool stakingStatus = walletModel->isStakingEnabled() && lockState != WalletModel::Locked;
246+
247+
ui->checkStaking->setEnabled(!syncFlag);
248+
setStakingText();
249+
250+
bool stakingStatus = walletModel->isStakingEnabled() && lockState != WalletModel::Locked && !syncFlag;
196251
if (ui->checkStaking->isChecked() != stakingStatus) {
197252
fBlockNextStakeCheckSignal = true;
198253
ui->checkStaking->setChecked(stakingStatus);
199-
return;
254+
return;
200255
}
201256
}
202257
}

src/qt/veil/veilstatusbar.h

+5
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,13 @@ private Q_SLOTS:
5252
WalletModel *walletModel = nullptr;
5353
ClientModel *clientModel = nullptr;
5454
UnlockPasswordDialog *unlockPasswordDialog = nullptr;
55+
#ifdef ENABLE_WALLET
56+
void setStakingText();
57+
#endif
5558

5659
bool preparingFlag = false;
60+
bool syncFlag = true;
61+
static const int64_t ACTIVE_STAKING_MAX_TIME = 70;
5762
};
5863

5964
#endif // VEILSTATUSBAR_H

src/wallet/rpcwallet.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -3388,6 +3388,7 @@ static UniValue getwalletinfo(const JSONRPCRequest& request)
33883388
" \"hdseedid\": \"<hash160>\" (string, optional) the Hash160 of the HD seed (only present when HD is enabled)\n"
33893389
" \"hdmasterkeyid\": \"<hash160>\" (string, optional) alias for hdseedid retained for backwards-compatibility. Will be removed in V0.18.\n"
33903390
" \"private_keys_enabled\": true|false (boolean) false if privatekeys are disabled for this wallet (enforced watch-only wallet)\n"
3391+
" \"staking_enabled\" : true|false (boolean) true if staking is enabled\n"
33913392
" \"staking_active\": true|false (boolean) true if wallet is actively trying to create new blocks using proof of stake\n"
33923393
"}\n"
33933394
"\nExamples:\n"
@@ -3426,6 +3427,8 @@ static UniValue getwalletinfo(const JSONRPCRequest& request)
34263427
}
34273428
obj.pushKV("private_keys_enabled", !pwallet->IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS));
34283429

3430+
obj.pushKV("staking_enabled", pwallet->IsStakingEnabled());
3431+
34293432
// Determine if staking is recently active. Note that this is not immediate effect. Staking could be disabled and it could take up to 70 seconds to update state.
34303433
int64_t nTimeLastHashing = 0;
34313434
if (!mapHashedBlocks.empty()) {

0 commit comments

Comments
 (0)