diff options
author | Samuel Dobson <dobsonsa68@gmail.com> | 2021-10-01 12:16:20 +1300 |
---|---|---|
committer | Samuel Dobson <dobsonsa68@gmail.com> | 2021-10-12 12:03:14 +1300 |
commit | b62b67e06cc406fdad68da4c091168fb5f11c1d4 (patch) | |
tree | 1c70b946c4c6c2003dc0186773bb4949e5fa0f8c /src/key_io.cpp | |
parent | 0b06e720c0182dee8b560d2e8d3891b036f63ea7 (diff) |
Add Bech32 error location function
Diffstat (limited to 'src/key_io.cpp')
-rw-r--r-- | src/key_io.cpp | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/src/key_io.cpp b/src/key_io.cpp index 9e246c0b81..6908c5ea52 100644 --- a/src/key_io.cpp +++ b/src/key_io.cpp @@ -76,7 +76,7 @@ public: std::string operator()(const CNoDestination& no) const { return {}; } }; -CTxDestination DecodeDestination(const std::string& str, const CChainParams& params, std::string& error_str) +CTxDestination DecodeDestination(const std::string& str, const CChainParams& params, std::string& error_str, std::vector<int>* error_locations) { std::vector<unsigned char> data; uint160 hash; @@ -184,8 +184,13 @@ CTxDestination DecodeDestination(const std::string& str, const CChainParams& par } } - //TODO: locate Bech32 errors - error_str = "Error in Bech32 encoding"; + // Perform Bech32 error location + if (!error_locations) { + std::vector<int> dummy_errors; + error_str = bech32::LocateErrors(str, dummy_errors); + } else { + error_str = bech32::LocateErrors(str, *error_locations); + } return CNoDestination(); } @@ -274,9 +279,9 @@ std::string EncodeDestination(const CTxDestination& dest) return std::visit(DestinationEncoder(Params()), dest); } -CTxDestination DecodeDestination(const std::string& str, std::string& error_msg) +CTxDestination DecodeDestination(const std::string& str, std::string& error_msg, std::vector<int>* error_locations) { - return DecodeDestination(str, Params(), error_msg); + return DecodeDestination(str, Params(), error_msg, error_locations); } CTxDestination DecodeDestination(const std::string& str) @@ -288,7 +293,7 @@ CTxDestination DecodeDestination(const std::string& str) bool IsValidDestinationString(const std::string& str, const CChainParams& params) { std::string error_msg; - return IsValidDestination(DecodeDestination(str, params, error_msg)); + return IsValidDestination(DecodeDestination(str, params, error_msg, nullptr)); } bool IsValidDestinationString(const std::string& str) |