Skip to content
Permalink
Browse files

added staking icon

  • Loading branch information...
Spidersbox committed Jul 2, 2017
1 parent 1ca0662 commit 82e7167f77aa6d59f6ac1920183e5ddf674324df
@@ -127,6 +127,9 @@ extern int64 nWalletUnlockTime;
extern int64 AmountFromValue(const json_spirit::Value& value);
extern json_spirit::Value ValueFromAmount(int64 amount);
extern double GetDifficulty(const CBlockIndex* blockindex = NULL);

extern double GetPoSKernelPS();

extern std::string HexBits(unsigned int nBits);
extern std::string HelpRequiringPassphrase();
extern void EnsureWalletIsUnlocked();
@@ -8,7 +8,7 @@
// These need to be macros, as version.cpp's and bitcoin-qt.rc's voodoo requires it
#define CLIENT_VERSION_MAJOR 2
#define CLIENT_VERSION_MINOR 0
#define CLIENT_VERSION_REVISION 1
#define CLIENT_VERSION_REVISION 2
#define CLIENT_VERSION_BUILD 1

// Converts the parameter X to a string after macro replacement on X has been performed.
@@ -23,6 +23,16 @@ static std::map<int, unsigned int> mapStakeModifierCheckpoints =
( 0, 0xfd11f4e7u )
;

// Get time weight
int64 GetWeight(int64 nIntervalBeginning, int64 nIntervalEnd)
{
// Kernel hash weight starts from 0 at the 30-day min age
// this change increases active coins participating the hash and helps
// to secure the network when proof-of-stake difficulty is low

return min(nIntervalEnd - nIntervalBeginning - GetStakeMinAge(nIntervalEnd), (int64)GetStakeMaxAge(nIntervalEnd));
}

