Skip to content

Commit

Permalink
Weight to CC + GUI enhance
Browse files Browse the repository at this point in the history
  • Loading branch information
presstab committed Jul 10, 2014
1 parent e4365d4 commit bd9830a
Show file tree
Hide file tree
Showing 11 changed files with 71 additions and 25 deletions.
4 changes: 2 additions & 2 deletions src/kernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ int64 GetWeight(int64 nIntervalBeginning, int64 nIntervalEnd)
return min(nIntervalEnd - nIntervalBeginning - nStakeMinAge, (int64)nStakeMaxAge);
}

// Get time weight 2 - This is added for informational purposes since staking takes 9.1 days min approx. because of bug
// Get time weight 2 - This is added for informational purposes since staking takes 8.8 days min approx. because of bug
int64 GetWeight2(int64 nIntervalBeginning, int64 nIntervalEnd)
{
// Kernel hash weight starts from 0 at the min age
// this change increases active coins participating the hash and helps
// to secure the network when proof-of-stake difficulty is low
int64 nStakeMinAgeV2 = 60 * 60 * 24 * 9.1;
int64 nStakeMinAgeV2 = 60 * 60 * 24 * 8.8;
return min(nIntervalEnd - nIntervalBeginning - nStakeMinAgeV2, (int64)nStakeMaxAge);
}

Expand Down
2 changes: 1 addition & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3984,7 +3984,7 @@ CBlock* CreateNewBlock(CWallet* pwallet, bool fProofOfStake)
int64 nMinTxFee = MIN_TX_FEE;
if (mapArgs.count("-mintxfee"))
ParseMoney(mapArgs["-mintxfee"], nMinTxFee);

// ppcoin: if coinstake available add coinstake tx
static int64 nLastCoinStakeSearchTime = GetAdjustedTime(); // only initialized at startup
CBlockIndex* pindexPrev = pindexBest;
Expand Down
15 changes: 13 additions & 2 deletions src/qt/coincontroldialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,18 +106,19 @@ CoinControlDialog::CoinControlDialog(QWidget *parent) :

ui->treeWidget->setColumnWidth(COLUMN_CHECKBOX, 84);
ui->treeWidget->setColumnWidth(COLUMN_AMOUNT, 100);
ui->treeWidget->setColumnWidth(COLUMN_CONFIRMATIONS, 100);
ui->treeWidget->setColumnWidth(COLUMN_WEIGHT, 100);
ui->treeWidget->setColumnWidth(COLUMN_LABEL, 170);
ui->treeWidget->setColumnWidth(COLUMN_ADDRESS, 290);
ui->treeWidget->setColumnWidth(COLUMN_DATE, 110);
ui->treeWidget->setColumnWidth(COLUMN_CONFIRMATIONS, 100);
ui->treeWidget->setColumnWidth(COLUMN_PRIORITY, 100);
ui->treeWidget->setColumnHidden(COLUMN_TXHASH, true); // store transacton hash in this column, but dont show it
ui->treeWidget->setColumnHidden(COLUMN_VOUT_INDEX, true); // store vout index in this column, but dont show it
ui->treeWidget->setColumnHidden(COLUMN_AMOUNT_INT64, true); // store amount int64 in this column, but dont show it
ui->treeWidget->setColumnHidden(COLUMN_PRIORITY_INT64, true); // store priority int64 in this column, but dont show it

// default view is sorted by amount desc
sortView(COLUMN_AMOUNT_INT64, Qt::DescendingOrder);
sortView(COLUMN_CONFIRMATIONS, Qt::DescendingOrder);
}

