Skip to content

Commit

Permalink
PoS GUI
Browse files Browse the repository at this point in the history
  • Loading branch information
Bushstar committed Oct 21, 2018
1 parent 1ad3635 commit 5955faa
Show file tree
Hide file tree
Showing 25 changed files with 1,290 additions and 517 deletions.
1 change: 1 addition & 0 deletions src/net.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ bool BindListenPort(const CService &bindAddr, std::string& strError, bool fWhite
void StartNode(boost::thread_group& threadGroup, CScheduler& scheduler);
bool StopNode();
void SocketSendData(CNode *pnode);
double GetPoSKernelPS();

struct CombinerAll
{
Expand Down
16 changes: 16 additions & 0 deletions src/qt/askpassphrasedialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
#include <QMessageBox>
#include <QPushButton>

extern bool fWalletUnlockStakingOnly;

AskPassphraseDialog::AskPassphraseDialog(Mode mode, QWidget *parent) :
QDialog(parent),
ui(new Ui::AskPassphraseDialog),
Expand All @@ -35,6 +37,8 @@ AskPassphraseDialog::AskPassphraseDialog(Mode mode, QWidget *parent) :
ui->passEdit2->setMaxLength(MAX_PASSPHRASE_SIZE);
ui->passEdit3->setMaxLength(MAX_PASSPHRASE_SIZE);

ui->stakingCheckBox->setChecked(fWalletUnlockStakingOnly);

// Setup Caps Lock detection.
ui->passEdit1->installEventFilter(this);
ui->passEdit2->installEventFilter(this);
Expand All @@ -56,6 +60,15 @@ AskPassphraseDialog::AskPassphraseDialog(Mode mode, QWidget *parent) :
ui->passEdit3->hide();
setWindowTitle(tr("Unlock wallet"));
break;
case UnlockStaking:
ui->warningLabel->setText(tr("This operation needs your wallet passphrase to unlock the wallet."));
ui->passLabel2->hide();
ui->passEdit2->hide();
ui->passLabel3->hide();
ui->passEdit3->hide();
ui->stakingCheckBox->setChecked(true);
setWindowTitle(tr("Unlock wallet for staking"));
break;
case Decrypt: // Ask passphrase
ui->warningLabel->setText(tr("This operation needs your wallet passphrase to decrypt the wallet."));
ui->passLabel2->hide();
Expand Down Expand Up @@ -151,6 +164,7 @@ void AskPassphraseDialog::accept()
QDialog::reject(); // Cancelled
}
} break;
case UnlockStaking:
case Unlock:
if(!model->setWalletLocked(false, oldpass))
{
Expand All @@ -159,6 +173,7 @@ void AskPassphraseDialog::accept()
}
else
{
fWalletUnlockStakingOnly = ui->stakingCheckBox->isChecked();
QDialog::accept(); // Success
}
break;
Expand Down Expand Up @@ -207,6 +222,7 @@ void AskPassphraseDialog::textChanged()
acceptable = !ui->passEdit2->text().isEmpty() && !ui->passEdit3->text().isEmpty();
break;
case Unlock: // Old passphrase x1
case UnlockStaking:
case Decrypt:
acceptable = !ui->passEdit1->text().isEmpty();
break;
Expand Down
1 change: 1 addition & 0 deletions src/qt/askpassphrasedialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class AskPassphraseDialog : public QDialog
enum Mode {
Encrypt, /**< Ask passphrase twice and encrypt */
Unlock, /**< Ask passphrase and unlock */
UnlockStaking, /**< Ask passphrase and unlock */
ChangePass, /**< Ask old passphrase + new passphrase twice */
Decrypt /**< Ask passphrase and decrypt wallet */
};
Expand Down
165 changes: 163 additions & 2 deletions src/qt/bitcoingui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "clientmodel.h"
#include "guiconstants.h"
#include "guiutil.h"
#include "net.h"
#include "networkstyle.h"
#include "notificator.h"
#include "openuridialog.h"
Expand All @@ -20,17 +21,23 @@
#include "platformstyle.h"
#include "rpcconsole.h"
#include "utilitydialog.h"
#include "walletmodel.h"
#include "wallet/rpcwallet.h"

