Support descriptors with checksums in initpegoutwallet

This commit is contained in:
Steven Roose 2019-09-30 15:48:55 +02:00
parent 280c33f865
commit fdba8c45f9
No known key found for this signature in database
GPG key ID: 2F2A88D7F8D68E87
3 changed files with 9 additions and 8 deletions

View file

@ -464,13 +464,6 @@ public:
}
};
//TODO(stevenroose) remove if unused
CScript P2PKHGetScript(const CPubKey& pubkey) { return GetScriptForDestination(PKHash(pubkey)); }
CScript P2PKGetScript(const CPubKey& pubkey) { return GetScriptForRawPubKey(pubkey); }
CScript P2WPKHGetScript(const CPubKey& pubkey) { return GetScriptForDestination(WitnessV0KeyHash(pubkey.GetID())); }
CScript ConvertP2SH(const CScript& script) { return GetScriptForDestination(ScriptHash(script)); }
CScript ConvertP2WSH(const CScript& script) { return GetScriptForDestination(WitnessV0ScriptHash(script)); }
/** Construct a vector with one element, which is moved into it. */
template<typename T>
std::vector<T> Singleton(T elem)

View file

@ -4982,13 +4982,19 @@ UniValue initpegoutwallet(const JSONRPCRequest& request)
}
FlatSigningProvider provider;
auto desc = Parse(bitcoin_desc, provider);
auto desc = Parse(bitcoin_desc, provider, false); // don't require checksum
if (!desc) {
throw JSONRPCError(RPC_INVALID_PARAMETER, "bitcoin_descriptor is not a valid descriptor string.");
} else if (!desc->IsRange()) {
throw JSONRPCError(RPC_INVALID_PARAMETER, "bitcoin_descriptor must be a ranged descriptor.");
}
// For our manual pattern matching, we don't want the checksum part.
auto checksum_char = bitcoin_desc.find('#');
if (checksum_char != std::string::npos) {
bitcoin_desc = bitcoin_desc.substr(0, checksum_char);
}
// Three acceptable descriptors:
if (bitcoin_desc.substr(0, 8) == "sh(wpkh("
&& bitcoin_desc.substr(bitcoin_desc.size()-2, 2) == "))") {

View file

@ -167,6 +167,8 @@ class PAKTest (BitcoinTestFramework):
# Peg out with each new type, check that destination script matches
wpkh_desc = "wpkh("+xpub+"/0/*)"
# add a valid checksum
wpkh_desc = self.nodes[1].getdescriptorinfo(wpkh_desc)["descriptor"]
wpkh_info = self.nodes[1].initpegoutwallet(wpkh_desc)
wpkh_pak_info = self.nodes[1].getwalletpakinfo()