From: CryptoManiac Date: Sun, 15 Jun 2014 20:37:39 +0000 (+0400) Subject: Add input weight to coin control interface X-Git-Tag: v0.4.4.6-nvc-update4~1^2~20 X-Git-Url: https://git.novaco.in/?p=novacoin.git;a=commitdiff_plain;h=b62973560f4cf5a7919882798e84b15bb720e7c1 Add input weight to coin control interface --- diff --git a/src/qt/coincontroldialog.cpp b/src/qt/coincontroldialog.cpp index 0fd690c..4fe9f3b 100644 --- a/src/qt/coincontroldialog.cpp +++ b/src/qt/coincontroldialog.cpp @@ -107,10 +107,11 @@ CoinControlDialog::CoinControlDialog(QWidget *parent) : ui->treeWidget->setColumnWidth(COLUMN_CHECKBOX, 84); ui->treeWidget->setColumnWidth(COLUMN_AMOUNT, 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_ADDRESS, 250); + ui->treeWidget->setColumnWidth(COLUMN_DATE, 90); + ui->treeWidget->setColumnWidth(COLUMN_CONFIRMATIONS, 70); ui->treeWidget->setColumnWidth(COLUMN_PRIORITY, 100); + ui->treeWidget->setColumnWidth(COLUMN_WEIGHT, 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 @@ -338,7 +339,7 @@ void CoinControlDialog::headerSectionClicked(int logicalIndex) else { sortColumn = logicalIndex; - sortOrder = ((sortColumn == COLUMN_AMOUNT_INT64 || sortColumn == COLUMN_PRIORITY_INT64 || sortColumn == COLUMN_DATE || sortColumn == COLUMN_CONFIRMATIONS) ? Qt::DescendingOrder : Qt::AscendingOrder); // if amount,date,conf,priority then default => desc, else default => asc + sortOrder = ((sortColumn == COLUMN_AMOUNT_INT64 || sortColumn == COLUMN_PRIORITY_INT64 || sortColumn == COLUMN_DATE || sortColumn == COLUMN_CONFIRMATIONS || sortColumn == COLUMN_WEIGHT) ? Qt::DescendingOrder : Qt::AscendingOrder); // if amount,date,conf,priority then default => desc, else default => asc } sortView(sortColumn, sortOrder); @@ -593,11 +594,11 @@ void CoinControlDialog::updateView() ui->treeWidget->setAlternatingRowColors(!treeMode); QFlags flgCheckbox=Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsUserCheckable; QFlags flgTristate=Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsUserCheckable | Qt::ItemIsTristate; - + int nDisplayUnit = BitcoinUnits::BTC; if (model && model->getOptionsModel()) nDisplayUnit = model->getOptionsModel()->getDisplayUnit(); - + map > mapCoins; model->listCoins(mapCoins); @@ -610,7 +611,7 @@ void CoinControlDialog::updateView() sWalletLabel = model->getAddressTableModel()->labelForAddress(sWalletAddress); if (sWalletLabel.length() == 0) sWalletLabel = tr("(no label)"); - + if (treeMode) { // wallet address @@ -618,10 +619,10 @@ void CoinControlDialog::updateView() itemWalletAddress->setFlags(flgTristate); itemWalletAddress->setCheckState(COLUMN_CHECKBOX,Qt::Unchecked); - + for (int i = 0; i < ui->treeWidget->columnCount(); i++) itemWalletAddress->setBackground(i, QColor(248, 247, 246)); - + // label itemWalletAddress->setText(COLUMN_LABEL, sWalletLabel); @@ -633,29 +634,32 @@ 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; + model->getStakeWeightFromValue(out.tx->GetTxTime(), out.tx->vout[out.i].nValue, nTxWeight); + nTxWeightSum += nTxWeight; nChildren++; - + QTreeWidgetItem *itemOutput; if (treeMode) itemOutput = new QTreeWidgetItem(itemWalletAddress); else itemOutput = new QTreeWidgetItem(ui->treeWidget); itemOutput->setFlags(flgCheckbox); itemOutput->setCheckState(COLUMN_CHECKBOX,Qt::Unchecked); - + // address CTxDestination outputAddress; QString sAddress = ""; if(ExtractDestination(out.tx->vout[out.i].scriptPubKey, outputAddress)) { sAddress = CBitcoinAddress(outputAddress).ToString().c_str(); - + // if listMode or change => show bitcoin address. In tree mode, address is not shown again for direct wallet address outputs if (!treeMode || (!(sAddress == sWalletAddress))) itemOutput->setText(COLUMN_ADDRESS, sAddress); - + CPubKey pubkey; CKeyID *keyid = boost::get< CKeyID >(&outputAddress); if (keyid && model->getPubKey(*keyid, pubkey) && !pubkey.IsCompressed()) @@ -685,7 +689,7 @@ void CoinControlDialog::updateView() // date itemOutput->setText(COLUMN_DATE, QDateTime::fromTime_t(out.tx->GetTxTime()).toUTC().toString("yy-MM-dd hh:mm")); - + // immature PoS reward if (out.tx->IsCoinStake() && out.tx->GetBlocksToMaturity() > 0 && out.tx->GetDepthInMainChain() > 0) { itemOutput->setBackground(COLUMN_CONFIRMATIONS, Qt::red); @@ -694,22 +698,25 @@ void CoinControlDialog::updateView() // confirmations itemOutput->setText(COLUMN_CONFIRMATIONS, strPad(QString::number(out.nDepth), 8, " ")); - + // priority double dPriority = ((double)out.tx->vout[out.i].nValue / (nInputSize + 78)) * (out.nDepth+1); // 78 = 2 * 34 + 10 itemOutput->setText(COLUMN_PRIORITY, CoinControlDialog::getPriorityLabel(dPriority)); itemOutput->setText(COLUMN_PRIORITY_INT64, strPad(QString::number((int64)dPriority), 20, " ")); 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()); - + // vout index itemOutput->setText(COLUMN_VOUT_INDEX, QString::number(out.i)); - - // disable locked coins + + // disable locked coins /*if (model->isLockedCoin(txhash, out.i)) { COutPoint outpt(txhash, out.i); @@ -717,7 +724,7 @@ void CoinControlDialog::updateView() itemOutput->setDisabled(true); itemOutput->setIcon(COLUMN_CHECKBOX, QIcon(":/icons/lock_closed")); }*/ - + // set checkbox if (coinControl->IsSelected(txhash, out.i)) itemOutput->setCheckState(COLUMN_CHECKBOX,Qt::Checked); @@ -732,9 +739,11 @@ 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, " ")); + itemWalletAddress->setText(COLUMN_WEIGHT, strPad(QString::number((uint64)nTxWeightSum),8," ")); + } } - + // expand all partially selected if (treeMode) { @@ -742,7 +751,7 @@ void CoinControlDialog::updateView() if (ui->treeWidget->topLevelItem(i)->checkState(COLUMN_CHECKBOX) == Qt::PartiallyChecked) ui->treeWidget->topLevelItem(i)->setExpanded(true); } - + // sort view sortView(sortColumn, sortOrder); ui->treeWidget->setEnabled(true); diff --git a/src/qt/coincontroldialog.h b/src/qt/coincontroldialog.h index 5d0a90b..28d8f4a 100644 --- a/src/qt/coincontroldialog.h +++ b/src/qt/coincontroldialog.h @@ -57,6 +57,7 @@ private: COLUMN_ADDRESS, COLUMN_DATE, COLUMN_CONFIRMATIONS, + COLUMN_WEIGHT, COLUMN_PRIORITY, COLUMN_TXHASH, COLUMN_VOUT_INDEX, diff --git a/src/qt/forms/coincontroldialog.ui b/src/qt/forms/coincontroldialog.ui index c19e312..e29e58d 100644 --- a/src/qt/forms/coincontroldialog.ui +++ b/src/qt/forms/coincontroldialog.ui @@ -379,7 +379,7 @@ 41 - + 14 @@ -494,6 +494,11 @@ + Weight + + + + Priority diff --git a/src/qt/locale/bitcoin_ru.ts b/src/qt/locale/bitcoin_ru.ts index 8cb011a..bb99298 100644 --- a/src/qt/locale/bitcoin_ru.ts +++ b/src/qt/locale/bitcoin_ru.ts @@ -891,6 +891,11 @@ This label turns red, if the priority is smaller than "medium". Приоритет + + Weight + Вес + + Label Метка diff --git a/src/qt/walletmodel.cpp b/src/qt/walletmodel.cpp index ac8b68f..115df69 100644 --- a/src/qt/walletmodel.cpp +++ b/src/qt/walletmodel.cpp @@ -306,6 +306,16 @@ bool WalletModel::changePassphrase(const SecureString &oldPass, const SecureStri return retval; } +void WalletModel::getStakeWeight(uint64& nMinWeight, uint64& nMaxWeight, uint64& nWeight) +{ + wallet->GetStakeWeight(*wallet, nMinWeight, nMaxWeight, nWeight); +} + +void WalletModel::getStakeWeightFromValue(const int64& nTime, const int64& nValue, uint64& nWeight) +{ + wallet->GetStakeWeightFromValue(nTime, nValue, nWeight); +} + bool WalletModel::backupWallet(const QString &filename) { return BackupWallet(*wallet, filename.toLocal8Bit().data()); diff --git a/src/qt/walletmodel.h b/src/qt/walletmodel.h index b33ff75..5f10e50 100644 --- a/src/qt/walletmodel.h +++ b/src/qt/walletmodel.h @@ -96,6 +96,9 @@ public: // Wallet backup bool backupWallet(const QString &filename); + void getStakeWeight(quint64& nMinWeight, quint64& nMaxWeight, quint64& nWeight); + void getStakeWeightFromValue(const qint64& nTime, const qint64& nValue, quint64& nWeight); + // RAI object for unlocking wallet, returned by requestUnlock() class UnlockContext { diff --git a/src/wallet.cpp b/src/wallet.cpp index 0994a2d..a0b0c6b 100644 --- a/src/wallet.cpp +++ b/src/wallet.cpp @@ -1497,6 +1497,22 @@ bool CWallet::CreateTransaction(CScript scriptPubKey, int64 nValue, CWalletTx& w return CreateTransaction(vecSend, wtxNew, reservekey, nFeeRet, coinControl); } +void CWallet::GetStakeWeightFromValue(const int64& nTime, const int64& nValue, uint64& nWeight) +{ + int64 nTimeWeight = GetWeight(nTime, (int64)GetTime()); + + // If time weight is lower or equal to zero then weight is zero. + if (nTimeWeight <= 0) + { + nWeight = 0; + return; + } + + CBigNum bnCoinDayWeight = CBigNum(nValue) * nTimeWeight / COIN / (24 * 60 * 60); + nWeight = bnCoinDayWeight.getuint64(); +} + + // NovaCoin: get current stake weight bool CWallet::GetStakeWeight(const CKeyStore& keystore, uint64& nMinWeight, uint64& nMaxWeight, uint64& nWeight) { diff --git a/src/wallet.h b/src/wallet.h index a78dcee..56a60e1 100644 --- a/src/wallet.h +++ b/src/wallet.h @@ -189,6 +189,7 @@ public: bool CommitTransaction(CWalletTx& wtxNew, CReserveKey& reservekey); bool GetStakeWeight(const CKeyStore& keystore, uint64& nMinWeight, uint64& nMaxWeight, uint64& nWeight); + void GetStakeWeightFromValue(const int64& nTime, const int64& nValue, uint64& nWeight); bool CreateCoinStake(const CKeyStore& keystore, unsigned int nBits, int64 nSearchInterval, CTransaction& txNew, CKey& key); std::string SendMoney(CScript scriptPubKey, int64 nValue, CWalletTx& wtxNew, bool fAskFee=false);