diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp
index 5b16ad00f6..2f808295de 100644
--- a/src/qt/bitcoingui.cpp
+++ b/src/qt/bitcoingui.cpp
@@ -988,6 +988,8 @@ void BitcoinGUI::setNumBlocks(int count, const QDateTime& blockDate, double nVer
tooltip += tr("Transactions after this will not yet be visible.");
}
+ veilStatusBar->updateStakingCheckbox();
+
// Don't word-wrap this (fixed-width) tooltip
tooltip = QString("") + tooltip + QString("");
diff --git a/src/qt/veil/veilstatusbar.cpp b/src/qt/veil/veilstatusbar.cpp
index 81e518c117..6c1a1ae571 100644
--- a/src/qt/veil/veilstatusbar.cpp
+++ b/src/qt/veil/veilstatusbar.cpp
@@ -10,6 +10,7 @@
#include
#include
#include
+#include
#ifdef ENABLE_WALLET
#include // For DEFAULT_DISABLE_WALLET
#endif
@@ -51,6 +52,7 @@ void VeilStatusBar::updateSyncIndicator(int height){
void VeilStatusBar::setSyncStatusVisible(bool fVisible) {
ui->btnSync->setVisible(fVisible);
+ syncFlag = fVisible;
}
void VeilStatusBar::onBtnSyncClicked(){
@@ -59,6 +61,52 @@ void VeilStatusBar::onBtnSyncClicked(){
#ifdef ENABLE_WALLET
bool fBlockNextStakeCheckSignal = false;
+void VeilStatusBar::setStakingText() {
+
+ // 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.
+ int64_t nTimeLastHashing = 0;
+ if (!mapHashedBlocks.empty()) {
+ auto pindexBest = chainActive.Tip();
+ if (mapHashedBlocks.count(pindexBest->GetBlockHash())) {
+ nTimeLastHashing = mapHashedBlocks.at(pindexBest->GetBlockHash());
+ } else if (mapHashedBlocks.count(pindexBest->pprev->GetBlockHash())) {
+ nTimeLastHashing = mapHashedBlocks.at(pindexBest->pprev->GetBlockHash());
+ }
+ }
+ bool fStakingActive = false;
+ if (nTimeLastHashing)
+ fStakingActive = GetAdjustedTime() + MAX_FUTURE_BLOCK_TIME - nTimeLastHashing < ACTIVE_STAKING_MAX_TIME;
+
+ WalletModel::EncryptionStatus eStatus = this->walletModel->getEncryptionStatus();
+
+ if (syncFlag){
+ ui->checkStaking->setText("Staking Disabled while Syncing");
+ }else if (WalletModel::Locked == eStatus) {
+ ui->checkStaking->setText("Unlock wallet for Staking");
+ }else if (this->walletModel->isStakingEnabled()) {
+ if (fStakingActive) {
+ ui->checkStaking->setText("Staking Enabled");
+ }else{
+
+ interfaces::Wallet& wallet = walletModel->wallet();
+ interfaces::WalletBalances balances = wallet.getBalances();
+ int64_t zerocoin_balance = balances.zerocoin_balance;
+
+ if (0.0 < zerocoin_balance) {
+ ui->checkStaking->setText("Enabling...");
+ }else{
+ ui->checkStaking->setText("You need some zerocoin");
+ }
+ }
+ }else{
+ if (fStakingActive) {
+ ui->checkStaking->setText("Disabling...");
+ }else{
+ ui->checkStaking->setText("Staking Disabled");
+ }
+ }
+}
+
void VeilStatusBar::onCheckStakingClicked(bool res) {
if (gArgs.GetBoolArg("-disablewallet", DEFAULT_DISABLE_WALLET))
return;
@@ -77,16 +125,19 @@ void VeilStatusBar::onCheckStakingClicked(bool res) {
openToastDialog(dialogMsg, mainWindow);
fBlockNextStakeCheckSignal = true;
ui->checkStaking->setChecked(false);
+ setStakingText();
return;
}else{
this->walletModel->setStakingEnabled(true);
mainWindow->updateWalletStatus();
openToastDialog("Staking enabled", mainWindow);
+ setStakingText();
}
} else {
this->walletModel->setStakingEnabled(false);
mainWindow->updateWalletStatus();
- openToastDialog("Staking disabled", mainWindow);
+ openToastDialog("Staking disabled - this may a few minutes", mainWindow);
+ setStakingText();
}
}
@@ -192,11 +243,15 @@ void VeilStatusBar::updateStakingCheckbox()
if(walletModel) {
WalletModel::EncryptionStatus lockState = walletModel->getEncryptionStatus();
- bool stakingStatus = walletModel->isStakingEnabled() && lockState != WalletModel::Locked;
+
+ ui->checkStaking->setEnabled(!syncFlag);
+ setStakingText();
+
+ bool stakingStatus = walletModel->isStakingEnabled() && lockState != WalletModel::Locked && !syncFlag;
if (ui->checkStaking->isChecked() != stakingStatus) {
fBlockNextStakeCheckSignal = true;
ui->checkStaking->setChecked(stakingStatus);
- return;
+ return;
}
}
}
diff --git a/src/qt/veil/veilstatusbar.h b/src/qt/veil/veilstatusbar.h
index 6b12dfc1f5..bc9141aa14 100644
--- a/src/qt/veil/veilstatusbar.h
+++ b/src/qt/veil/veilstatusbar.h
@@ -52,8 +52,13 @@ private Q_SLOTS:
WalletModel *walletModel = nullptr;
ClientModel *clientModel = nullptr;
UnlockPasswordDialog *unlockPasswordDialog = nullptr;
+#ifdef ENABLE_WALLET
+ void setStakingText();
+#endif
bool preparingFlag = false;
+ bool syncFlag = true;
+ static const int64_t ACTIVE_STAKING_MAX_TIME = 70;
};
#endif // VEILSTATUSBAR_H
diff --git a/src/veil/mnemonic/mnemonicwalletinit.cpp b/src/veil/mnemonic/mnemonicwalletinit.cpp
index 78ccb1bbd0..f0ebe8e9a7 100644
--- a/src/veil/mnemonic/mnemonicwalletinit.cpp
+++ b/src/veil/mnemonic/mnemonicwalletinit.cpp
@@ -73,7 +73,7 @@ bool MnemonicWalletInit::Open() const
return false;
}
- if (gArgs.GetBoolArg("-exchangesandservicesmode", false))
+ if (gArgs.GetBoolArg("-exchangesandservicesmode", false) || !gArgs.GetBoolArg("-staking",true))
pwallet->SetStakingEnabled(false);
AddWallet(pwallet);
diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp
index 7d52ce8dc1..139ca31fcf 100644
--- a/src/wallet/rpcwallet.cpp
+++ b/src/wallet/rpcwallet.cpp
@@ -3388,6 +3388,7 @@ static UniValue getwalletinfo(const JSONRPCRequest& request)
" \"hdseedid\": \"\" (string, optional) the Hash160 of the HD seed (only present when HD is enabled)\n"
" \"hdmasterkeyid\": \"\" (string, optional) alias for hdseedid retained for backwards-compatibility. Will be removed in V0.18.\n"
" \"private_keys_enabled\": true|false (boolean) false if privatekeys are disabled for this wallet (enforced watch-only wallet)\n"
+ " \"staking_enabled\" : true|false (boolean) true if staking is enabled\n"
" \"staking_active\": true|false (boolean) true if wallet is actively trying to create new blocks using proof of stake\n"
"}\n"
"\nExamples:\n"
@@ -3426,6 +3427,8 @@ static UniValue getwalletinfo(const JSONRPCRequest& request)
}
obj.pushKV("private_keys_enabled", !pwallet->IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS));
+ obj.pushKV("staking_enabled", pwallet->IsStakingEnabled());
+
// 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.
int64_t nTimeLastHashing = 0;
if (!mapHashedBlocks.empty()) {