Merge pull request #58 from fsb4000/columnPoSReward
authorCryptoManiac <CryptoManiac@users.noreply.github.com>
Thu, 27 Nov 2014 18:03:35 +0000 (21:03 +0300)
committerCryptoManiac <CryptoManiac@users.noreply.github.com>
Thu, 27 Nov 2014 18:03:35 +0000 (21:03 +0300)
columnPoSReward

src/kernelrecord.cpp
src/kernelrecord.h
src/qt/bitcoingui.cpp
src/qt/guiconstants.h
src/qt/locale/bitcoin_ru.ts
src/qt/mintingtablemodel.cpp
src/qt/mintingtablemodel.h
src/qt/mintingview.cpp
src/qt/mintingview.h
src/wallet.cpp

index 54f71e9..3121845 100644 (file)
@@ -2,7 +2,7 @@
 
 #include "wallet.h"
 #include "base58.h"
-#include "main.h"
+
 
 using namespace std;
 
@@ -75,6 +75,27 @@ int64 KernelRecord::getAge() const
     return (GetAdjustedTime() - nTime) / 86400;
 }
 
+uint64 KernelRecord::getCoinDay() const
+{
+    int64 nWeight = GetAdjustedTime() - nTime - nStakeMinAge;
+    if( nWeight <  0)
+        return 0;
+    nWeight = min(nWeight, (int64)nStakeMaxAge);
+    uint64 coinAge = (nValue * nWeight ) / (COIN * 86400);
+    return coinAge;
+}
+
+int64 KernelRecord::getPoSReward(int nBits, int minutes)
+{
+    double PoSReward;
+    int64 nWeight = GetAdjustedTime() - nTime + minutes * 60;
+    if( nWeight <  nStakeMinAge)
+        return 0;
+    uint64 coinAge = (nValue * nWeight ) / (COIN * 86400);
+    PoSReward = GetProofOfStakeReward(coinAge, nBits, GetAdjustedTime() + minutes * 60);
+    return PoSReward;
+}
+
 double KernelRecord::getProbToMintStake(double difficulty, int timeOffset) const
 {
     //double maxTarget = pow(static_cast<double>(2), 224);
index d54e551..fce7b24 100644 (file)
@@ -41,8 +41,10 @@ public:
 
     std::string getTxID();
     int64 getAge() const;
+    uint64 getCoinDay() const;
     double getProbToMintStake(double difficulty, int timeOffset = 0) const;
     double getProbToMintWithinNMinutes(double difficulty, int minutes);
+    int64 getPoSReward(int nBits, int timeOffset);
 protected:
     int prevMinutes;
     double prevDifficulty;
index 2bf2b6c..67d724c 100644 (file)
@@ -385,6 +385,8 @@ void BitcoinGUI::createToolBars()
     QToolBar *toolbar2 = addToolBar(tr("Actions toolbar"));
     toolbar2->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
     toolbar2->addAction(exportAction);
+    toolbar2->setVisible(false);
+    
 }
 
 void BitcoinGUI::setClientModel(ClientModel *clientModel)
index da18c83..6149553 100644 (file)
@@ -32,8 +32,8 @@ static const int MAX_URI_LENGTH = 255;
 #define EXPORT_IMAGE_SIZE 256
 
 /* Colors for minting tab for each coin age group */
-#define COLOR_MINT_YOUNG QColor(127, 127, 240)
-#define COLOR_MINT_MATURE QColor(127, 240, 127)
-#define COLOR_MINT_OLD QColor(240, 127, 127)
+#define COLOR_MINT_YOUNG QColor(180, 180, 250)
+#define COLOR_MINT_MATURE QColor(180, 250, 180)
+#define COLOR_MINT_OLD QColor(250, 180, 180)
 
 #endif // GUICONSTANTS_H
index 4fbd50b..94d57d1 100644 (file)
       <translation>Показывать вероятность найти блок в течение : </translation>
     </message>
     <message>
-      <location filename="../mintingview.cpp" line="62"/>
+      <location filename="../mintingview.cpp" line="63"/>
       <source>10 min</source>
       <translation>10 минут</translation>
     </message>
     <message>
-      <location filename="../mintingview.cpp" line="63"/>
+      <location filename="../mintingview.cpp" line="64"/>
       <source>24 hours</source>
       <translation>24 часов</translation>
     </message>
     <message>
