Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backports 0.17 pr29 #4173

Merged
merged 11 commits into from
May 25, 2021
7 changes: 6 additions & 1 deletion src/Makefile.qttest.include
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,17 @@ TEST_QT_MOC_CPP = \

if ENABLE_WALLET
TEST_QT_MOC_CPP += \
qt/test/moc_addressbooktests.cpp \
qt/test/moc_paymentservertests.cpp \
qt/test/moc_wallettests.cpp
endif

TEST_QT_H = \
qt/test/addressbooktests.h \
qt/test/compattests.h \
qt/test/rpcnestedtests.h \
qt/test/uritests.h \
qt/test/util.h \
qt/test/paymentrequestdata.h \
qt/test/paymentservertests.h \
qt/test/trafficgraphdatatests.h \
Expand All @@ -39,13 +42,15 @@ qt_test_test_dash_qt_SOURCES = \
qt/test/compattests.cpp \
qt/test/rpcnestedtests.cpp \
qt/test/test_main.cpp \
qt/test/uritests.cpp \
qt/test/trafficgraphdatatests.cpp \
qt/test/uritests.cpp \
qt/test/util.cpp \
$(TEST_QT_H) \
$(TEST_BITCOIN_CPP) \
$(TEST_BITCOIN_H)
if ENABLE_WALLET
qt_test_test_dash_qt_SOURCES += \
qt/test/addressbooktests.cpp \
qt/test/paymentservertests.cpp \
qt/test/wallettests.cpp \
wallet/test/wallet_test_fixture.cpp
Expand Down
2 changes: 1 addition & 1 deletion src/bench/bench_dash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ int main(int argc, char** argv)
SetupBenchArgs();
gArgs.ParseParameters(argc, argv);

