| 1519 | return Vector(GetScriptForDestination(output)); |
| 1520 | } |
| 1521 | bool ToStringSubScriptHelper(const SigningProvider* arg, std::string& ret, const StringType type, const DescriptorCache* cache = nullptr) const override |
| 1522 | { |
| 1523 | if (m_depths.empty()) { |
| 1524 | // If there are no sub-descriptors and a PRIVATE string |
| 1525 | // is requested, return `false` to indicate that the presence |
| 1526 | // of a private key depends solely on the internal key (which is checked |
| 1527 | // in the caller), not on any sub-descriptor. This ensures correct behavior for |
| 1528 | // descriptors like tr(internal_key) when checking for private keys. |
| 1529 | return type != StringType::PRIVATE; |
| 1530 | } |
| 1531 | std::vector<bool> path; |
| 1532 | bool is_private{type == StringType::PRIVATE}; |
| 1533 | // For private string output, track if at least one key has a private key available. |
| 1534 | // Initialize to true for non-private types. |
| 1535 | bool any_success{!is_private}; |
| 1536 | |
| 1537 | for (size_t pos = 0; pos < m_depths.size(); ++pos) { |
| 1538 | if (pos) ret += ','; |
| 1539 | while ((int)path.size() <= m_depths[pos]) { |
| 1540 | if (path.size()) ret += '{'; |
| 1541 | path.push_back(false); |
| 1542 | } |
| 1543 | std::string tmp; |
| 1544 | bool subscript_res{m_subdescriptor_args[pos]->ToStringHelper(arg, tmp, type, cache)}; |
| 1545 | if (!is_private && !subscript_res) return false; |
| 1546 | any_success = any_success || subscript_res; |
| 1547 | ret += tmp; |
| 1548 | while (!path.empty() && path.back()) { |
| 1549 | if (path.size() > 1) ret += '}'; |
| 1550 | path.pop_back(); |
| 1551 | } |
| 1552 | if (!path.empty()) path.back() = true; |
| 1553 | } |
| 1554 | return any_success; |
| 1555 | } |
| 1556 | public: |
| 1557 | TRDescriptor(std::unique_ptr<PubkeyProvider> internal_key, std::vector<std::unique_ptr<DescriptorImpl>> descs, std::vector<int> depths) : |
| 1558 | DescriptorImpl(Vector(std::move(internal_key)), std::move(descs), "tr"), m_depths(std::move(depths)) |