-      <location filename="../mintingview.cpp" line="64"/>
+      <location filename="../mintingview.cpp" line="65"/>
+      <source>7 days</source>
+      <translation>7 дней</translation>
+    </message>
+    <message>
+      <location filename="../mintingview.cpp" line="66"/>
       <source>30 days</source>
       <translation>30 дней</translation>
     </message>
     <message>
-      <location filename="../mintingview.cpp" line="65"/>
+      <location filename="../mintingview.cpp" line="67"/>
+      <source>60 days</source>
+      <translation>60 дней</translation>
+    </message>
+    <message>
+      <location filename="../mintingview.cpp" line="68"/>
       <source>90 days</source>
       <translation>90 дней</translation>
     </message>
     <message>
+      <location filename="../mintingview.cpp" line="103"/>
+      <source>Copy transaction ID of input</source>
+      <translation>Скопировать ID транзакции входа</translation>
+    </message>
+    <message>
+      <location filename="../mintingview.cpp" line="104"/>
+      <source>Copy address of input</source>
+      <translation>Скопировать адрес входа</translation>
+    </message>
+    <message>
+      <location filename="../mintingview.cpp" line="105"/>
+      <source>Show/hide 'Address' column</source>
+      <translation>Показать/скрыть столбец 'Адрес'</translation>
+    </message>
+    <message>
+      <location filename="../mintingview.cpp" line="106"/>
+      <source>Show/hide 'Transaction' column</source>
+      <translation>Показать/скрыть столбец 'Транзакция'</translation>
+    </message>
+    <message>
       <location filename="../mintingview.cpp" line="167"/>
       <source>Export Minting Data</source>
       <translation>Экспортировать данные таблицы</translation>
     </message>
     <message>
       <source>Balance</source>
-      <translation>Баланс</translation>
+      <translation>Сумма</translation>
     </message>
     <message>
       <source>MintProbability</source>
       <translation>Вероятность PoS</translation>
     </message>
     <message>
+      <source>MintReward</source>
+      <translation>Награда PoS</translation>
+    </message>
+    <message>
       <source>minutes</source>
       <translation>минут</translation>
     </message>
       <source>Chance to mint a block within given time interval.</source>
       <translation>Шанс найти блок в течение выбранного временного интервала.</translation>
     </message>
+    <message>
+      <source>The size of the potential rewards if the block is found at the beginning and the end given time interval.</source>
+      <translation>Размер потенциальной награды если блок найден в начале и конце выбранного временного интервала.</translation>
+    </message>
   </context>
 <context>
   <name>QObject</name>
   <message>
+    <source>from  %1 to %2</source>
+    <translation>от %1 до %2</translation>
+  </message>
+  <message>
     <source>%1 d</source>
     <translation>%1 д</translation>
   </message>
index 4973480..1007c95 100644 (file)
@@ -26,10 +26,11 @@ extern double GetDifficulty(const CBlockIndex* blockindex);
 static int column_alignments[] = {
     Qt::AlignLeft|Qt::AlignVCenter,
     Qt::AlignLeft|Qt::AlignVCenter,
-    Qt::AlignRight|Qt::AlignVCenter,
-    Qt::AlignRight|Qt::AlignVCenter,
-    Qt::AlignRight|Qt::AlignVCenter,
-    Qt::AlignRight|Qt::AlignVCenter
+    Qt::AlignLeft|Qt::AlignVCenter,
+    Qt::AlignLeft|Qt::AlignVCenter,
+    Qt::AlignLeft|Qt::AlignVCenter,
+    Qt::AlignLeft|Qt::AlignVCenter,
+    Qt::AlignLeft|Qt::AlignVCenter
 };
 
 struct TxLessThan
@@ -134,16 +135,17 @@ public:
                             KernelRecord::decomposeOutput(wallet, mi->second);
                     if(!toInsert.empty()) /* only if something to insert */
                     {
-                        parent->beginInsertRows(QModelIndex(), lowerIndex, lowerIndex+toInsert.size()-1);
                         int insert_idx = lowerIndex;
                         BOOST_FOREACH(const KernelRecord &rec, toInsert)
                         {
-                            if(!rec.spent) {
+                            if(!rec.spent) 
+                            {
+                                parent->beginInsertRows(QModelIndex(), insert_idx, insert_idx);
                                 cachedWallet.insert(insert_idx, rec);
+                                parent->endInsertRows();
                                 insert_idx += 1;
                             }
                         }
-                        parent->endInsertRows();
                     }
                 }
                 else if(!inWallet && inModel)