if (gArgs.IsArgSet("-?") || gArgs.IsArgSet("-h") || gArgs.IsArgSet("-help")) {
if (HelpRequested(gArgs)) {
std::cout << gArgs.GetHelpMessage();

return 0;
Expand Down
6 changes: 3 additions & 3 deletions src/coinjoin/coinjoin-util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,9 @@ CTransactionBuilder::CTransactionBuilder(std::shared_ptr<CWallet> pwalletIn, con
tallyItem(tallyItemIn)
{
// Generate a feerate which will be used to consider if the remainder is dust and will go into fees or not
coinControl.m_discard_feerate = ::GetDiscardRate(::feeEstimator);
coinControl.m_discard_feerate = ::GetDiscardRate(*pwallet.get(), ::feeEstimator);
// Generate a feerate which will be used by calculations of this class and also by CWallet::CreateTransaction
coinControl.m_feerate = std::max(::feeEstimator.estimateSmartFee((int)::nTxConfirmTarget, nullptr, true), payTxFee);
coinControl.m_feerate = std::max(::feeEstimator.estimateSmartFee((int)pwallet->m_confirm_target, nullptr, true), pwallet->m_pay_tx_fee);
// Change always goes back to origin
coinControl.destChange = tallyItemIn.txdest;
// Only allow tallyItems inputs for tx creation
Expand Down Expand Up @@ -239,7 +239,7 @@ CAmount CTransactionBuilder::GetAmountUsed() const
CAmount CTransactionBuilder::GetFee(unsigned int nBytes) const
{
CAmount nFeeCalc = coinControl.m_feerate->GetFee(nBytes);
CAmount nRequiredFee = GetRequiredFee(nBytes);
CAmount nRequiredFee = GetRequiredFee(*pwallet.get(), nBytes);
if (nRequiredFee > nFeeCalc) {
nFeeCalc = nRequiredFee;
}
Expand Down
2 changes: 1 addition & 1 deletion src/dash-cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ static int AppInitRPC(int argc, char* argv[])
return true;
}

if (argc<2 || gArgs.IsArgSet("-?") || gArgs.IsArgSet("-h") || gArgs.IsArgSet("-help") || gArgs.IsArgSet("-version")) {
if (argc < 2 || HelpRequested(gArgs) || gArgs.IsArgSet("-version")) {
std::string strUsage = strprintf("%s RPC client version", PACKAGE_NAME) + " " + FormatFullVersion() + "\n";
if (!gArgs.IsArgSet("-version")) {
strUsage += "\nUsage:\n"
Expand Down
3 changes: 1 addition & 2 deletions src/dash-tx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,7 @@ static int AppInitRawTx(int argc, char* argv[])

fCreateBlank = gArgs.GetBoolArg("-create", false);

if (argc<2 || gArgs.IsArgSet("-?") || gArgs.IsArgSet("-h") || gArgs.IsArgSet("-help"))
{
if (argc < 2 || HelpRequested(gArgs)) {
// First part of help message is specific to this utility
std::string strUsage = strprintf("%s dash-tx utility version", PACKAGE_NAME) + " " + FormatFullVersion() + "\n\n" +
"Usage:\n"
Expand Down
3 changes: 1 addition & 2 deletions src/dashd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,7 @@ bool AppInit(int argc, char* argv[])
}

// Process help and version before taking care about datadir
if (gArgs.IsArgSet("-?") || gArgs.IsArgSet("-h") || gArgs.IsArgSet("-help") || gArgs.IsArgSet("-version"))
{
if (HelpRequested(gArgs) || gArgs.IsArgSet("-version")) {
std::string strUsage = strprintf("%s Daemon", PACKAGE_NAME) + " version " + FormatFullVersion() + "\n";

if (gArgs.IsArgSet("-version"))
Expand Down
14 changes: 0 additions & 14 deletions src/interfaces/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -311,20 +311,6 @@ class NodeImpl : public Node
}
}
bool getNetworkActive() override { return g_connman && g_connman->GetNetworkActive(); }
unsigned int getTxConfirmTarget() override { CHECK_WALLET(return ::nTxConfirmTarget); }
CAmount getRequiredFee(unsigned int tx_bytes) override { CHECK_WALLET(return GetRequiredFee(tx_bytes)); }
CAmount getMinimumFee(unsigned int tx_bytes,
const CCoinControl& coin_control,
int* returned_target,
FeeReason* reason) override
{
FeeCalculation fee_calc;
CAmount result;
CHECK_WALLET(result = GetMinimumFee(tx_bytes, coin_control, ::mempool, ::feeEstimator, &fee_calc));
if (returned_target) *returned_target = fee_calc.returnedTarget;
if (reason) *reason = fee_calc.reason;
return result;
}
CAmount getMaxTxFee() override { return ::maxTxFee; }
CFeeRate estimateSmartFee(int num_blocks, bool conservative, int* returned_target = nullptr) override
{
Expand Down
14 changes: 0 additions & 14 deletions src/interfaces/node.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,9 @@ class Coin;
class RPCTimerInterface;
class UniValue;
class proxyType;
enum class FeeReason;
struct CNodeStateStats;

namespace interfaces {

class Handler;
class Wallet;

Expand Down Expand Up @@ -209,18 +207,6 @@ class Node
//! Get network active.
virtual bool getNetworkActive() = 0;

//! Get tx confirm target.
virtual unsigned int getTxConfirmTarget() = 0;

//! Get required fee.
virtual CAmount getRequiredFee(unsigned int tx_bytes) = 0;

//! Get minimum fee.
virtual CAmount getMinimumFee(unsigned int tx_bytes,
const CCoinControl& coin_control,
int* returned_target,
FeeReason* reason) = 0;

//! Get max tx fee.
virtual CAmount getMaxTxFee() = 0;

Expand Down
25 changes: 24 additions & 1 deletion src/interfaces/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
#include <consensus/validation.h>
#include <interfaces/handler.h>
#include <net.h>
#include <policy/feerate.h>
#include <policy/fees.h>
#include <policy/policy.h>
#include <primitives/transaction.h>
#include <script/ismine.h>
Expand All @@ -21,6 +23,7 @@
#include <ui_interface.h>
#include <uint256.h>
#include <validation.h>
#include <wallet/fees.h>
#include <wallet/wallet.h>

#include <memory>
Expand Down Expand Up @@ -219,7 +222,10 @@ class WalletImpl : public Wallet
{
return m_wallet.DelAddressBook(dest);
}
bool getAddress(const CTxDestination& dest, std::string* name, isminetype* is_mine) override
bool getAddress(const CTxDestination& dest,
std::string* name,
isminetype* is_mine,
std::string* purpose) override
{
LOCK(m_wallet.cs_wallet);
auto it = m_wallet.mapAddressBook.find(dest);
Expand All @@ -232,6 +238,9 @@ class WalletImpl : public Wallet
if (is_mine) {
*is_mine = IsMine(m_wallet, dest);
}
if (purpose) {
*purpose = it->second.purpose;
}
return true;
}
std::vector<WalletAddress> getAddresses() override
Expand Down Expand Up @@ -482,6 +491,20 @@ class WalletImpl : public Wallet
}
return result;
}
CAmount getRequiredFee(unsigned int tx_bytes) override { return GetRequiredFee(m_wallet, tx_bytes); }
CAmount getMinimumFee(unsigned int tx_bytes,
const CCoinControl& coin_control,
int* returned_target,
FeeReason* reason) override
{
FeeCalculation fee_calc;
CAmount result;
result = GetMinimumFee(m_wallet, tx_bytes, coin_control, ::mempool, ::feeEstimator, &fee_calc);
if (returned_target) *returned_target = fee_calc.returnedTarget;
if (reason) *reason = fee_calc.reason;
return result;
}
unsigned int getConfirmTarget() override { return m_wallet.m_confirm_target; }
bool hdEnabled() override { return m_wallet.IsHDEnabled(); }
CoinJoin::Client& coinJoin() override { return m_coinjoin; }
std::unique_ptr<Handler> handleUnload(UnloadFn fn) override
Expand Down
19 changes: 17 additions & 2 deletions src/interfaces/wallet.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@
#include <vector>

class CCoinControl;
class CFeeRate;
class CKey;
class CWallet;
enum class FeeReason;
struct CRecipient;

namespace interfaces {
Expand Down Expand Up @@ -125,8 +127,9 @@ class Wallet

//! Look up address in wallet, return whether exists.
virtual bool getAddress(const CTxDestination& dest,
std::string* name = nullptr,
isminetype* is_mine = nullptr) = 0;
std::string* name,
isminetype* is_mine,
std::string* purpose) = 0;

//! Get wallet address list.
virtual std::vector<WalletAddress> getAddresses() = 0;
Expand Down Expand Up @@ -244,6 +247,18 @@ class Wallet
//! Return wallet transaction output information.
virtual std::vector<WalletTxOut> getCoins(const std::vector<COutPoint>& outputs) = 0;

//! Get required fee.
virtual CAmount getRequiredFee(unsigned int tx_bytes) = 0;

//! Get minimum fee.
virtual CAmount getMinimumFee(unsigned int tx_bytes,
const CCoinControl& coin_control,
int* returned_target,
FeeReason* reason) = 0;

//! Get tx confirm target.
virtual unsigned int getConfirmTarget() = 0;

// Return whether HD enabled.
virtual bool hdEnabled() = 0;

Expand Down
2 changes: 1 addition & 1 deletion src/qt/addressbookpage.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class AddressBookPage : public QDialog
ForEditing /**< Open address book for editing */
};

explicit AddressBookPage(Mode mode, Tabs tab, QWidget* parent);
explicit AddressBookPage(Mode mode, Tabs tab, QWidget* parent = 0);
~AddressBookPage();

void setModel(AddressTableModel *model);
Expand Down
34 changes: 20 additions & 14 deletions src/qt/addresstablemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,8 @@ bool AddressTableModel::setData(const QModelIndex &index, const QVariant &value,
}
// Check for duplicate addresses to prevent accidental deletion of addresses, if you try
// to paste an existing address over another address (with a different label)
if (walletModel->wallet().getAddress(newAddress))
if (walletModel->wallet().getAddress(
newAddress, /* name= */ nullptr, /* is_mine= */ nullptr, /* purpose= */ nullptr))
{
editStatus = DUPLICATE_ADDRESS;
return false;
Expand Down Expand Up @@ -351,7 +352,8 @@ QString AddressTableModel::addRow(const QString &type, const QString &label, con
}
// Check for duplicate addresses
{
if(walletModel->wallet().getAddress(DecodeDestination(strAddress)))
if (walletModel->wallet().getAddress(
DecodeDestination(strAddress), /* name= */ nullptr, /* is_mine= */ nullptr, /* purpose= */ nullptr))
{
editStatus = DUPLICATE_ADDRESS;
return QString();
Expand Down Expand Up @@ -404,27 +406,31 @@ bool AddressTableModel::removeRows(int row, int count, const QModelIndex &parent
return true;
}

/* Look up label for address in address book, if not found return empty string.
*/
QString AddressTableModel::labelForAddress(const QString &address) const
{
CTxDestination dest = DecodeDestination(address.toStdString());
return labelForDestination(dest);
std::string name;
if (getAddressData(address, &name, /* purpose= */ nullptr)) {
return QString::fromStdString(name);
}
return QString();
}


QString AddressTableModel::labelForDestination(const CTxDestination &dest) const
QString AddressTableModel::purposeForAddress(const QString &address) const
{
{
std::string name;
if (walletModel->wallet().getAddress(dest, &name))
{
return QString::fromStdString(name);
}
std::string purpose;
if (getAddressData(address, /* name= */ nullptr, &purpose)) {
return QString::fromStdString(purpose);
}
return QString();
}

bool AddressTableModel::getAddressData(const QString &address,
std::string* name,
std::string* purpose) const {
CTxDestination destination = DecodeDestination(address.toStdString());
return walletModel->wallet().getAddress(destination, name, /* is_mine= */ nullptr, purpose);
}
PastaPastaPasta marked this conversation as resolved.
Show resolved Hide resolved

int AddressTableModel::lookupAddress(const QString &address) const
{
QModelIndexList lst = match(index(0, Address, QModelIndex()),
Expand Down
10 changes: 7 additions & 3 deletions src/qt/addresstablemodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,11 @@ class AddressTableModel : public QAbstractTableModel
*/
QString addRow(const QString &type, const QString &label, const QString &address);

/* Look up label for address in address book, if not found return empty string.
*/
/** Look up label for address in address book, if not found return empty string. */
QString labelForAddress(const QString &address) const;
QString labelForDestination(const CTxDestination &dest) const;

/** Look up purpose for address in address book, if not found return empty string. */
QString purposeForAddress(const QString &address) const;

/* Look up row index of an address in the model.
Return -1 if not found.
Expand All @@ -85,6 +86,9 @@ class AddressTableModel : public QAbstractTableModel
QStringList columns;
EditStatus editStatus;

/** Look up address book data given an address string. */
bool getAddressData(const QString &address, std::string* name, std::string* purpose) const;

/** Notify listeners that data changed. */
void emitDataChanged(int index);

Expand Down
2 changes: 1 addition & 1 deletion src/qt/coincontroldialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ void CoinControlDialog::updateLabels(CCoinControl& m_coin_control, WalletModel *
nBytes -= 34;

// Fee
nPayFee = model->node().getMinimumFee(nBytes, m_coin_control, nullptr /* returned_target */, nullptr /* reason */);
nPayFee = model->wallet().getMinimumFee(nBytes, m_coin_control, nullptr /* returned_target */, nullptr /* reason */);

if (nPayAmount > 0)
{
Expand Down
3 changes: 1 addition & 2 deletions src/qt/dash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -635,8 +635,7 @@ int main(int argc, char *argv[])

// Show help message immediately after parsing command-line options (for "-lang") and setting locale,
// but before showing splash screen.
if (gArgs.IsArgSet("-?") || gArgs.IsArgSet("-h") || gArgs.IsArgSet("-help") || gArgs.IsArgSet("-version"))
{
if (HelpRequested(gArgs) || gArgs.IsArgSet("-version")) {
HelpMessageDialog help(*node, nullptr, gArgs.IsArgSet("-version") ? HelpMessageDialog::about : HelpMessageDialog::cmdline);
help.showOrPrint();
return EXIT_SUCCESS;
Expand Down
21 changes: 20 additions & 1 deletion src/qt/editaddressdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ void EditAddressDialog::accept()
break;
case AddressTableModel::DUPLICATE_ADDRESS:
QMessageBox::warning(this, windowTitle(),
tr("The entered address \"%1\" is already in the address book.").arg(ui->addressEdit->text()),
getDuplicateAddressWarning(),
QMessageBox::Ok, QMessageBox::Ok);
break;
case AddressTableModel::WALLET_UNLOCK_FAILURE:
Expand All @@ -134,6 +134,25 @@ void EditAddressDialog::accept()
QDialog::accept();
}

QString EditAddressDialog::getDuplicateAddressWarning() const
{
QString dup_address = ui->addressEdit->text();
QString existing_label = model->labelForAddress(dup_address);
QString existing_purpose = model->purposeForAddress(dup_address);

if (existing_purpose == "receive" &&
(mode == NewSendingAddress || mode == EditSendingAddress)) {
return tr(
"Address \"%1\" already exists as a receiving address with label "
"\"%2\" and so cannot be added as a sending address."
).arg(dup_address).arg(existing_label);
}
return tr(
"The entered address \"%1\" is already in the address book with "
"label \"%2\"."
).arg(dup_address).arg(existing_label);
}

QString EditAddressDialog::getAddress() const
{
return address;
Expand Down
Loading