From 0ab61caafd10d0539da626bd4354cb7e6df15e54 Mon Sep 17 00:00:00 2001 From: Sjors Provoost Date: Mon, 16 Jun 2025 15:00:55 +0200 Subject: [PATCH] rpc: ParsePathBIP32 helper --- src/rpc/util.cpp | 10 ++++++++++ src/rpc/util.h | 3 +++ 2 files changed, 13 insertions(+) diff --git a/src/rpc/util.cpp b/src/rpc/util.cpp index a9c35cccada..d9d1adb20ac 100644 --- a/src/rpc/util.cpp +++ b/src/rpc/util.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -1379,6 +1380,15 @@ std::vector EvalDescriptorStringOrObject(const UniValue& scanobject, Fl return ret; } +std::vector ParsePathBIP32(const std::string& path) +{ + std::vector out; + if (!ParseHDKeypath(path, out)) { + throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid BIP32 keypath"); + } + return out; +} + /** Convert a vector of bilingual strings to a UniValue::VARR containing their original untranslated values. */ [[nodiscard]] static UniValue BilingualStringsToUniValue(const std::vector& bilingual_strings) { diff --git a/src/rpc/util.h b/src/rpc/util.h index 2cb36488137..6142c37a553 100644 --- a/src/rpc/util.h +++ b/src/rpc/util.h @@ -156,6 +156,9 @@ std::pair ParseDescriptorRange(const UniValue& value); /** Evaluate a descriptor given as a string, or as a {"desc":...,"range":...} object, with default range of 1000. */ std::vector EvalDescriptorStringOrObject(const UniValue& scanobject, FlatSigningProvider& provider, bool expand_priv = false); +//! Parse BIP32 path +std::vector ParsePathBIP32(const std::string& path); + /** * Serializing JSON objects depends on the outer type. Only arrays and * dictionaries can be nested in json. The top-level outer type is "NONE".