@@ -202,7 +204,7 @@ MintingTableModel::MintingTableModel(CWallet *wallet, WalletModel *parent):
         mintingInterval(10),
         priv(new MintingTablePriv(wallet, this))
 {
-    columns << tr("Transaction") <<  tr("Address") << tr("Age") << tr("Balance") << tr("CoinDay") << tr("MintProbability");
+    columns << tr("Transaction") <<  tr("Address") << tr("Balance") << tr("Age") << tr("CoinDay") << tr("MintProbability") << tr("MintReward");
     priv->refreshWallet();
 
     QTimer *timer = new QTimer(this);
@@ -273,6 +275,8 @@ QVariant MintingTableModel::data(const QModelIndex &index, int role) const
             return formatTxCoinDay(rec);
         case MintProbability:
             return formatDayToMint(rec);
+        case MintReward:
+            return formatTxPoSReward(rec);
         }
         break;
       case Qt::TextAlignmentRole:
@@ -316,6 +320,8 @@ QVariant MintingTableModel::data(const QModelIndex &index, int role) const
             return rec->nValue;
         case MintProbability:
             return getDayToMint(rec);
+        case MintReward:
+            return formatTxPoSReward(rec);
         }
         break;
       case Qt::BackgroundColorRole:
@@ -359,6 +365,15 @@ QString MintingTableModel::lookupAddress(const std::string &address, bool toolti
     return description;
 }
 
+QString MintingTableModel::formatTxPoSReward(KernelRecord *wtx) const
+{
+    QString posReward;
+    int nBits = GetLastBlockIndex(pindexBest, true)->nBits;
+    posReward += QString(QObject::tr("from  %1 to %2")).arg(BitcoinUnits::formatWithUnit(walletModel->getOptionsModel()->getDisplayUnit(), wtx->getPoSReward(nBits, 0)), 
+        BitcoinUnits::formatWithUnit(walletModel->getOptionsModel()->getDisplayUnit(), wtx->getPoSReward(nBits, mintingInterval))); 
+    return posReward;
+}
+
 double MintingTableModel::getDayToMint(KernelRecord *wtx) const
 {
     const CBlockIndex *p = GetLastBlockIndex(pindexBest, true);
@@ -387,7 +402,7 @@ QString MintingTableModel::formatTxHash(const KernelRecord *wtx) const
 
 QString MintingTableModel::formatTxCoinDay(const KernelRecord *wtx) const
 {
-    return QString::number(wtx->coinAge);
+    return QString::number(wtx->getCoinDay());
 }
 
 QString MintingTableModel::formatTxAge(const KernelRecord *wtx) const
@@ -398,7 +413,7 @@ QString MintingTableModel::formatTxAge(const KernelRecord *wtx) const
 
 QString MintingTableModel::formatTxBalance(const KernelRecord *wtx) const
 {
-    return BitcoinUnits::format(walletModel->getOptionsModel()->getDisplayUnit(), wtx->nValue);
+    return BitcoinUnits::formatWithUnit(walletModel->getOptionsModel()->getDisplayUnit(), wtx->nValue);
 }
 
 QVariant MintingTableModel::headerData(int section, Qt::Orientation orientation, int role) const
@@ -428,6 +443,8 @@ QVariant MintingTableModel::headerData(int section, Qt::Orientation orientation,
                 return tr("Coin age in the output.");
             case MintProbability:
                 return tr("Chance to mint a block within given time interval.");
+            case MintReward:
+                return tr("The size of the potential rewards if the block is found at the beginning and the end given time interval.");
             }
         }
     }
@@ -447,4 +464,3 @@ QModelIndex MintingTableModel::index(int row, int column, const QModelIndex &par
         return QModelIndex();
     }
 }
-
index c265ce5..47c5120 100644 (file)
@@ -20,10 +20,11 @@ public:
     enum ColumnIndex {
         TxHash = 0,
         Address = 1,
-        Age = 2,
-        Balance = 3,
+        Balance = 2,
+        Age = 3,
         CoinDay = 4,
-        MintProbability = 5
+        MintProbability = 5,
+        MintReward = 6
     };
 
 
