mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-25 10:43:19 -03:00
rpcwallet: add 'ischange' field to 'getaddressinfo' response
This commit is contained in:
parent
f504a1402a
commit
93d1aa9abc
4 changed files with 13 additions and 2 deletions
|
@ -4,3 +4,6 @@ Low-level RPC changes
|
|||
`-usehd` was removed in version 0.16. From that version onwards, all new
|
||||
wallets created are hierarchical deterministic wallets. Version 0.18 makes
|
||||
specifying `-usehd` invalid config.
|
||||
|
||||
`ischange` field of boolean type that shows if an address was used for change
|
||||
output was added to `getaddressinfo` method response.
|
||||
|
|
|
@ -3540,6 +3540,7 @@ UniValue getaddressinfo(const JSONRPCRequest& request)
|
|||
" \"ismine\" : true|false, (boolean) If the address is yours or not\n"
|
||||
" \"iswatchonly\" : true|false, (boolean) If the address is watchonly\n"
|
||||
" \"isscript\" : true|false, (boolean) If the key is a script\n"
|
||||
" \"ischange\" : true|false, (boolean) If the address was used for change output\n"
|
||||
" \"iswitness\" : true|false, (boolean) If the address is a witness address\n"
|
||||
" \"witness_version\" : version (numeric, optional) The version number of the witness program\n"
|
||||
" \"witness_program\" : \"hex\" (string, optional) The hex value of the witness program\n"
|
||||
|
@ -3597,6 +3598,7 @@ UniValue getaddressinfo(const JSONRPCRequest& request)
|
|||
if (pwallet->mapAddressBook.count(dest)) {
|
||||
ret.pushKV("label", pwallet->mapAddressBook[dest].name);
|
||||
}
|
||||
ret.pushKV("ischange", pwallet->IsChange(scriptPubKey));
|
||||
const CKeyMetadata* meta = nullptr;
|
||||
CKeyID key_id = GetKeyForDestination(*pwallet, dest);
|
||||
if (!key_id.IsNull()) {
|
||||
|
|
|
@ -1261,6 +1261,11 @@ CAmount CWallet::GetCredit(const CTxOut& txout, const isminefilter& filter) cons
|
|||
}
|
||||
|
||||
bool CWallet::IsChange(const CTxOut& txout) const
|
||||
{
|
||||
return IsChange(txout.scriptPubKey);
|
||||
}
|
||||
|
||||
bool CWallet::IsChange(const CScript& script) const
|
||||
{
|
||||
// TODO: fix handling of 'change' outputs. The assumption is that any
|
||||
// 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
|
|||
// a better way of identifying which outputs are 'the send' and which are
|
||||
// 'the change' will need to be implemented (maybe extend CWalletTx to remember
|
||||
// which output, if any, was change).
|
||||
if (::IsMine(*this, txout.scriptPubKey))
|
||||
if (::IsMine(*this, script))
|
||||
{
|
||||
CTxDestination address;
|
||||
if (!ExtractDestination(txout.scriptPubKey, address))
|
||||
if (!ExtractDestination(script, address))
|
||||
return true;
|
||||
|
||||
LOCK(cs_wallet);
|
||||
|
|
|
@ -961,6 +961,7 @@ public:
|
|||
isminetype IsMine(const CTxOut& txout) const;
|
||||
CAmount GetCredit(const CTxOut& txout, const isminefilter& filter) const;
|
||||
bool IsChange(const CTxOut& txout) const;
|
||||
bool IsChange(const CScript& script) const;
|
||||
CAmount GetChange(const CTxOut& txout) const;
|
||||
bool IsMine(const CTransaction& tx) const;
|
||||
/** should probably be renamed to IsRelevantToMe */
|
||||
|
|
Loading…
Add table
Reference in a new issue