| 200 | } |
| 201 | |
| 202 | static bool getScriptFromDescriptor(const std::string& descriptor, CScript& script, std::string& error) |
| 203 | { |
| 204 | FlatSigningProvider key_provider; |
| 205 | const auto desc = Parse(descriptor, key_provider, error, /* require_checksum = */ false); |
| 206 | if (desc) { |
| 207 | if (desc->IsRange()) { |
| 208 | throw JSONRPCError(RPC_INVALID_PARAMETER, "Ranged descriptor not accepted. Maybe pass through deriveaddresses first?"); |
| 209 | } |
| 210 | |
| 211 | FlatSigningProvider provider; |
| 212 | std::vector<CScript> scripts; |
| 213 | if (!desc->Expand(0, key_provider, scripts, provider)) { |
| 214 | throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Cannot derive script without private keys"); |
| 215 | } |
| 216 | |
| 217 | // Combo descriptors can have 2 or 4 scripts, so we can't just check scripts.size() == 1 |
| 218 | CHECK_NONFATAL(scripts.size() > 0 && scripts.size() <= 4); |
| 219 | |
| 220 | if (scripts.size() == 1) { |
| 221 | script = scripts.at(0); |
| 222 | } else if (scripts.size() == 4) { |
| 223 | // For uncompressed keys, take the 3rd script, since it is p2wpkh |
| 224 | script = scripts.at(2); |
| 225 | } else { |
| 226 | // Else take the 2nd script, since it is p2pkh |
| 227 | script = scripts.at(1); |
| 228 | } |
| 229 | |
| 230 | return true; |
| 231 | } else { |
| 232 | return false; |
| 233 | } |
| 234 | } |
| 235 | |
| 236 | static RPCHelpMan generatetodescriptor() |
| 237 | { |
no test coverage detected