MCPcopy Create free account
hub / github.com/Bitcoin-ABC/bitcoin-abc / getScriptFromDescriptor

Function getScriptFromDescriptor

src/rpc/mining.cpp:210–245  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

208}
209
210static bool getScriptFromDescriptor(const std::string &descriptor,
211 CScript &script, std::string &error) {
212 FlatSigningProvider key_provider;
213 const auto desc =
214 Parse(descriptor, key_provider, error, /* require_checksum = */ false);
215 if (desc) {
216 if (desc->IsRange()) {
217 throw JSONRPCError(RPC_INVALID_PARAMETER,
218 "Ranged descriptor not accepted. Maybe pass "
219 "through deriveaddresses first?");
220 }
221
222 FlatSigningProvider provider;
223 std::vector<CScript> scripts;
224 if (!desc->Expand(0, key_provider, scripts, provider)) {
225 throw JSONRPCError(
226 RPC_INVALID_ADDRESS_OR_KEY,
227 strprintf("Cannot derive script without private keys"));
228 }
229
230 // Combo descriptors can have 2 scripts, so we can't just check
231 // scripts.size() == 1
232 CHECK_NONFATAL(scripts.size() > 0 && scripts.size() <= 2);
233
234 if (scripts.size() == 1) {
235 script = scripts.at(0);
236 } else {
237 // Else take the 2nd script, since it is p2pkh
238 script = scripts.at(1);
239 }
240
241 return true;
242 }
243
244 return false;
245}
246
247static RPCHelpMan generatetodescriptor() {
248 return RPCHelpMan{

Callers 2

generatetodescriptorFunction · 0.85
generateblockFunction · 0.85

Calls 6

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

Tested by

no test coverage detected