// Get the last stake modifier and its generation time from a given block
static bool GetLastStakeModifier(const CBlockIndex* pindex, uint64& nStakeModifier, int64& nModifierTime)
{
@@ -34,4 +34,7 @@ unsigned int GetStakeModifierChecksum(const CBlockIndex* pindex);
// Check stake modifier hard checkpoints
bool CheckStakeModifierCheckpoints(int nHeight, unsigned int nStakeModifierChecksum);

// Get time weight using supplied timestamps
int64 GetWeight(int64 nIntervalBeginning, int64 nIntervalEnd);

#endif // PPCOIN_KERNEL_H
@@ -973,6 +973,22 @@ int64 GetProofOfStakeReward(int64 nCoinAge, unsigned int nBits, unsigned int nTi
return nSubsidy;
}

unsigned int GetStakeMinAge(unsigned int nTime)
{
// if (nTime > VERSION2_SWITCH_TIME)
// return nStakeMinAgeV2; // 15 days
// else
return nStakeMinAge; //30 days
}

unsigned int GetStakeMaxAge(unsigned int nTime)
{
// if (nTime > VERSION2_SWITCH_TIME)
// return nStakeMaxAgeV2; // 45 days
// else
return nStakeMaxAge; // 90 days
}

static const int64 nTargetTimespan = 60 * 60 * 4; // 4 hours
static const int64 nTargetSpacingWorkMax = 2 * nStakeTargetSpacing;

@@ -114,6 +114,9 @@ bool CheckWork(CBlock* pblock, CWallet& wallet, CReserveKey& reservekey);
bool CheckProofOfWork(uint256 hash, unsigned int nBits);
int64 GetProofOfWorkReward(int nHeight, int64 nFees, uint256 prevHash);
int64 GetProofOfStakeReward(int64 nCoinAge, unsigned int nBits, unsigned int nTime, int nHeight);
unsigned int GetStakeMinAge(unsigned int nTime);
unsigned int GetStakeMaxAge(unsigned int nTime);

unsigned int ComputeMinWork(unsigned int nBase, int64 nTime);
unsigned int ComputeMinStake(unsigned int nBase, int64 nTime, unsigned int nBlockTime);
int GetNumBlocksOfPeers();
@@ -37,6 +37,8 @@
<file alias="lock_closed">res/icons/lock_closed.png</file>
<file alias="lock_open">res/icons/lock_open.png</file>
<file alias="key">res/icons/key.png</file>
<file alias="staking_off">res/icons/staking_off.png</file>
<file alias="staking_on">res/icons/staking_on.png</file>
<file alias="filesave">res/icons/filesave.png</file>
<file alias="qrcode">res/icons/qrcode.png</file>
<file alias="debugwindow">res/icons/debugwindow.png</file>
@@ -25,6 +25,8 @@
#include "notificator.h"
#include "guiutil.h"
#include "rpcconsole.h"
#include "wallet.h"
#include "bitcoinrpc.h"
#include "version.h"

#ifdef Q_OS_MAC
@@ -58,6 +60,11 @@

#include <iostream>

extern CWallet *pwalletMain;
extern int64 nLastCoinStakeSearchInterval;
extern unsigned int nStakeTargetSpacing;
extern bool fWalletUnlockMintOnly;

BitcoinGUI::BitcoinGUI(QWidget *parent):
QMainWindow(parent),
clientModel(0),
@@ -125,22 +132,40 @@ menuBar()->setNativeMenuBar(false);// menubar on form instead
// Status bar notification icons
QFrame *frameBlocks = new QFrame();
frameBlocks->setContentsMargins(0,0,0,0);
frameBlocks->setMinimumWidth(56);
frameBlocks->setMaximumWidth(56);
frameBlocks->setMinimumWidth(85);
frameBlocks->setMaximumWidth(85);
QHBoxLayout *frameBlocksLayout = new QHBoxLayout(frameBlocks);
frameBlocksLayout->setContentsMargins(3,0,3,0);
frameBlocksLayout->setSpacing(3);
labelEncryptionIcon = new QLabel();
labelMintingIcon = new QLabel();
labelConnectionsIcon = new QLabel();
labelBlocksIcon = new QLabel();
frameBlocksLayout->addStretch();
frameBlocksLayout->addWidget(labelEncryptionIcon);
frameBlocksLayout->addStretch();
frameBlocksLayout->addWidget(labelMintingIcon);
frameBlocksLayout->addStretch();
frameBlocksLayout->addWidget(labelConnectionsIcon);
frameBlocksLayout->addStretch();
frameBlocksLayout->addWidget(labelBlocksIcon);
frameBlocksLayout->addStretch();

// Set minting pixmap
labelMintingIcon->setPixmap(QIcon(":/icons/staking_on").pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
labelMintingIcon->setEnabled(false);
// Add timer to update minting icon
QTimer *timerMintingIcon = new QTimer(labelMintingIcon);
timerMintingIcon->start(MODEL_UPDATE_DELAY);
connect(timerMintingIcon, SIGNAL(timeout()), this, SLOT(updateMintingIcon()));
// Add timer to update minting weights
QTimer *timerMintingWeights = new QTimer(labelMintingIcon);
timerMintingWeights->start(30 * 1000);
connect(timerMintingWeights, SIGNAL(timeout()), this, SLOT(updateMintingWeights()));
// Set initial values for user and network weights
nWeight=0;
nNetworkWeight = 0;

// Progress bar and label for blocks download
progressBarLabel = new QLabel();
progressBarLabel->setVisible(false);
@@ -253,6 +278,7 @@ void BitcoinGUI::createActions()
encryptWalletAction = new QAction(QIcon(":/icons/lock_closed"), tr("&Encrypt Wallet..."), this);
encryptWalletAction->setToolTip(tr("Encrypt or decrypt wallet"));
encryptWalletAction->setCheckable(true);

backupWalletAction = new QAction(QIcon(":/icons/filesave"), tr("&Backup Wallet..."), this);
backupWalletAction->setToolTip(tr("Backup wallet to another location"));
changePassphraseAction = new QAction(QIcon(":/icons/key"), tr("&Change Passphrase..."), this);
@@ -882,3 +908,63 @@ void BitcoinGUI::toggleHidden()
{
showNormalIfMinimized(true);
}

void BitcoinGUI::updateMintingIcon()
{
if (!walletModel)
return;

labelMintingIcon->setEnabled(false);
// labelStakingIcon->setPixmap(QIcon(":/icons/staking_off").pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));

if (!clientModel->getNumConnections())
labelMintingIcon->setToolTip(tr("Not staking because wallet is offline"));
else if (clientModel->inInitialBlockDownload() ||
clientModel->getNumBlocks() < clientModel->getNumBlocksOfPeers())
labelMintingIcon->setToolTip(tr("Not staking because wallet is syncing"));
else if(walletModel->getEncryptionStatus() == WalletModel::Locked)
labelMintingIcon->setToolTip(tr("Not staking because wallet is locked"));
else
{
uint64 nMinWeight = 0, nMaxWeight = 0, nWeight = 0;

walletModel->getStakeWeight(nMinWeight,nMaxWeight,nWeight);
if (!nWeight)
labelMintingIcon->setToolTip(tr("Not staking because you don't have mature coins"));
else
{
uint64 nNetworkWeight = clientModel->getPosKernalPS();
int nEstimateTime = clientModel->getStakeTargetSpacing() * 10 * nNetworkWeight / nWeight;
QString text;
if (nEstimateTime < 60)
text = tr("%n second(s)", "", nEstimateTime);
else if (nEstimateTime < 60*60)
text = tr("%n minute(s)", "", nEstimateTime/60);
else if (nEstimateTime < 24*60*60)
text = tr("%n hour(s)", "", nEstimateTime/(60*60));
else
text = tr("%n day(s)", "", nEstimateTime/(60*60*24));

labelMintingIcon->setEnabled(true);
// labelStakingIcon->setPixmap(QIcon(":/icons/staking_on").pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
labelMintingIcon->setToolTip(tr("Staking.\n Your weight is %1\n Network weight is %2\n You have 50\% chance of producing a stake within %3").arg(nWeight).arg(nNetworkWeight).arg(text));
}
}



}

void BitcoinGUI::updateMintingWeights()
{
// Only update if we have the network's current number of blocks, or weight(s) are zero (fixes lagging GUI)
if ((clientModel && clientModel->getNumBlocks() == clientModel->getNumBlocksOfPeers()) || !nWeight || !nNetworkWeight)
{
nWeight = 0;

if (pwalletMain)
pwalletMain->GetStakeWeight(*pwalletMain, nMinMax, nMinMax, nWeight);

nNetworkWeight = GetPoSKernelPS();
}
}
@@ -4,6 +4,8 @@
#include <QMainWindow>
#include <QSystemTrayIcon>

#include "util.h" // for uint64

class TransactionTableModel;
class ClientModel;
class WalletModel;
@@ -67,6 +69,7 @@ class BitcoinGUI : public QMainWindow
SignVerifyMessageDialog *signVerifyMessageDialog;

QLabel *labelEncryptionIcon;
QLabel *labelMintingIcon;
QLabel *labelConnectionsIcon;
QLabel *labelBlocksIcon;
QLabel *progressBarLabel;
@@ -98,6 +101,10 @@ class BitcoinGUI : public QMainWindow

QMovie *syncIconMovie;

uint64 nMinMax;
uint64 nWeight;
uint64 nNetworkWeight;

/** Create the main UI actions. */
void createActions();
/** Create the menu bar and sub-menus. */
@@ -174,6 +181,11 @@ private slots:
void showNormalIfMinimized(bool fToggleHidden = false);
/** simply calls showNormalIfMinimized(true) for use in SLOT() macro */
void toggleHidden();

/** Update info about minting */
void updateMintingIcon();
/** Update minting weight info */
void updateMintingWeights();
};

#endif
@@ -12,6 +12,8 @@
#include <QTimer>

static const int64 nClientStartupTime = GetTime();
double GetPoSKernelPS(const CBlockIndex* blockindex = NULL);
extern unsigned int nStakeTargetSpacing;

ClientModel::ClientModel(OptionsModel *optionsModel, QObject *parent) :
QObject(parent), optionsModel(optionsModel),
@@ -32,6 +34,16 @@ ClientModel::~ClientModel()
unsubscribeFromCoreSignals();
}

