Skip to content

Commit c39dd2e

Browse files
committed
Merge #12408: wallet: Change output type globals to members
fab8a6f wallet: Change output type globals to members (MarcoFalke) Pull request description: Output type is used by the wallet when generating addresses or transactions with change, thus it should be a member of `CWallet`. Moreover, in light of multiwallet, it makes sense to prepare for per-wallet attributes instead of for-all-wallets globals. Tree-SHA512: 4fa397cd82522e5bacf4870160a2a0f5e1f2dc046e4b9e2514dee18b187a0e1724d036315f77fa48e48f85533021d5e5525d798160a92d389d75512f3f9e1405
2 parents 6324c68 + fab8a6f commit c39dd2e

16 files changed

+84
-92
lines changed

src/qt/addresstablemodel.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,8 @@ int AddressTableModel::lookupAddress(const QString &address) const
441441
}
442442
}
443443

444+
OutputType AddressTableModel::GetDefaultAddressType() const { return wallet->m_default_address_type; };
445+
444446
void AddressTableModel::emitDataChanged(int idx)
445447
{
446448
Q_EMIT dataChanged(index(idx, 0, QModelIndex()), index(idx, columns.length()-1, QModelIndex()));

src/qt/addresstablemodel.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#include <QAbstractTableModel>
99
#include <QStringList>
1010

11-
enum OutputType : int;
11+
enum class OutputType;
1212

1313
class AddressTablePriv;
1414
class WalletModel;
@@ -76,6 +76,8 @@ class AddressTableModel : public QAbstractTableModel
7676

7777
EditStatus getEditStatus() const { return editStatus; }
7878

79+
OutputType GetDefaultAddressType() const;
80+
7981
private:
8082
WalletModel *walletModel;
8183
CWallet *wallet;

src/qt/editaddressdialog.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
#include <QDataWidgetMapper>
1212
#include <QMessageBox>
1313

14-
extern OutputType g_address_type;
1514

1615
EditAddressDialog::EditAddressDialog(Mode _mode, QWidget *parent) :
1716
QDialog(parent),
@@ -80,7 +79,7 @@ bool EditAddressDialog::saveCurrentRow()
8079
mode == NewSendingAddress ? AddressTableModel::Send : AddressTableModel::Receive,
8180
ui->labelEdit->text(),
8281
ui->addressEdit->text(),
83-
g_address_type);
82+
model->GetDefaultAddressType());
8483
break;
8584
case EditReceivingAddress:
8685
case EditSendingAddress:

src/qt/paymentserver.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -643,7 +643,7 @@ void PaymentServer::fetchPaymentACK(CWallet* wallet, const SendCoinsRecipient& r
643643
// use for change. Despite an actual payment and not change, this is a close match:
644644
// it's the output type we use subject to privacy issues, but not restricted by what
645645
// other software supports.
646-
const OutputType change_type = g_change_type != OUTPUT_TYPE_NONE ? g_change_type : g_address_type;
646+
const OutputType change_type = wallet->m_default_change_type != OutputType::NONE ? wallet->m_default_change_type : wallet->m_default_address_type;
647647
wallet->LearnRelatedScripts(newKey, change_type);
648648
CTxDestination dest = GetDestinationForKey(newKey, change_type);
649649
wallet->SetAddressBook(dest, strAccount, "refund");

src/qt/receivecoinsdialog.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,13 @@ void ReceiveCoinsDialog::setModel(WalletModel *_model)
9595
columnResizingFixer = new GUIUtil::TableViewLastColumnResizingFixer(tableView, AMOUNT_MINIMUM_COLUMN_WIDTH, DATE_COLUMN_WIDTH, this);
9696

9797
// configure bech32 checkbox, disable if launched with legacy as default:
98-
if (model->getDefaultAddressType() == OUTPUT_TYPE_BECH32) {
98+
if (model->getDefaultAddressType() == OutputType::BECH32) {
9999
ui->useBech32->setCheckState(Qt::Checked);
100100
} else {
101101
ui->useBech32->setCheckState(Qt::Unchecked);
102102
}
103103

104-
ui->useBech32->setVisible(model->getDefaultAddressType() != OUTPUT_TYPE_LEGACY);
104+
ui->useBech32->setVisible(model->getDefaultAddressType() != OutputType::LEGACY);
105105
}
106106
}
107107

