mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-04-28 15:58:42 +02:00
Add descriptors to listunspent and getaddressinfo + tests
This commit is contained in:
@@ -20,6 +20,7 @@
|
||||
#include <rpc/rawtransaction.h>
|
||||
#include <rpc/server.h>
|
||||
#include <rpc/util.h>
|
||||
#include <script/descriptor.h>
|
||||
#include <script/sign.h>
|
||||
#include <shutdown.h>
|
||||
#include <timedata.h>
|
||||
@@ -2623,6 +2624,7 @@ static UniValue listunspent(const JSONRPCRequest& request)
|
||||
" \"redeemScript\" : n (string) The redeemScript if scriptPubKey is P2SH\n"
|
||||
" \"spendable\" : xxx, (bool) Whether we have the private keys to spend this output\n"
|
||||
" \"solvable\" : xxx, (bool) Whether we know how to spend this output, ignoring the lack of keys\n"
|
||||
" \"desc\" : xxx, (string, only when solvable) A descriptor for spending this output\n"
|
||||
" \"safe\" : xxx (bool) Whether this output is considered safe to spend. Unconfirmed transactions\n"
|
||||
" from outside keys and unconfirmed replacement transactions are considered unsafe\n"
|
||||
" and are not eligible for spending by fundrawtransaction and sendtoaddress.\n"
|
||||
@@ -2740,6 +2742,10 @@ static UniValue listunspent(const JSONRPCRequest& request)
|
||||
entry.pushKV("confirmations", out.nDepth);
|
||||
entry.pushKV("spendable", out.fSpendable);
|
||||
entry.pushKV("solvable", out.fSolvable);
|
||||
if (out.fSolvable) {
|
||||
auto descriptor = InferDescriptor(scriptPubKey, *pwallet);
|
||||
entry.pushKV("desc", descriptor->ToString());
|
||||
}
|
||||
entry.pushKV("safe", out.fSafe);
|
||||
results.push_back(entry);
|
||||
}
|
||||
@@ -3456,6 +3462,8 @@ UniValue getaddressinfo(const JSONRPCRequest& request)
|
||||
" \"scriptPubKey\" : \"hex\", (string) The hex-encoded scriptPubKey generated by the address\n"
|
||||
" \"ismine\" : true|false, (boolean) If the address is yours or not\n"
|
||||
" \"iswatchonly\" : true|false, (boolean) If the address is watchonly\n"
|
||||
" \"solvable\" : true|false, (boolean) Whether we know how to spend coins sent to this address, ignoring the possible lack of private keys\n"
|
||||
" \"desc\" : \"desc\", (string, optional) A descriptor for spending coins sent to this address (only when solvable)\n"
|
||||
" \"isscript\" : true|false, (boolean) If the key is a script\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"
|
||||
@@ -3508,6 +3516,11 @@ UniValue getaddressinfo(const JSONRPCRequest& request)
|
||||
|
||||
isminetype mine = IsMine(*pwallet, dest);
|
||||
ret.pushKV("ismine", bool(mine & ISMINE_SPENDABLE));
|
||||
bool solvable = IsSolvable(*pwallet, scriptPubKey);
|
||||
ret.pushKV("solvable", solvable);
|
||||
if (solvable) {
|
||||
ret.pushKV("desc", InferDescriptor(scriptPubKey, *pwallet)->ToString());
|
||||
}
|
||||
ret.pushKV("iswatchonly", bool(mine & ISMINE_WATCH_ONLY));
|
||||
UniValue detail = DescribeWalletAddress(pwallet, dest);
|
||||
ret.pushKVs(detail);
|
||||
|
||||
Reference in New Issue
Block a user