double ClientModel::getPosKernalPS()
{
return GetPoSKernelPS();
}

int ClientModel::getStakeTargetSpacing()
{
return nStakeTargetSpacing;
}

int ClientModel::getNumConnections() const
{
return vNodes.size();
@@ -26,6 +26,8 @@ class ClientModel : public QObject
int getNumConnections() const;
int getNumBlocks() const;
int getNumBlocksAtStartup();
double getPosKernalPS();
int getStakeTargetSpacing();

QDateTime getLastBlockDate() const;

Binary file not shown.
Binary file not shown.
@@ -310,6 +310,11 @@ bool WalletModel::backupWallet(const QString &filename)
return BackupWallet(*wallet, filename.toLocal8Bit().data());
}

void WalletModel::getStakeWeight(uint64& nMinWeight, uint64& nMaxWeight, uint64& nWeight )
{
wallet->GetStakeWeight(*wallet, nMinWeight, nMaxWeight, nWeight);
}

// Handlers for core signals
static void NotifyKeyStoreStatusChanged(WalletModel *walletmodel, CCryptoKeyStore *wallet)
{
@@ -453,4 +458,4 @@ void WalletModel::UnlockContext::CopyFrom(const UnlockContext& rhs)
void WalletModel::listLockedCoins(std::vector<COutPoint>& vOutpts)
{
return;
}
}
@@ -94,6 +94,8 @@ class WalletModel : public QObject
bool changePassphrase(const SecureString &oldPass, const SecureString &newPass);
// Wallet backup
bool backupWallet(const QString &filename);
//PoS Information
void getStakeWeight(quint64& nMinWeight, quint64& nMaxWeight, quint64& nWeight);