@@ -145,8 +145,8 @@ void ReceiveCoinsDialog::on_receiveButton_clicked()
145145
QString label = ui->reqLabel->text();
146146
/* Generate new receiving address */
147147
OutputType address_type = model->getDefaultAddressType();
148-
if (address_type != OUTPUT_TYPE_LEGACY) {
149-
address_type = ui->useBech32->isChecked() ? OUTPUT_TYPE_BECH32 : OUTPUT_TYPE_P2SH_SEGWIT;
148+
if (address_type != OutputType::LEGACY) {
149+
address_type = ui->useBech32->isChecked() ? OutputType::BECH32 : OutputType::P2SH_SEGWIT;
150150
}
151151
address = model->getAddressTableModel()->addRow(AddressTableModel::Receive, label, "", address_type);
152152
SendCoinsRecipient info(address, label,

src/qt/test/wallettests.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,6 @@ void BumpFee(TransactionView& view, const uint256& txid, bool expectDisabled, st
150150
// src/qt/test/test_bitcoin-qt -platform cocoa # macOS
151151
void TestGUI()
152152
{
153-
g_address_type = OUTPUT_TYPE_P2SH_SEGWIT;
154-
g_change_type = OUTPUT_TYPE_P2SH_SEGWIT;
155-
156153
// Set up wallet and chain with 105 blocks (5 mature blocks for spending).
157154
TestChain100Setup test;
158155
for (int i = 0; i < 5; ++i) {
@@ -163,7 +160,7 @@ void TestGUI()
163160
wallet.LoadWallet(firstRun);
164161
{
165162
LOCK(wallet.cs_wallet);
166-
wallet.SetAddressBook(GetDestinationForKey(test.coinbaseKey.GetPubKey(), g_address_type), "", "receive");
163+
wallet.SetAddressBook(GetDestinationForKey(test.coinbaseKey.GetPubKey(), wallet.m_default_address_type), "", "receive");
167164
wallet.AddKeyPubKey(test.coinbaseKey, test.coinbaseKey.GetPubKey());
168165
}
169166
{

src/qt/walletmodel.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -736,7 +736,7 @@ bool WalletModel::hdEnabled() const
736736

737737
OutputType WalletModel::getDefaultAddressType() const
738738
{
739-
return g_address_type;
739+
return wallet->m_default_address_type;
740740
}
741741

742742
int WalletModel::getDefaultConfirmTarget() const

src/qt/walletmodel.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
#include <QObject>
2222

23-
enum OutputType : int;
23+
enum class OutputType;
2424

2525
class AddressTableModel;
2626
class OptionsModel;

src/wallet/coincontrol.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ class CCoinControl
1818
public:
1919
//! Custom change destination, if not set an address is generated
2020
CTxDestination destChange;
21-
//! Custom change type, ignored if destChange is set, defaults to g_change_type
22-
OutputType change_type;
21+
//! Override the default change type if set, ignored if destChange is set
22+
boost::optional<OutputType> m_change_type;
2323
//! If false, allows unselected inputs, but requires all selected inputs be used
2424
bool fAllowOtherInputs;
2525
//! Includes watch only addresses which match the ISMINE_WATCH_SOLVABLE criteria
@@ -43,7 +43,7 @@ class CCoinControl
4343
void SetNull()
4444
{
4545
destChange = CNoDestination();
46-
change_type = g_change_type;
46+
m_change_type.reset();
4747
fAllowOtherInputs = false;
4848
fAllowWatchOnly = false;
4949
setSelected.clear();

src/wallet/init.cpp

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
std::string GetWalletHelpString(bool showDebug)
1818
{
1919
std::string strUsage = HelpMessageGroup(_("Wallet options:"));
20-
strUsage += HelpMessageOpt("-addresstype", strprintf("What type of addresses to use (\"legacy\", \"p2sh-segwit\", or \"bech32\", default: \"%s\")", FormatOutputType(OUTPUT_TYPE_DEFAULT)));
20+
strUsage += HelpMessageOpt("-addresstype", strprintf("What type of addresses to use (\"legacy\", \"p2sh-segwit\", or \"bech32\", default: \"%s\")", FormatOutputType(DEFAULT_ADDRESS_TYPE)));
2121
strUsage += HelpMessageOpt("-changetype", "What type of change to use (\"legacy\", \"p2sh-segwit\", or \"bech32\"). Default is same as -addresstype, except when -addresstype=p2sh-segwit a native segwit output is used when sending to a native segwit address)");
2222
strUsage += HelpMessageOpt("-disablewallet", _("Do not load the wallet and disable wallet RPC calls"));
2323
strUsage += HelpMessageOpt("-discardfee=<amt>", strprintf(_("The fee rate (in %s/kB) that indicates your tolerance for discarding change by adding it to the fee (default: %s). "
@@ -181,18 +181,6 @@ bool WalletParameterInteraction()
181181
bSpendZeroConfChange = gArgs.GetBoolArg("-spendzeroconfchange", DEFAULT_SPEND_ZEROCONF_CHANGE);
182182
fWalletRbf = gArgs.GetBoolArg("-walletrbf", DEFAULT_WALLET_RBF);
183183

184-
g_address_type = ParseOutputType(gArgs.GetArg("-addresstype", ""));
185-
if (g_address_type == OUTPUT_TYPE_NONE) {
186-
return InitError(strprintf("Unknown address type '%s'", gArgs.GetArg("-addresstype", "")));
187-
}
188-
189-
// If changetype is set in config file or parameter, check that it's valid.
190-
// Default to OUTPUT_TYPE_NONE if not set.
191-
g_change_type = ParseOutputType(gArgs.GetArg("-changetype", ""), OUTPUT_TYPE_NONE);
192-
if (g_change_type == OUTPUT_TYPE_NONE && !gArgs.GetArg("-changetype", "").empty()) {
193-
return InitError(strprintf("Unknown change type '%s'", gArgs.GetArg("-changetype", "")));
194-
}
195-
196184
return true;
197185
}
198186

0 commit comments

Comments
 (0)