| 1332 | } |
| 1333 | |
| 1334 | std::vector<CScript> EvalDescriptorStringOrObject(const UniValue& scanobject, FlatSigningProvider& provider, const bool expand_priv) |
| 1335 | { |
| 1336 | std::string desc_str; |
| 1337 | std::pair<int64_t, int64_t> range = {0, 1000}; |
| 1338 | if (scanobject.isStr()) { |
| 1339 | desc_str = scanobject.get_str(); |
| 1340 | } else if (scanobject.isObject()) { |
| 1341 | const UniValue& desc_uni{scanobject.find_value("desc")}; |
| 1342 | if (desc_uni.isNull()) throw JSONRPCError(RPC_INVALID_PARAMETER, "Descriptor needs to be provided in scan object"); |
| 1343 | desc_str = desc_uni.get_str(); |
| 1344 | const UniValue& range_uni{scanobject.find_value("range")}; |
| 1345 | if (!range_uni.isNull()) { |
| 1346 | range = ParseDescriptorRange(range_uni); |
| 1347 | } |
| 1348 | } else { |
| 1349 | throw JSONRPCError(RPC_INVALID_PARAMETER, "Scan object needs to be either a string or an object"); |
| 1350 | } |
| 1351 | |
| 1352 | std::string error; |
| 1353 | auto descs = Parse(desc_str, provider, error); |
| 1354 | if (descs.empty()) { |
| 1355 | throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, error); |
| 1356 | } |
| 1357 | if (!descs.at(0)->IsRange()) { |
| 1358 | range.first = 0; |
| 1359 | range.second = 0; |
| 1360 | } |
| 1361 | std::vector<CScript> ret; |
| 1362 | for (int i = range.first; i <= range.second; ++i) { |
| 1363 | for (const auto& desc : descs) { |
| 1364 | std::vector<CScript> scripts; |
| 1365 | if (!desc->Expand(i, provider, scripts, provider)) { |
| 1366 | throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, strprintf("Cannot derive script without private keys: '%s'", desc_str)); |
| 1367 | } |
| 1368 | if (expand_priv) { |
| 1369 | desc->ExpandPrivate(/*pos=*/i, provider, /*out=*/provider); |
| 1370 | } |
| 1371 | std::move(scripts.begin(), scripts.end(), std::back_inserter(ret)); |
| 1372 | } |
| 1373 | } |
| 1374 | return ret; |
| 1375 | } |
| 1376 | |
| 1377 | /** Convert a vector of bilingual strings to a UniValue::VARR containing their original untranslated values. */ |
| 1378 | [[nodiscard]] static UniValue BilingualStringsToUniValue(const std::vector<bilingual_str>& bilingual_strings) |
no test coverage detected