Add getdescriptorinfo to compute checksum
This commit is contained in:
parent
3b40bff988
commit
b52cb63688
2 changed files with 43 additions and 0 deletions
|
@ -143,6 +143,46 @@ static UniValue createmultisig(const JSONRPCRequest& request)
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
UniValue getdescriptorinfo(const JSONRPCRequest& request)
|
||||||
|
{
|
||||||
|
if (request.fHelp || request.params.size() != 1) {
|
||||||
|
throw std::runtime_error(
|
||||||
|
RPCHelpMan{"getdescriptorinfo",
|
||||||
|
{"\nAnalyses a descriptor.\n"},
|
||||||
|
{
|
||||||
|
{"descriptor", RPCArg::Type::STR, RPCArg::Optional::NO, "The descriptor."},
|
||||||
|
},
|
||||||
|
RPCResult{
|
||||||
|
"{\n"
|
||||||
|
" \"descriptor\" : \"desc\", (string) The descriptor in canonical form, without private keys\n"
|
||||||
|
" \"isrange\" : true|false, (boolean) Whether the descriptor is ranged\n"
|
||||||
|
" \"issolvable\" : true|false, (boolean) Whether the descriptor is solvable\n"
|
||||||
|
" \"hasprivatekeys\" : true|false, (boolean) Whether the input descriptor contained at least one private key\n"
|
||||||
|
"}\n"
|
||||||
|
},
|
||||||
|
RPCExamples{
|
||||||
|
"Analyse a descriptor\n" +
|
||||||
|
HelpExampleCli("getdescriptorinfo", "\"wpkh([d34db33f/84h/0h/0h]0279be667ef9dcbbac55a06295Ce870b07029Bfcdb2dce28d959f2815b16f81798)\"")
|
||||||
|
}}.ToString()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
RPCTypeCheck(request.params, {UniValue::VSTR});
|
||||||
|
|
||||||
|
FlatSigningProvider provider;
|
||||||
|
auto desc = Parse(request.params[0].get_str(), provider);
|
||||||
|
if (!desc) {
|
||||||
|
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, strprintf("Invalid descriptor"));
|
||||||
|
}
|
||||||
|
|
||||||
|
UniValue result(UniValue::VOBJ);
|
||||||
|
result.pushKV("descriptor", desc->ToString());
|
||||||
|
result.pushKV("isrange", desc->IsRange());
|
||||||
|
result.pushKV("issolvable", desc->IsSolvable());
|
||||||
|
result.pushKV("hasprivatekeys", provider.keys.size() > 0);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
UniValue deriveaddresses(const JSONRPCRequest& request)
|
UniValue deriveaddresses(const JSONRPCRequest& request)
|
||||||
{
|
{
|
||||||
if (request.fHelp || request.params.empty() || request.params.size() > 3) {
|
if (request.fHelp || request.params.empty() || request.params.size() > 3) {
|
||||||
|
@ -564,6 +604,7 @@ static const CRPCCommand commands[] =
|
||||||
{ "util", "validateaddress", &validateaddress, {"address"} },
|
{ "util", "validateaddress", &validateaddress, {"address"} },
|
||||||
{ "util", "createmultisig", &createmultisig, {"nrequired","keys","address_type"} },
|
{ "util", "createmultisig", &createmultisig, {"nrequired","keys","address_type"} },
|
||||||
{ "util", "deriveaddresses", &deriveaddresses, {"descriptor", "begin", "end"} },
|
{ "util", "deriveaddresses", &deriveaddresses, {"descriptor", "begin", "end"} },
|
||||||
|
{ "util", "getdescriptorinfo", &getdescriptorinfo, {"descriptor"} },
|
||||||
{ "util", "verifymessage", &verifymessage, {"address","signature","message"} },
|
{ "util", "verifymessage", &verifymessage, {"address","signature","message"} },
|
||||||
{ "util", "signmessagewithprivkey", &signmessagewithprivkey, {"privkey","message"} },
|
{ "util", "signmessagewithprivkey", &signmessagewithprivkey, {"privkey","message"} },
|
||||||
|
|
||||||
|
|
|
@ -175,6 +175,8 @@ class AddressTypeTest(BitcoinTestFramework):
|
||||||
assert(descsum_check(info['desc']))
|
assert(descsum_check(info['desc']))
|
||||||
# Verify that stripping the checksum and recreating it using Python roundtrips
|
# Verify that stripping the checksum and recreating it using Python roundtrips
|
||||||
assert(info['desc'] == descsum_create(info['desc'][:-9]))
|
assert(info['desc'] == descsum_create(info['desc'][:-9]))
|
||||||
|
# Verify that stripping the checksum and feeding it to getdescriptorinfo roundtrips
|
||||||
|
assert(info['desc'] == self.nodes[0].getdescriptorinfo(info['desc'][:-9])['descriptor'])
|
||||||
|
|
||||||
if not multisig and typ == 'legacy':
|
if not multisig and typ == 'legacy':
|
||||||
# P2PKH
|
# P2PKH
|
||||||
|
|
Loading…
Add table
Reference in a new issue