Skip to content

Commit 93d1aa9

Browse files
committed
rpcwallet: add 'ischange' field to 'getaddressinfo' response
1 parent f504a14 commit 93d1aa9

File tree

4 files changed

+13
-2
lines changed

4 files changed

+13
-2
lines changed

doc/release-notes-14282.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@ Low-level RPC changes
44
`-usehd` was removed in version 0.16. From that version onwards, all new
55
wallets created are hierarchical deterministic wallets. Version 0.18 makes
66
specifying `-usehd` invalid config.
7+
8+
`ischange` field of boolean type that shows if an address was used for change
9+
output was added to `getaddressinfo` method response.

src/wallet/rpcwallet.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3540,6 +3540,7 @@ UniValue getaddressinfo(const JSONRPCRequest& request)
35403540
" \"ismine\" : true|false, (boolean) If the address is yours or not\n"
35413541
" \"iswatchonly\" : true|false, (boolean) If the address is watchonly\n"
35423542
" \"isscript\" : true|false, (boolean) If the key is a script\n"
3543+
" \"ischange\" : true|false, (boolean) If the address was used for change output\n"
35433544
" \"iswitness\" : true|false, (boolean) If the address is a witness address\n"
35443545
" \"witness_version\" : version (numeric, optional) The version number of the witness program\n"
35453546
" \"witness_program\" : \"hex\" (string, optional) The hex value of the witness program\n"
@@ -3597,6 +3598,7 @@ UniValue getaddressinfo(const JSONRPCRequest& request)
35973598
if (pwallet->mapAddressBook.count(dest)) {
35983599
ret.pushKV("label", pwallet->mapAddressBook[dest].name);
35993600
}
3601+
ret.pushKV("ischange", pwallet->IsChange(scriptPubKey));
36003602
const CKeyMetadata* meta = nullptr;
36013603
CKeyID key_id = GetKeyForDestination(*pwallet, dest);
36023604
if (!key_id.IsNull()) {

src/wallet/wallet.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1261,6 +1261,11 @@ CAmount CWallet::GetCredit(const CTxOut& txout, const isminefilter& filter) cons
12611261
}
12621262

12631263
bool CWallet::IsChange(const CTxOut& txout) const
1264+
{
1265+
return IsChange(txout.scriptPubKey);
1266+
}
1267+
1268+
bool CWallet::IsChange(const CScript& script) const
12641269
{
12651270
// TODO: fix handling of 'change' outputs. The assumption is that any
12661271
// payment to a script that is ours, but is not in the address book
@@ -1269,10 +1274,10 @@ bool CWallet::IsChange(const CTxOut& txout) const
12691274
// a better way of identifying which outputs are 'the send' and which are
12701275
// 'the change' will need to be implemented (maybe extend CWalletTx to remember
12711276
// which output, if any, was change).
1272-
if (::IsMine(*this, txout.scriptPubKey))
1277+
if (::IsMine(*this, script))
12731278
{
12741279
CTxDestination address;
1275-
if (!ExtractDestination(txout.scriptPubKey, address))
1280+
if (!ExtractDestination(script, address))
12761281
return true;
12771282

12781283
LOCK(cs_wallet);

src/wallet/wallet.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -961,6 +961,7 @@ class CWallet final : public CCryptoKeyStore, public CValidationInterface
961961
isminetype IsMine(const CTxOut& txout) const;
962962
CAmount GetCredit(const CTxOut& txout, const isminefilter& filter) const;
963963
bool IsChange(const CTxOut& txout) const;
964+
bool IsChange(const CScript& script) const;
964965
CAmount GetChange(const CTxOut& txout) const;
965966
bool IsMine(const CTransaction& tx) const;
966967
/** should probably be renamed to IsRelevantToMe */

0 commit comments

Comments
 (0)