diff options
author | Pieter Wuille <pieter.wuille@gmail.com> | 2018-07-27 12:21:12 -0700 |
---|---|---|
committer | Pieter Wuille <pieter.wuille@gmail.com> | 2018-07-27 12:21:12 -0700 |
commit | f6b7fc349ccf9cfbeb7e91e19c20e2a2fcc9026f (patch) | |
tree | 4f5e3cb6933ef7399fb69d47b935b3ab24467c23 /src | |
parent | fddea672eb8f63012f2e9ce04fa477e5d4140750 (diff) |
Support h instead of ' in hardened descriptor paths
Diffstat (limited to 'src')
-rw-r--r-- | src/rpc/blockchain.cpp | 3 | ||||
-rw-r--r-- | src/script/descriptor.cpp | 4 | ||||
-rw-r--r-- | src/script/descriptor.h | 1 | ||||
-rw-r--r-- | src/test/descriptor_tests.cpp | 19 |
4 files changed, 22 insertions, 5 deletions
diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index 307af61917..46dec4ca6e 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -1999,7 +1999,8 @@ UniValue scantxoutset(const JSONRPCRequest& request) " pkh(<pubkey>) P2PKH outputs for the given pubkey\n" " sh(multi(<n>,<pubkey>,<pubkey>,...)) P2SH-multisig outputs for the given threshold and pubkeys\n" "\nIn the above, <pubkey> either refers to a fixed public key in hexadecimal notation, or to an xpub/xprv optionally followed by one\n" - "or more path elements separated by \"/\", and optionally ending in \"/*\" or \"/*'\" to specify all unhardened or hardened child keys.\n" + "or more path elements separated by \"/\", and optionally ending in \"/*\" (unhardened), or \"/*'\" or \"/*h\" (hardened) to specify all\n" + "unhardened or hardened child keys.\n" "In the latter case, a range needs to be specified by below if different from 1000.\n" "For more information on output descriptors, see the documentation at TODO\n" "\nArguments:\n" diff --git a/src/script/descriptor.cpp b/src/script/descriptor.cpp index bbeabab372..f366b99ec3 100644 --- a/src/script/descriptor.cpp +++ b/src/script/descriptor.cpp @@ -436,7 +436,7 @@ bool ParseKeyPath(const std::vector<Span<const char>>& split, KeyPath& out) for (size_t i = 1; i < split.size(); ++i) { Span<const char> elem = split[i]; bool hardened = false; - if (elem.size() > 0 && elem[elem.size() - 1] == '\'') { + if (elem.size() > 0 && (elem[elem.size() - 1] == '\'' || elem[elem.size() - 1] == 'h')) { elem = elem.first(elem.size() - 1); hardened = true; } @@ -472,7 +472,7 @@ std::unique_ptr<PubkeyProvider> ParsePubkey(const Span<const char>& sp, bool per if (split.back() == MakeSpan("*").first(1)) { split.pop_back(); type = DeriveType::UNHARDENED; - } else if (split.back() == MakeSpan("*'").first(2)) { + } else if (split.back() == MakeSpan("*'").first(2) || split.back() == MakeSpan("*h").first(2)) { split.pop_back(); type = DeriveType::HARDENED; } diff --git a/src/script/descriptor.h b/src/script/descriptor.h index d7c7ccbfb6..e079c72e92 100644 --- a/src/script/descriptor.h +++ b/src/script/descriptor.h @@ -68,6 +68,7 @@ // * X // * E/I: unhardened child // * E/I': hardened child +// * E/Ih: hardened child (alternative notation) // // The top level is S. diff --git a/src/test/descriptor_tests.cpp b/src/test/descriptor_tests.cpp index 6d0492e050..f189222be8 100644 --- a/src/test/descriptor_tests.cpp +++ b/src/test/descriptor_tests.cpp @@ -28,13 +28,28 @@ constexpr int HARDENED = 2; // Derivation needs access to private keys constexpr int UNSOLVABLE = 4; // This descriptor is not expected to be solvable constexpr int SIGNABLE = 8; // We can sign with this descriptor (this is not true when actual BIP32 derivation is used, as that's not integrated in our signing code) +std::string MaybeUseHInsteadOfApostrophy(std::string ret) +{ + if (InsecureRandBool()) { + while (true) { + auto it = ret.find("'"); + if (it != std::string::npos) { + ret[it] = 'h'; + } else { + break; + } + } + } + return ret; +} + void Check(const std::string& prv, const std::string& pub, int flags, const std::vector<std::vector<std::string>>& scripts) { FlatSigningProvider keys_priv, keys_pub; // Check that parsing succeeds. - auto parse_priv = Parse(prv, keys_priv); - auto parse_pub = Parse(pub, keys_pub); + auto parse_priv = Parse(MaybeUseHInsteadOfApostrophy(prv), keys_priv); + auto parse_pub = Parse(MaybeUseHInsteadOfApostrophy(pub), keys_pub); BOOST_CHECK(parse_priv); BOOST_CHECK(parse_pub); |