Skip to content

Commit 38c2647

Browse files
committed
Add ChangeAddressType method
Suggested #12729 (comment)
1 parent 4d7a7a9 commit 38c2647

File tree

6 files changed

+18
-5
lines changed

6 files changed

+18
-5
lines changed

src/interface/wallet.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ class WalletImpl : public Wallet
406406
}
407407
bool hdEnabled() override { return m_wallet.IsHDEnabled(); }
408408
OutputType getDefaultAddressType() override { return m_wallet.m_default_address_type; }
409-
OutputType getDefaultChangeType() override { return m_wallet.m_default_change_type; }
409+
OutputType getChangeAddressType() override { return m_wallet.ChangeAddressType(); }
410410
std::unique_ptr<Handler> handleShowProgress(ShowProgressFn fn) override
411411
{
412412
return MakeHandler(m_wallet.ShowProgress.connect(fn));

src/interface/wallet.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,8 +221,8 @@ class Wallet
221221
// Get default address type.
222222
virtual OutputType getDefaultAddressType() = 0;
223223

224-
// Get default change type.
225-
virtual OutputType getDefaultChangeType() = 0;
224+
// Get change type to use for a new address.
225+
virtual OutputType getChangeAddressType() = 0;
226226

227227
//! Register handler for show progress messages.
228228
using ShowProgressFn = std::function<void(const std::string& title, int progress)>;

src/qt/paymentserver.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -648,7 +648,7 @@ void PaymentServer::fetchPaymentACK(WalletModel* walletModel, const SendCoinsRec
648648
// use for change. Despite an actual payment and not change, this is a close match:
649649
// it's the output type we use subject to privacy issues, but not restricted by what
650650
// other software supports.
651-
const OutputType change_type = walletModel->wallet().getDefaultChangeType() != OutputType::CHANGE_AUTO ? walletModel->wallet().getDefaultChangeType() : walletModel->wallet().getDefaultAddressType();
651+
const OutputType change_type = walletModel->wallet().getChangeAddressType();
652652
walletModel->wallet().learnRelatedScripts(newKey, change_type);
653653
CTxDestination dest = GetDestinationForKey(newKey, change_type);
654654
std::string label = tr("Refund from %1").arg(recipient.authenticatedMerchant).toStdString();

src/wallet/rpcwallet.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ UniValue getrawchangeaddress(const JSONRPCRequest& request)
258258
pwallet->TopUpKeyPool();
259259
}
260260

261-
OutputType output_type = pwallet->m_default_change_type != OutputType::CHANGE_AUTO ? pwallet->m_default_change_type : pwallet->m_default_address_type;
261+
OutputType output_type = pwallet->ChangeAddressType();
262262
if (!request.params[0].isNull()) {
263263
if (!ParseOutputType(request.params[0].get_str(), output_type)) {
264264
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, strprintf("Unknown address type '%s'", request.params[0].get_str()));

src/wallet/wallet.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2673,6 +2673,11 @@ OutputType CWallet::TransactionChangeType(OutputType change_type, const std::vec
26732673
return m_default_address_type;
26742674
}
26752675

2676+
OutputType CWallet::ChangeAddressType() const
2677+
{
2678+
return m_default_change_type != OutputType::CHANGE_AUTO ? m_default_change_type : m_default_address_type;
2679+
}
2680+
26762681
bool CWallet::CreateTransaction(const std::vector<CRecipient>& vecSend, CTransactionRef& tx, CReserveKey& reservekey, CAmount& nFeeRet,
26772682
int& nChangePosInOut, std::string& strFailReason, const CCoinControl& coin_control, bool sign)
26782683
{

src/wallet/wallet.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -963,8 +963,16 @@ class CWallet final : public CCryptoKeyStore, public CValidationInterface
963963
CAmount GetLegacyBalance(const isminefilter& filter, int minDepth, const std::string* account) const;
964964
CAmount GetAvailableBalance(const CCoinControl* coinControl = nullptr) const;
965965

966+
/**
967+
* Return change type to use for a new transaction.
968+
*/
966969
OutputType TransactionChangeType(OutputType change_type, const std::vector<CRecipient>& vecSend);
967970

971+
/**
972+
* Return change type to use for a new address.
973+
*/
974+
OutputType ChangeAddressType() const;
975+
968976
/**
969977
* Insert additional inputs into the transaction by
970978
* calling CreateTransaction();

0 commit comments

Comments
 (0)