CoinControlDialog::~CoinControlDialog()
Expand Down Expand Up @@ -622,12 +623,16 @@ void CoinControlDialog::updateView()
double dPrioritySum = 0;
int nChildren = 0;
int nInputSum = 0;
uint64 nTxWeight = 0, nTxWeightSum = 0;
BOOST_FOREACH(const COutput& out, coins.second)
{
int nInputSize = 148; // 180 if uncompressed public key
nSum += out.tx->vout[out.i].nValue;
nChildren++;

model->getStakeWeightFromValue(out.tx->GetTxTime(), out.tx->vout[out.i].nValue, nTxWeight);
nTxWeightSum += nTxWeight;

QTreeWidgetItem *itemOutput;
if (treeMode) itemOutput = new QTreeWidgetItem(itemWalletAddress);
else itemOutput = new QTreeWidgetItem(ui->treeWidget);
Expand Down Expand Up @@ -691,6 +696,9 @@ void CoinControlDialog::updateView()
dPrioritySum += (double)out.tx->vout[out.i].nValue * (out.nDepth+1);
nInputSum += nInputSize;

// List Mode Weight
itemOutput->setText(COLUMN_WEIGHT, strPad(QString::number(nTxWeight), 8, " "));

// transaction hash
uint256 txhash = out.tx->GetHash();
itemOutput->setText(COLUMN_TXHASH, txhash.GetHex().c_str());
Expand Down Expand Up @@ -721,6 +729,9 @@ void CoinControlDialog::updateView()
itemWalletAddress->setText(COLUMN_AMOUNT_INT64, strPad(QString::number(nSum), 15, " "));
itemWalletAddress->setText(COLUMN_PRIORITY, CoinControlDialog::getPriorityLabel(dPrioritySum));
itemWalletAddress->setText(COLUMN_PRIORITY_INT64, strPad(QString::number((int64)dPrioritySum), 20, " "));

//Tree Mode Weight
itemWalletAddress->setText(COLUMN_WEIGHT, strPad(QString::number((uint64)nTxWeightSum),8," "));
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/qt/coincontroldialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,11 @@ class CoinControlDialog : public QDialog
{
COLUMN_CHECKBOX,
COLUMN_AMOUNT,
COLUMN_CONFIRMATIONS,
COLUMN_WEIGHT,
COLUMN_LABEL,
COLUMN_ADDRESS,
COLUMN_DATE,
COLUMN_CONFIRMATIONS,
COLUMN_PRIORITY,
COLUMN_TXHASH,
COLUMN_VOUT_INDEX,
Expand Down
41 changes: 27 additions & 14 deletions src/qt/forms/coincontroldialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -395,36 +395,36 @@
</sizepolicy>
</property>
<property name="text">
<string>(un)select all</string>
<string>clear selections</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="radioTreeMode">
<widget class="QRadioButton" name="radioListMode">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Tree mode</string>
<string>List Mode</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="radioListMode">
<widget class="QRadioButton" name="radioTreeMode">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>List mode</string>
<string>Tree Mode</string>
</property>
</widget>
</item>
Expand Down Expand Up @@ -472,29 +472,42 @@
<string>Amount</string>
</property>
</column>
<column>

<column>
<property name="text">
<string>Label</string>
<string>Confirmations</string>
</property>
<property name="toolTip">
<string>Confirmed</string>
</property>
</column>
<column>

<column>
<property name="text">
<string>Address</string>
<string>Weight</string>
</property>
</column>
<column>

<column>
<property name="text">
<string>Date</string>
<string>Label</string>
</property>
</column>

<column>
<property name="text">
<string>Confirmations</string>
<string>Address</string>
</property>
<property name="toolTip">
<string>Confirmed</string>
</column>

<column>
<property name="text">
<string>Date</string>
</property>
</column>



<column>
<property name="text">
<string>Priority</string>
Expand Down
4 changes: 2 additions & 2 deletions src/qt/forms/sendcoinsdialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,14 @@
<string notr="true"/>
</property>
<property name="text">
<string>Inputs...</string>
<string>Coin Control</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="labelCoinControlAutomaticallySelected">
<property name="text">
<string>automatically selected</string>
<string>Low Priority Coins Automatically Selected</string>
</property>
<property name="margin">
<number>5</number>
Expand Down
2 changes: 1 addition & 1 deletion src/qt/optionsmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ void OptionsModel::Init()
bDisplayAddresses = settings.value("bDisplayAddresses", false).toBool();
fMinimizeToTray = settings.value("fMinimizeToTray", false).toBool();
fMinimizeOnClose = settings.value("fMinimizeOnClose", false).toBool();
fCoinControlFeatures = settings.value("fCoinControlFeatures", false).toBool();
fCoinControlFeatures = settings.value("fCoinControlFeatures", true).toBool();
nTransactionFee = settings.value("nTransactionFee").toLongLong();
language = settings.value("language", "").toString();

Expand Down
5 changes: 5 additions & 0 deletions src/qt/walletmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,11 @@ bool WalletModel::backupWallet(const QString &filename)
return BackupWallet(*wallet, filename.toLocal8Bit().data());
}

void WalletModel::getStakeWeightFromValue(const int64& nTime, const int64& nValue, uint64& nWeight)
{
wallet->GetStakeWeightFromValue(nTime, nValue, nWeight);
}

// Handlers for core signals
static void NotifyKeyStoreStatusChanged(WalletModel *walletmodel, CCryptoKeyStore *wallet)
{
Expand Down
3 changes: 2 additions & 1 deletion src/qt/walletmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ class WalletModel : public QObject
bool changePassphrase(const SecureString &oldPass, const SecureString &newPass);
// Wallet backup
bool backupWallet(const QString &filename);

//Stake Weight for coin control dialog
void getStakeWeightFromValue(const qint64& nTime, const qint64& nValue, quint64& nWeight);
// RAI object for unlocking wallet, returned by requestUnlock()
class UnlockContext
{
Expand Down
16 changes: 15 additions & 1 deletion src/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1366,6 +1366,20 @@ bool CWallet::CreateTransaction(const vector<pair<CScript, int64> >& vecSend, CW
return true;
}

bool CWallet::GetStakeWeightFromValue(const int64& nTime, const int64& nValue, uint64& nWeight)
{
//This is a negative value when there is no weight. But set it to zero
//so the user is not confused. Used in reporting in Coin Control.
// Descisions based on this function should be used with care.
int64 nTimeWeight = GetWeight2(nTime, (int64)GetTime());
if (nTimeWeight < 0 )
nTimeWeight=0;

CBigNum bnCoinDayWeight = CBigNum(nValue) * nTimeWeight / COIN / (24 * 60 * 60);
nWeight = bnCoinDayWeight.getuint64();
return true;
}

bool CWallet::CreateTransaction(CScript scriptPubKey, int64 nValue, CWalletTx& wtxNew, CReserveKey& reservekey, int64& nFeeRet, const CCoinControl* coinControl)
{
vector< pair<CScript, int64> > vecSend;
Expand Down Expand Up @@ -1429,7 +1443,7 @@ bool CWallet::GetStakeWeight(const CKeyStore& keystore, uint64& nMinWeight, uint
return true;
}

//This is added for informational purposes since staking takes 9.1 days min approx. because of bug
//This is added for informational purposes since staking takes 8.8 days min approx. because of bug
bool CWallet::GetStakeWeight2(const CKeyStore& keystore, uint64& nMinWeight, uint64& nMaxWeight, uint64& nWeight)
{
// Choose coins to use
Expand Down
1 change: 1 addition & 0 deletions src/wallet.h
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ class CWallet : public CCryptoKeyStore
bool GetStakeWeight(const CKeyStore& keystore, uint64& nMinWeight, uint64& nMaxWeight, uint64& nWeight);
bool GetStakeWeight2(const CKeyStore& keystore, uint64& nMinWeight, uint64& nMaxWeight, uint64& nWeight);
bool CreateCoinStake(const CKeyStore& keystore, unsigned int nBits, int64 nSearchInterval, CTransaction& txNew);
bool GetStakeWeightFromValue(const int64& nTime, const int64& nValue, uint64& nWeight);
std::string SendMoney(CScript scriptPubKey, int64 nValue, CWalletTx& wtxNew, bool fAskFee=false);
std::string SendMoneyToDestination(const CTxDestination &address, int64 nValue, CWalletTx& wtxNew, bool fAskFee=false);

Expand Down

0 comments on commit bd9830a

Please sign in to comment.