| 2691 | |
| 2692 | template <typename Ctx> |
| 2693 | inline std::optional<Node<typename Ctx::Key>> FromScript(const CScript& script, const Ctx& ctx) |
| 2694 | { |
| 2695 | using namespace internal; |
| 2696 | // A too large Script is necessarily invalid, don't bother parsing it. |
| 2697 | if (script.size() > MaxScriptSize(ctx.MsContext())) return {}; |
| 2698 | auto decomposed = DecomposeScript(script); |
| 2699 | if (!decomposed) return {}; |
| 2700 | auto it = decomposed->begin(); |
| 2701 | auto ret = DecodeScript<typename Ctx::Key>(it, decomposed->end(), ctx); |
| 2702 | if (!ret) return {}; |
| 2703 | if (it != decomposed->end()) return {}; |
| 2704 | return ret; |
| 2705 | } |
| 2706 | |
| 2707 | } // namespace miniscript |
| 2708 | |