Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GUI] Update Staking Slider to be reflective of status #880

Merged
merged 1 commit into from
Dec 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/qt/bitcoingui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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("<nobr>") + tooltip + QString("</nobr>");

Expand Down
61 changes: 58 additions & 3 deletions src/qt/veil/veilstatusbar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <qt/walletmodel.h>
#include <qt/veil/qtutils.h>
#include <iostream>
#include <timedata.h>
#ifdef ENABLE_WALLET
#include <wallet/wallet.h> // For DEFAULT_DISABLE_WALLET
#endif
Expand Down Expand Up @@ -51,6 +52,7 @@ void VeilStatusBar::updateSyncIndicator(int height){

void VeilStatusBar::setSyncStatusVisible(bool fVisible) {
ui->btnSync->setVisible(fVisible);
syncFlag = fVisible;
}

void VeilStatusBar::onBtnSyncClicked(){
Expand All @@ -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;
Expand All @@ -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();
}

}
Expand Down Expand Up @@ -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;
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions src/qt/veil/veilstatusbar.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion src/veil/mnemonic/mnemonicwalletinit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions src/wallet/rpcwallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3388,6 +3388,7 @@ static UniValue getwalletinfo(const JSONRPCRequest& request)
" \"hdseedid\": \"<hash160>\" (string, optional) the Hash160 of the HD seed (only present when HD is enabled)\n"
" \"hdmasterkeyid\": \"<hash160>\" (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"
Expand Down Expand Up @@ -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()) {
Expand Down