#ifdef ENABLE_WALLET
#include "walletframe.h"
#include "walletmodel.h"
#include "walletview.h"
#include "wallet/wallet.h"
#endif // ENABLE_WALLET

#ifdef Q_OS_MAC
#include "macdockiconhandler.h"
#endif

#include "chainparams.h"
#include "init.h"
#include "miner.h"
#include "ui_interface.h"
#include "util.h"

Expand All @@ -40,13 +47,16 @@
#include <QApplication>
#include <QDateTime>
#include <QDesktopWidget>
#include <QDir>
#include <QDragEnterEvent>
#include <QInputDialog>
#include <QListWidget>
#include <QMenuBar>
#include <QMessageBox>
#include <QMimeData>
#include <QProgressBar>
#include <QProgressDialog>
#include <QPushButton>
#include <QSettings>
#include <QShortcut>
#include <QStackedWidget>
Expand All @@ -55,6 +65,18 @@
#include <QTimer>
#include <QToolBar>
#include <QVBoxLayout>
#include <QWidget>
#include <QNetworkAccessManager>
#include <QNetworkRequest>
#include <QNetworkReply>
#include <QUrl>
#include <QUrlQuery>
#include <QVariant>
#include <QJsonValue>
#include <QJsonDocument>
#include <QJsonObject>
#include <QVariantMap>
#include <QJsonArray>