@@ -51,6 +52,7 @@ private:
     QString formatTxAge(const KernelRecord *wtx) const;
     QString formatTxBalance(const KernelRecord *wtx) const;
     QString formatTxCoinDay(const KernelRecord *wtx) const;
+    QString formatTxPoSReward(KernelRecord *wtx) const;
 private slots:
     void update();
 
index 07ecadf..9a227e8 100644 (file)
@@ -17,6 +17,7 @@
 #include <QLineEdit>
 #include <QComboBox>
 #include <QMessageBox>
+#include <QMenu>
 
 MintingView::MintingView(QWidget *parent) :
     QWidget(parent), model(0), mintingView(0)
@@ -61,7 +62,9 @@ MintingView::MintingView(QWidget *parent) :
     mintingCombo = new QComboBox();
     mintingCombo->addItem(tr("10 min"), Minting10min);
     mintingCombo->addItem(tr("24 hours"), Minting1day);
+    mintingCombo->addItem(tr("7 days"), Minting7days);
     mintingCombo->addItem(tr("30 days"), Minting30days);
+    mintingCombo->addItem(tr("60 days"), Minting60days);
     mintingCombo->addItem(tr("90 days"), Minting90days);
     mintingCombo->setFixedWidth(120);
 
@@ -96,6 +99,24 @@ MintingView::MintingView(QWidget *parent) :
 
     connect(mintingCombo, SIGNAL(activated(int)), this, SLOT(chooseMintingInterval(int)));
 
+    // Actions
+    QAction *copyTxIDAction = new QAction(tr("Copy transaction ID of input"), this);
+    QAction *copyAddressAction = new QAction(tr("Copy address of input"), this);
+    QAction *showHideAddressAction = new QAction(tr("Show/hide 'Address' column"), this);
+    QAction *showHideTxIDAction = new QAction(tr("Show/hide 'Transaction' column"), this);
+
+    contextMenu = new QMenu();
+    contextMenu->addAction(copyAddressAction);
+    contextMenu->addAction(copyTxIDAction);
+    contextMenu->addAction(showHideAddressAction);
+    contextMenu->addAction(showHideTxIDAction);
+
+    connect(copyAddressAction, SIGNAL(triggered()), this, SLOT(copyAddress()));
+    connect(copyTxIDAction, SIGNAL(triggered()), this, SLOT(copyTxID()));
+    connect(showHideAddressAction, SIGNAL(triggered()), this, SLOT(showHideAddress()));
+    connect(showHideTxIDAction, SIGNAL(triggered()), this, SLOT(showHideTxID()));
+
+    connect(view, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(contextualMenu(QPoint)));
 }
 
 
@@ -118,22 +139,24 @@ void MintingView::setModel(WalletModel *model)
         mintingView->verticalHeader()->hide();
 
         mintingView->horizontalHeader()->resizeSection(
-                MintingTableModel::Address, 420);
+                MintingTableModel::Age, 60);
+        mintingView->horizontalHeader()->resizeSection(
+                MintingTableModel::Balance, 80);
+        mintingView->horizontalHeader()->resizeSection(
+                MintingTableModel::CoinDay,60);
+        mintingView->horizontalHeader()->resizeSection(
+                MintingTableModel::MintProbability, 105);
 #if QT_VERSION < 0x050000
         mintingView->horizontalHeader()->setResizeMode(
-                MintingTableModel::TxHash, QHeaderView::Stretch);
+                MintingTableModel::MintReward, QHeaderView::Stretch);
 #else
         mintingView->horizontalHeader()->setSectionResizeMode(
-                MintingTableModel::TxHash, QHeaderView::Stretch);
+                MintingTableModel::MintReward, QHeaderView::Stretch);
 #endif
         mintingView->horizontalHeader()->resizeSection(
-                MintingTableModel::Age, 120);
-        mintingView->horizontalHeader()->resizeSection(
-                MintingTableModel::Balance, 120);
+            MintingTableModel::Address, 245);
         mintingView->horizontalHeader()->resizeSection(
-                MintingTableModel::CoinDay,120);
-        mintingView->horizontalHeader()->resizeSection(
-                MintingTableModel::MintProbability, 160);
+            MintingTableModel::TxHash, 75);
     }
 }
 
