MCPcopy Create free account
hub / github.com/ElementsProject/elements / getScriptFromDescriptor

Function getScriptFromDescriptor

src/rpc/mining.cpp:202–234  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

200}
201
202static 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
236static RPCHelpMan generatetodescriptor()
237{

Callers 2

generatetodescriptorFunction · 0.85
generateblockFunction · 0.85

Calls 5

ParseFunction · 0.85
JSONRPCErrorFunction · 0.85
ExpandMethod · 0.80
IsRangeMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected