diff options
author | Pieter Wuille <pieter.wuille@gmail.com> | 2018-07-19 17:37:19 -0700 |
---|---|---|
committer | Pieter Wuille <pieter.wuille@gmail.com> | 2018-08-13 08:46:23 -0700 |
commit | 3b01efa0d1bf3d23d1b7b7e518849f1fc26314f9 (patch) | |
tree | 4779af5b25e8d6dffbed87a8bdd8fbd27170aa54 /src/utilstrencodings.cpp | |
parent | 81e1dd5ce1a32114a38691ec6b55e72ab04dbbb1 (diff) |
[MOVEONLY] Move ParseHDKeypath to utilstrencodings
Diffstat (limited to 'src/utilstrencodings.cpp')
-rw-r--r-- | src/utilstrencodings.cpp | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/src/utilstrencodings.cpp b/src/utilstrencodings.cpp index a06d88cb19..e66e2c238c 100644 --- a/src/utilstrencodings.cpp +++ b/src/utilstrencodings.cpp @@ -544,3 +544,43 @@ bool ParseFixedPoint(const std::string &val, int decimals, int64_t *amount_out) return true; } +bool ParseHDKeypath(const std::string& keypath_str, std::vector<uint32_t>& keypath) +{ + std::stringstream ss(keypath_str); + std::string item; + bool first = true; + while (std::getline(ss, item, '/')) { + if (item.compare("m") == 0) { + if (first) { + first = false; + continue; + } + return false; + } + // Finds whether it is hardened + uint32_t path = 0; + size_t pos = item.find("'"); + if (pos != std::string::npos) { + // The hardened tick can only be in the last index of the string + if (pos != item.size() - 1) { + return false; + } + path |= 0x80000000; + item = item.substr(0, item.size() - 1); // Drop the last character which is the hardened tick + } + + // Ensure this is only numbers + if (item.find_first_not_of( "0123456789" ) != std::string::npos) { + return false; + } + uint32_t number; + if (!ParseUInt32(item, &number)) { + return false; + } + path |= number; + + keypath.push_back(path); + first = false; + } + return true; +} |