@@ -148,9 +171,15 @@ void MintingView::chooseMintingInterval(int idx)
         case Minting1day:
             interval = 60*24;
             break;
+        case Minting7days:
+            interval = 60*24*7;
+            break;
         case Minting30days:
             interval = 60*24*30;
             break;
+        case Minting60days:
+            interval = 60*24*60;
+            break;
         case Minting90days:
             interval = 60*24*90;
             break;
@@ -173,12 +202,13 @@ void MintingView::exportClicked()
 
     // name, column, role
     writer.setModel(mintingProxyModel);
-    writer.addColumn(tr("Address"),0, MintingTableModel::Address);
-    writer.addColumn(tr("Transaction"), 0, MintingTableModel::TxHash);
-    writer.addColumn(tr("Age"), 0, MintingTableModel::Age);
-    writer.addColumn(tr("CoinDay"), 0, MintingTableModel::CoinDay);
-    writer.addColumn(tr("Balance"), 0, MintingTableModel::Balance);
-    writer.addColumn(tr("MintingProbability"), 0, MintingTableModel::MintProbability);
+    writer.addColumn(tr("Address"),MintingTableModel::Address,0);
+    writer.addColumn(tr("Transaction"),MintingTableModel::TxHash,0);
+    writer.addColumn(tr("Age"), MintingTableModel::Age,0);
+    writer.addColumn(tr("CoinDay"), MintingTableModel::CoinDay,0);
+    writer.addColumn(tr("Balance"), MintingTableModel::Balance,0);
+    writer.addColumn(tr("MintingProbability"), MintingTableModel::MintProbability,0);
+    writer.addColumn(tr("MintingReward"), MintingTableModel::MintReward,0);
 
     if(!writer.write())
     {
@@ -186,3 +216,34 @@ void MintingView::exportClicked()
                               QMessageBox::Abort, QMessageBox::Abort);
     }
 }
+
+void MintingView::copyTxID()
+{
+    GUIUtil::copyEntryData(mintingView, MintingTableModel::TxHash, 0);
+}
+
+void MintingView::copyAddress()
+{
+    GUIUtil::copyEntryData(mintingView, MintingTableModel::Address, 0 );
+}
+
+void MintingView::showHideAddress()
+{
+    mintingView->horizontalHeader()->setSectionHidden(MintingTableModel::Address, 
+        !(mintingView->horizontalHeader()->isSectionHidden(MintingTableModel::Address)));
+}
+
+void MintingView::showHideTxID()
+{
+    mintingView->horizontalHeader()->setSectionHidden(MintingTableModel::TxHash, 
+        !(mintingView->horizontalHeader()->isSectionHidden(MintingTableModel::TxHash)));
+}
+
+void MintingView::contextualMenu(const QPoint &point)
+{
+    QModelIndex index = mintingView->indexAt(point);
+    if(index.isValid())
+    {
+        contextMenu->exec(QCursor::pos());
+    }
+}
\ No newline at end of file
index 452deaa..f318011 100644 (file)
@@ -10,6 +10,7 @@ class WalletModel;
 
 QT_BEGIN_NAMESPACE
 class QTableView;
+class QMenu;
 QT_END_NAMESPACE
 
 class MintingView : public QWidget
@@ -23,7 +24,9 @@ public:
     {
         Minting10min,
         Minting1day,
+        Minting7days,
         Minting30days,
+        Minting60days,
         Minting90days
     };
 
@@ -35,11 +38,18 @@ private:
 
     MintingFilterProxy *mintingProxyModel;
 
+    QMenu *contextMenu;
+
 signals:
 
 public slots:
     void exportClicked();
     void chooseMintingInterval(int idx);
+    void copyTxID();
+    void copyAddress();
+    void showHideAddress();
+    void showHideTxID();
+    void contextualMenu(const QPoint &point);
 };
 
 #endif // MINTINGVIEW_H
index 87e487f..9131743 100644 (file)
@@ -648,8 +648,7 @@ bool CWallet::IsChange(const CTxOut& txout) const
 
 int64 CWalletTx::GetTxTime() const
 {
-    int64 n = nTimeSmart;
-    return n ? n : nTimeReceived;
+    return nTime;
 }
 
 int CWalletTx::GetRequestCount() const