Skip to content

Commit

Permalink
[BROKEN] Unbreak Qt code after CA
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenroose committed Mar 20, 2019
1 parent f7920d7 commit 5f9f578
Show file tree
Hide file tree
Showing 11 changed files with 71 additions and 59 deletions.
16 changes: 8 additions & 8 deletions src/qt/coincontroldialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ void CoinControlDialog::updateLabels(WalletModel *model, QDialog* dialog)

if (amount > 0)
{
CTxOut txout(amount, static_cast<CScript>(std::vector<unsigned char>(24, 0)));
CTxOut txout(::policyAsset, amount, static_cast<CScript>(std::vector<unsigned char>(24, 0)));
txDummy.vout.push_back(txout);
fDust |= IsDust(txout, model->node().getDustRelayFee());
}
Expand Down Expand Up @@ -454,7 +454,7 @@ void CoinControlDialog::updateLabels(WalletModel *model, QDialog* dialog)
nQuantity++;

// Amount
nAmount += out.txout.nValue;
nAmount += out.txout.nValue.GetAmount();

// Bytes
CTxDestination address;
Expand All @@ -468,8 +468,8 @@ void CoinControlDialog::updateLabels(WalletModel *model, QDialog* dialog)
else if(ExtractDestination(out.txout.scriptPubKey, address))
{
CPubKey pubkey;
CKeyID *keyid = boost::get<CKeyID>(&address);
if (keyid && model->wallet().getPubKey(*keyid, pubkey))
PKHash *keyid = boost::get<PKHash>(&address);
if (keyid && model->wallet().getPubKey(CKeyID(*keyid), pubkey))
{
nBytesInputs += (pubkey.IsCompressed() ? 148 : 180);
}
Expand Down Expand Up @@ -510,7 +510,7 @@ void CoinControlDialog::updateLabels(WalletModel *model, QDialog* dialog)
// Never create dust outputs; if we would, just add the dust to the fee.
if (nChange > 0 && nChange < MIN_CHANGE)
{
CTxOut txout(nChange, static_cast<CScript>(std::vector<unsigned char>(24, 0)));
CTxOut txout(::policyAsset, nChange, static_cast<CScript>(std::vector<unsigned char>(24, 0)));
if (IsDust(txout, model->node().getDustRelayFee()))
{
nPayFee += nChange;
Expand Down Expand Up @@ -639,7 +639,7 @@ void CoinControlDialog::updateView()
for (const auto& outpair : coins.second) {
const COutPoint& output = std::get<0>(outpair);
const interfaces::WalletTxOut& out = std::get<1>(outpair);
nSum += out.txout.nValue;
nSum += out.txout.nValue.GetAmount();
nChildren++;

CCoinControlWidgetItem *itemOutput;
Expand Down Expand Up @@ -676,8 +676,8 @@ void CoinControlDialog::updateView()
}

// amount
itemOutput->setText(COLUMN_AMOUNT, BitcoinUnits::format(nDisplayUnit, out.txout.nValue));
itemOutput->setData(COLUMN_AMOUNT, Qt::UserRole, QVariant((qlonglong)out.txout.nValue)); // padding so that sorting works correctly
itemOutput->setText(COLUMN_AMOUNT, BitcoinUnits::format(nDisplayUnit, out.txout.nValue.GetAmount()));
itemOutput->setData(COLUMN_AMOUNT, Qt::UserRole, QVariant((qlonglong)out.txout.nValue.GetAmount())); // padding so that sorting works correctly

// date
itemOutput->setText(COLUMN_DATE, GUIUtil::dateTimeStr(out.time));
Expand Down
3 changes: 2 additions & 1 deletion src/qt/guiutil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <qt/qvalidatedlineedit.h>
#include <qt/walletmodel.h>

#include <asset.h>
#include <base58.h>
#include <chainparams.h>
#include <primitives/transaction.h>
Expand Down Expand Up @@ -211,7 +212,7 @@ bool isDust(interfaces::Node& node, const QString& address, const CAmount& amoun
{
CTxDestination dest = DecodeDestination(address.toStdString());
CScript script = GetScriptForDestination(dest);
CTxOut txOut(amount, script);
CTxOut txOut(CAsset(), amount, script);
return IsDust(txOut, node.getDustRelayFee());
}

Expand Down
26 changes: 14 additions & 12 deletions src/qt/overviewpage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
#include <qt/transactiontablemodel.h>
#include <qt/walletmodel.h>

#include <policy/policy.h>

#include <QAbstractItemDelegate>
#include <QPainter>

Expand Down Expand Up @@ -119,7 +121,7 @@ OverviewPage::OverviewPage(const PlatformStyle *platformStyle, QWidget *parent)
{
ui->setupUi(this);

m_balances.balance = -1;
m_balances.balance[::policyAsset] = -1;

// use a SingleColorIcon for the "out of sync warning" icon
QIcon icon = platformStyle->SingleColorIcon(":/icons/warning");
Expand Down Expand Up @@ -161,19 +163,19 @@ void OverviewPage::setBalance(const interfaces::WalletBalances& balances)
{
int unit = walletModel->getOptionsModel()->getDisplayUnit();
m_balances = balances;
ui->labelBalance->setText(BitcoinUnits::formatWithUnit(unit, balances.balance, false, BitcoinUnits::separatorAlways));
ui->labelUnconfirmed->setText(BitcoinUnits::formatWithUnit(unit, balances.unconfirmed_balance, false, BitcoinUnits::separatorAlways));
ui->labelImmature->setText(BitcoinUnits::formatWithUnit(unit, balances.immature_balance, false, BitcoinUnits::separatorAlways));
ui->labelTotal->setText(BitcoinUnits::formatWithUnit(unit, balances.balance + balances.unconfirmed_balance + balances.immature_balance, false, BitcoinUnits::separatorAlways));
ui->labelWatchAvailable->setText(BitcoinUnits::formatWithUnit(unit, balances.watch_only_balance, false, BitcoinUnits::separatorAlways));
ui->labelWatchPending->setText(BitcoinUnits::formatWithUnit(unit, balances.unconfirmed_watch_only_balance, false, BitcoinUnits::separatorAlways));
ui->labelWatchImmature->setText(BitcoinUnits::formatWithUnit(unit, balances.immature_watch_only_balance, false, BitcoinUnits::separatorAlways));
ui->labelWatchTotal->setText(BitcoinUnits::formatWithUnit(unit, balances.watch_only_balance + balances.unconfirmed_watch_only_balance + balances.immature_watch_only_balance, false, BitcoinUnits::separatorAlways));
ui->labelBalance->setText(BitcoinUnits::formatWithUnit(unit, valueFor(balances.balance, ::policyAsset), false, BitcoinUnits::separatorAlways));
ui->labelUnconfirmed->setText(BitcoinUnits::formatWithUnit(unit, valueFor(balances.unconfirmed_balance, ::policyAsset), false, BitcoinUnits::separatorAlways));
ui->labelImmature->setText(BitcoinUnits::formatWithUnit(unit, valueFor(balances.immature_balance, ::policyAsset), false, BitcoinUnits::separatorAlways));
ui->labelTotal->setText(BitcoinUnits::formatWithUnit(unit, valueFor(balances.balance, ::policyAsset) + valueFor(balances.unconfirmed_balance, ::policyAsset) + valueFor(balances.immature_balance, ::policyAsset), false, BitcoinUnits::separatorAlways));
ui->labelWatchAvailable->setText(BitcoinUnits::formatWithUnit(unit, valueFor(balances.watch_only_balance, ::policyAsset), false, BitcoinUnits::separatorAlways));
ui->labelWatchPending->setText(BitcoinUnits::formatWithUnit(unit, valueFor(balances.unconfirmed_watch_only_balance, ::policyAsset), false, BitcoinUnits::separatorAlways));
ui->labelWatchImmature->setText(BitcoinUnits::formatWithUnit(unit, valueFor(balances.immature_watch_only_balance, ::policyAsset), false, BitcoinUnits::separatorAlways));
ui->labelWatchTotal->setText(BitcoinUnits::formatWithUnit(unit, valueFor(balances.watch_only_balance, ::policyAsset) + valueFor(balances.unconfirmed_watch_only_balance, ::policyAsset) + valueFor(balances.immature_watch_only_balance, ::policyAsset), false, BitcoinUnits::separatorAlways));

// only show immature (newly mined) balance if it's non-zero, so as not to complicate things
// for the non-mining users
bool showImmature = balances.immature_balance != 0;
bool showWatchOnlyImmature = balances.immature_watch_only_balance != 0;
bool showImmature = valueFor(balances.immature_balance, ::policyAsset) != 0;
bool showWatchOnlyImmature = valueFor(balances.immature_watch_only_balance, ::policyAsset) != 0;

// for symmetry reasons also show immature label when the watch-only one is shown
ui->labelImmature->setVisible(showImmature || showWatchOnlyImmature);
Expand Down Expand Up @@ -243,7 +245,7 @@ void OverviewPage::updateDisplayUnit()
{
if(walletModel && walletModel->getOptionsModel())
{
if (m_balances.balance != -1) {
if (m_balances.balance[::policyAsset] != -1) {
setBalance(m_balances);
}

Expand Down
2 changes: 1 addition & 1 deletion src/qt/paymentserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@ bool PaymentServer::processPaymentRequest(const PaymentRequestPlus& request, Sen
}

// Extract and check amounts
CTxOut txOut(sendingTo.second, sendingTo.first);
CTxOut txOut(::policyAsset, sendingTo.second, sendingTo.first);
if (IsDust(txOut, optionsModel->node().getDustRelayFee())) {
Q_EMIT message(tr("Payment request error"), tr("Requested payment amount of %1 is too small (considered dust).")
.arg(BitcoinUnits::formatWithUnit(optionsModel->getDisplayUnit(), sendingTo.second)),
Expand Down
20 changes: 13 additions & 7 deletions src/qt/sendcoinsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <ui_interface.h>
#include <txmempool.h>
#include <policy/fees.h>
#include <policy/policy.h>
#include <wallet/fees.h>

#include <QFontMetrics>
Expand Down Expand Up @@ -526,7 +527,7 @@ void SendCoinsDialog::setBalance(const interfaces::WalletBalances& balances)
{
if(model && model->getOptionsModel())
{
ui->labelBalance->setText(BitcoinUnits::formatWithUnit(model->getOptionsModel()->getDisplayUnit(), balances.balance));
ui->labelBalance->setText(BitcoinUnits::formatWithUnit(model->getOptionsModel()->getDisplayUnit(), valueFor(balances.balance, ::policyAsset)));
}
}

Expand Down Expand Up @@ -618,7 +619,7 @@ void SendCoinsDialog::useAvailableBalance(SendCoinsEntry* entry)
}

// Calculate available amount to send.
CAmount amount = model->wallet().getAvailableBalance(coin_control);
CAmount amount = valueFor(model->wallet().getAvailableBalance(coin_control), ::policyAsset);
for (int i = 0; i < ui->entries->count(); ++i) {
SendCoinsEntry* e = qobject_cast<SendCoinsEntry*>(ui->entries->itemAt(i)->widget());
if (e && !e->isHidden() && e != entry) {
Expand Down Expand Up @@ -784,7 +785,8 @@ void SendCoinsDialog::coinControlChangeChecked(int state)
{
if (state == Qt::Unchecked)
{
CoinControlDialog::coinControl()->destChange = CNoDestination();
// ELEMENTS: it's a map now, should be initialized automatically
//CoinControlDialog::coinControl()->destChange = CNoDestination();
ui->labelCoinControlChangeLabel->clear();
}
else
Expand All @@ -800,7 +802,8 @@ void SendCoinsDialog::coinControlChangeEdited(const QString& text)
if (model && model->getAddressTableModel())
{
// Default to no change address until verified
CoinControlDialog::coinControl()->destChange = CNoDestination();
// ELEMENTS: it's a map now, should be initialized automatically
//CoinControlDialog::coinControl()->destChange = CNoDestination();
ui->labelCoinControlChangeLabel->setStyleSheet("QLabel{color:red;}");

const CTxDestination dest = DecodeDestination(text.toStdString());
Expand All @@ -822,8 +825,10 @@ void SendCoinsDialog::coinControlChangeEdited(const QString& text)
QMessageBox::StandardButton btnRetVal = QMessageBox::question(this, tr("Confirm custom change address"), tr("The address you selected for change is not part of this wallet. Any or all funds in your wallet may be sent to this address. Are you sure?"),
QMessageBox::Yes | QMessageBox::Cancel, QMessageBox::Cancel);

if(btnRetVal == QMessageBox::Yes)
CoinControlDialog::coinControl()->destChange = dest;
if(btnRetVal == QMessageBox::Yes) {
// ELEMENTS: it's a map now
//CoinControlDialog::coinControl()->destChange = dest;
}
else
{
ui->lineEditCoinControlChange->setText("");
Expand All @@ -842,7 +847,8 @@ void SendCoinsDialog::coinControlChangeEdited(const QString& text)
else
ui->labelCoinControlChangeLabel->setText(tr("(no label)"));

CoinControlDialog::coinControl()->destChange = dest;
// ELEMENTS: it's a map now
//CoinControlDialog::coinControl()->destChange = dest;
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/qt/signverifymessagedialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ void SignVerifyMessageDialog::on_signMessageButton_SM_clicked()
ui->statusLabel_SM->setText(tr("The entered address is invalid.") + QString(" ") + tr("Please check the address and try again."));
return;
}
const CKeyID* keyID = boost::get<CKeyID>(&destination);
const PKHash* keyID = boost::get<PKHash>(&destination);
if (!keyID) {
ui->addressIn_SM->setValid(false);
ui->statusLabel_SM->setStyleSheet("QLabel { color: red; }");
Expand All @@ -137,7 +137,7 @@ void SignVerifyMessageDialog::on_signMessageButton_SM_clicked()
}

CKey key;
if (!model->wallet().getPrivKey(*keyID, key))
if (!model->wallet().getPrivKey(CKeyID(*keyID), key))
{
ui->statusLabel_SM->setStyleSheet("QLabel { color: red; }");
ui->statusLabel_SM->setText(tr("Private key for the entered address is not available."));
Expand Down Expand Up @@ -198,7 +198,7 @@ void SignVerifyMessageDialog::on_verifyMessageButton_VM_clicked()
ui->statusLabel_VM->setText(tr("The entered address is invalid.") + QString(" ") + tr("Please check the address and try again."));
return;
}
if (!boost::get<CKeyID>(&destination)) {
if (!boost::get<PKHash>(&destination)) {
ui->addressIn_VM->setValid(false);
ui->statusLabel_VM->setStyleSheet("QLabel { color: red; }");
ui->statusLabel_VM->setText(tr("The entered address does not refer to a key.") + QString(" ") + tr("Please check the address and try again."));
Expand Down Expand Up @@ -229,7 +229,7 @@ void SignVerifyMessageDialog::on_verifyMessageButton_VM_clicked()
return;
}

if (!(CTxDestination(pubkey.GetID()) == destination)) {
if (!(CTxDestination(PKHash(pubkey.GetID())) == destination)) {
ui->statusLabel_VM->setStyleSheet("QLabel { color: red; }");
ui->statusLabel_VM->setText(QString("<nobr>") + tr("Message verification failed.") + QString("</nobr>"));
return;
Expand Down
7 changes: 4 additions & 3 deletions src/qt/test/wallettests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <qt/transactionview.h>
#include <qt/walletmodel.h>
#include <key_io.h>
#include <policy/policy.h>
#include <test/test_bitcoin.h>
#include <validation.h>
#include <wallet/wallet.h>
Expand Down Expand Up @@ -164,8 +165,8 @@ void TestGUI()
// Send two transactions, and verify they are added to transaction list.
TransactionTableModel* transactionTableModel = walletModel.getTransactionTableModel();
QCOMPARE(transactionTableModel->rowCount({}), 105);
uint256 txid1 = SendCoins(*wallet.get(), sendCoinsDialog, CKeyID(), 5 * COIN, false /* rbf */);
uint256 txid2 = SendCoins(*wallet.get(), sendCoinsDialog, CKeyID(), 10 * COIN, true /* rbf */);
uint256 txid1 = SendCoins(*wallet.get(), sendCoinsDialog, PKHash(), 5 * COIN, false /* rbf */);
uint256 txid2 = SendCoins(*wallet.get(), sendCoinsDialog, PKHash(), 10 * COIN, true /* rbf */);
QCOMPARE(transactionTableModel->rowCount({}), 107);
QVERIFY(FindTx(*transactionTableModel, txid1).isValid());
QVERIFY(FindTx(*transactionTableModel, txid2).isValid());
Expand All @@ -182,7 +183,7 @@ void TestGUI()
QLabel* balanceLabel = overviewPage.findChild<QLabel*>("labelBalance");
QString balanceText = balanceLabel->text();
int unit = walletModel.getOptionsModel()->getDisplayUnit();
CAmount balance = walletModel.wallet().getBalance();
CAmount balance = valueFor(walletModel.wallet().getBalance(), ::policyAsset);
QString balanceComparison = BitcoinUnits::formatWithUnit(unit, balance, false, BitcoinUnits::separatorAlways);
QCOMPARE(balanceText, balanceComparison);

Expand Down
Loading

0 comments on commit 5f9f578

Please sign in to comment.