#if QT_VERSION < 0x050000
#include <QTextDocument>
Expand Down Expand Up @@ -83,6 +105,8 @@ BitcoinGUI::BitcoinGUI(const PlatformStyle *platformStyle, const NetworkStyle *n
labelEncryptionIcon(0),
labelConnectionsIcon(0),
labelBlocksIcon(0),
labelStakingIcon(0),
labelPrice(0),
progressBarLabel(0),
progressBar(0),
progressDialog(0),
Expand Down Expand Up @@ -115,9 +139,12 @@ BitcoinGUI::BitcoinGUI(const PlatformStyle *platformStyle, const NetworkStyle *n
helpMessageDialog(0),
prevBlocks(0),
spinnerFrame(0),
unlockWalletAction(0),
lockWalletAction(0),
toggleStakingAction(0),
platformStyle(platformStyle)
{
GUIUtil::restoreWindowGeometry("nWindow", QSize(850, 550), this);
GUIUtil::restoreWindowGeometry("nWindow", QSize(840, 600), this);

QString windowTitle = tr(PACKAGE_NAME) + " - ";
#ifdef ENABLE_WALLET
Expand Down Expand Up @@ -195,10 +222,16 @@ BitcoinGUI::BitcoinGUI(const PlatformStyle *platformStyle, const NetworkStyle *n
frameBlocksLayout->setSpacing(3);
unitDisplayControl = new UnitDisplayStatusBarControl(platformStyle);
labelEncryptionIcon = new QLabel();
labelStakingIcon = new QLabel();
labelPrice = new QLabel();
labelConnectionsIcon = new QLabel();
labelBlocksIcon = new QLabel();
if(enableWallet)
{
frameBlocksLayout->addStretch();
frameBlocksLayout->addWidget(labelStakingIcon);
frameBlocksLayout->addStretch();
frameBlocksLayout->addWidget(labelPrice);
frameBlocksLayout->addStretch();
frameBlocksLayout->addWidget(unitDisplayControl);
frameBlocksLayout->addStretch();
Expand All @@ -210,6 +243,18 @@ BitcoinGUI::BitcoinGUI(const PlatformStyle *platformStyle, const NetworkStyle *n
frameBlocksLayout->addWidget(labelBlocksIcon);
frameBlocksLayout->addStretch();

if (GetBoolArg("-staking", true))
{
QTimer *timerStakingIcon = new QTimer(labelStakingIcon);
connect(timerStakingIcon, SIGNAL(timeout()), this, SLOT(updateStakingStatus()));
timerStakingIcon->start(150 * 1000);
updateStakingStatus();
}
else
{
walletFrame->setStakingStatus(tr("Staking is turned off."));
}

// Progress bar and label for blocks download
progressBarLabel = new QLabel();
progressBarLabel->setVisible(false);
Expand Down Expand Up @@ -289,6 +334,9 @@ void BitcoinGUI::createActions()
receiveCoinsMenuAction->setStatusTip(receiveCoinsAction->statusTip());
receiveCoinsMenuAction->setToolTip(receiveCoinsMenuAction->statusTip());

toggleStakingAction = new QAction(tr("Toggle &Staking"), this);
toggleStakingAction->setStatusTip(tr("Toggle Staking"));

historyAction = new QAction(platformStyle->SingleColorIcon(":/icons/history"), tr("&Transactions"), this);
historyAction->setStatusTip(tr("Browse transaction history"));
historyAction->setToolTip(historyAction->statusTip());
Expand All @@ -311,6 +359,7 @@ void BitcoinGUI::createActions()
connect(receiveCoinsMenuAction, SIGNAL(triggered()), this, SLOT(gotoReceiveCoinsPage()));
connect(historyAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
connect(historyAction, SIGNAL(triggered()), this, SLOT(gotoHistoryPage()));
connect(toggleStakingAction, SIGNAL(triggered()), this, SLOT(toggleStaking()));
#endif // ENABLE_WALLET

quitAction = new QAction(platformStyle->TextColorIcon(":/icons/quit"), tr("E&xit"), this);
Expand All @@ -334,6 +383,8 @@ void BitcoinGUI::createActions()
encryptWalletAction = new QAction(platformStyle->TextColorIcon(":/icons/lock_closed"), tr("&Encrypt Wallet..."), this);
encryptWalletAction->setStatusTip(tr("Encrypt the private keys that belong to your wallet"));
encryptWalletAction->setCheckable(true);
unlockWalletAction = new QAction(tr("&Unlock Wallet for Staking..."), this);
unlockWalletAction->setToolTip(tr("Unlock wallet for Staking"));
backupWalletAction = new QAction(platformStyle->TextColorIcon(":/icons/filesave"), tr("&Backup Wallet..."), this);
backupWalletAction->setStatusTip(tr("Backup wallet to another location"));
changePassphraseAction = new QAction(platformStyle->TextColorIcon(":/icons/key"), tr("&Change Passphrase..."), this);
Expand Down Expand Up @@ -374,6 +425,7 @@ void BitcoinGUI::createActions()
if(walletFrame)
{
connect(encryptWalletAction, SIGNAL(triggered(bool)), walletFrame, SLOT(encryptWallet(bool)));
connect(unlockWalletAction, SIGNAL(triggered()), walletFrame, SLOT(unlockWalletStaking()));
connect(backupWalletAction, SIGNAL(triggered()), walletFrame, SLOT(backupWallet()));
connect(changePassphraseAction, SIGNAL(triggered()), walletFrame, SLOT(changePassphrase()));
connect(signMessageAction, SIGNAL(triggered()), this, SLOT(gotoSignMessageTab()));
Expand Down Expand Up @@ -409,16 +461,18 @@ void BitcoinGUI::createMenuBar()
file->addSeparator();
file->addAction(usedSendingAddressesAction);
file->addAction(usedReceivingAddressesAction);
file->addSeparator();
}
file->addAction(quitAction);

QMenu *settings = appMenuBar->addMenu(tr("&Settings"));
if(walletFrame)
{
settings->addAction(encryptWalletAction);
settings->addAction(unlockWalletAction);
settings->addAction(changePassphraseAction);
settings->addSeparator();
settings->addAction(toggleStakingAction);
settings->addSeparator();
}
settings->addAction(optionsAction);

Expand Down Expand Up @@ -999,31 +1053,54 @@ bool BitcoinGUI::handlePaymentRequest(const SendCoinsRecipient& recipient)

void BitcoinGUI::setEncryptionStatus(int status)
{
if(fWalletUnlockStakingOnly)
{
labelEncryptionIcon->setPixmap(QIcon(":/icons/lock_closed").pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
labelEncryptionIcon->setToolTip(tr("Wallet is <b>encrypted</b> and currently <b>unlocked for staking only</b>"));
changePassphraseAction->setEnabled(false);
unlockWalletAction->setVisible(false);
encryptWalletAction->setEnabled(false);
if(walletFrame)
walletFrame->showLockStaking(false);
}
else
{
switch(status)
{
case WalletModel::Unencrypted:
labelEncryptionIcon->hide();
encryptWalletAction->setChecked(false);
changePassphraseAction->setEnabled(false);
encryptWalletAction->setEnabled(true);
unlockWalletAction->setVisible(false);
if(walletFrame)
walletFrame->showLockStaking(false);
break;
case WalletModel::Unlocked:
labelEncryptionIcon->show();
labelEncryptionIcon->setPixmap(platformStyle->SingleColorIcon(":/icons/lock_open").pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
labelEncryptionIcon->setToolTip(tr("Wallet is <b>encrypted</b> and currently <b>unlocked</b>"));
unlockWalletAction->setVisible(false);
encryptWalletAction->setChecked(true);
changePassphraseAction->setEnabled(true);
encryptWalletAction->setEnabled(false); // TODO: decrypt currently not supported
if(walletFrame)
walletFrame->showLockStaking(false);
break;
case WalletModel::Locked:
labelEncryptionIcon->show();
labelEncryptionIcon->setPixmap(platformStyle->SingleColorIcon(":/icons/lock_closed").pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
labelEncryptionIcon->setToolTip(tr("Wallet is <b>encrypted</b> and currently <b>locked</b>"));
encryptWalletAction->setChecked(true);
changePassphraseAction->setEnabled(true);
unlockWalletAction->setVisible(true);
encryptWalletAction->setEnabled(false); // TODO: decrypt currently not supported
if(walletFrame)
walletFrame->showLockStaking(true);
break;
}
}
updateStakingStatus();
}
#endif // ENABLE_WALLET

Expand Down Expand Up @@ -1202,3 +1279,87 @@ void UnitDisplayStatusBarControl::onMenuSelection(QAction* action)
optionsModel->setDisplayUnit(action->data());
}
}

void BitcoinGUI::toggleStaking()
{
SetStaking(!GetStaking());

Q_EMIT message(tr("Staking"), GetStaking() ? tr("Staking has been enabled") : tr("Staking has been disabled"),
CClientUIInterface::MSG_INFORMATION);
}

#ifdef ENABLE_WALLET
void BitcoinGUI::updateWeight()
{
if (!pwalletMain)
return;

TRY_LOCK(cs_main, lockMain);
if (!lockMain)
return;

TRY_LOCK(pwalletMain->cs_wallet, lockWallet);
if (!lockWallet)
return;

uint64_t nMinWeight = 0, nMaxWeight = 0;
pwalletMain->GetStakeWeight(nMinWeight, nMaxWeight, this->nWeight);
}

void BitcoinGUI::updateStakingStatus()
{
updateWeight();

if(walletFrame){
if (!GetBoolArg("-staking",true))
{
walletFrame->setStakingStatus(tr("Staking is turned off."));
walletFrame->showLockStaking(false);
}
else if (nLastCoinStakeSearchInterval && nWeight)
{

uint64_t nWeight = this->nWeight;
uint64_t nNetworkWeight = GetPoSKernelPS();
int nBestHeight = pindexBestHeader->nHeight;

unsigned nEstimateTime = Params().GetConsensus().nPowTargetSpacing * nNetworkWeight / nWeight;

QString text;
if (nEstimateTime > 60)
{
if (nEstimateTime < 60*60)
{
text = tr("Expected time to earn reward is %n minute(s)", "", nEstimateTime/60);
}
else if (nEstimateTime < 24*60*60)
{
text = tr("Expected time to earn reward is %n hour(s)", "", nEstimateTime/(60*60));
}
else
{
text = tr("Expected time to earn reward is %n day(s)", "", nEstimateTime/(60*60*24));
}
}

nWeight /= COIN;
nNetworkWeight /= COIN;

walletFrame->setStakingStatus(text!=""?text:tr("You are staking"));
}
else
{
if (pwalletMain && pwalletMain->IsLocked())
walletFrame->setStakingStatus(tr("Not staking - Wallet locked"));
else if (vNodes.empty())
walletFrame->setStakingStatus(tr("Not staking - Wallet offline"));
else if (IsInitialBlockDownload())
walletFrame->setStakingStatus(tr("Not staking - Wallet syncing"));
else if (!nWeight)
walletFrame->setStakingStatus(tr("Not staking - Immature coins"));
else
walletFrame->setStakingStatus(tr("Not staking - Please wait"));
}
}
}
#endif
Loading

0 comments on commit 5955faa

Please sign in to comment.