// RAI object for unlocking wallet, returned by requestUnlock()
class UnlockContext
@@ -43,6 +43,61 @@ double GetDifficulty(const CBlockIndex* blockindex)
}


double GetPoSKernelPS()
{
int nPoSInterval = 72;
double dStakeKernelsTriedAvg = 0;
int nStakesHandled = 0, nStakesTime = 0;

CBlockIndex* pindex = pindexBest;;
CBlockIndex* pindexPrevStake = NULL;

while (pindex && nStakesHandled < nPoSInterval)
{
if (pindex->IsProofOfStake())
{
dStakeKernelsTriedAvg += GetDifficulty(pindex) * 4294967296.0;
nStakesTime += pindexPrevStake ? (pindexPrevStake->nTime - pindex->nTime) : 0;
pindexPrevStake = pindex;
nStakesHandled++;
}

pindex = pindex->pprev;
}

return nStakesTime ? dStakeKernelsTriedAvg / nStakesTime : 0;
}

double GetPoSKernelPS(const CBlockIndex* blockindex)
{
int nPoSInterval = 72;
double dStakeKernelsTriedAvg = 0;
int nStakesHandled = 0, nStakesTime = 0;

const CBlockIndex* pindex = pindexBest;
const CBlockIndex* pindexPrevStake = NULL;

if (blockindex != NULL)
pindex = blockindex;


while (pindex && nStakesHandled < nPoSInterval)
{
if (pindex->IsProofOfStake())
{
dStakeKernelsTriedAvg += GetDifficulty(pindex) * 4294967296.0;
nStakesTime += pindexPrevStake ? (pindexPrevStake->nTime - pindex->nTime) : 0;
pindexPrevStake = pindex;
nStakesHandled++;
}

pindex = pindex->pprev;
}

return dStakeKernelsTriedAvg / nStakesTime;
}


Object blockToJSON(const CBlock& block, const CBlockIndex* blockindex, bool fPrintTransactionDetail)
{
Object result;
@@ -46,7 +46,7 @@ static const int MEMPOOL_GD_VERSION = 60002;

#define DISPLAY_VERSION_MAJOR 2
#define DISPLAY_VERSION_MINOR 0
#define DISPLAY_VERSION_REVISION 1
#define DISPLAY_VERSION_REVISION 2
#define DISPLAY_VERSION_BUILD 1

#endif

0 comments on commit 82e7167

Please sign in to comment.
You can’t perform that action at this time.