Skip to content

Commit

Permalink
fixup! Add error_locations to validateaddress RPC
Browse files Browse the repository at this point in the history
  • Loading branch information
promag committed Oct 25, 2021
1 parent 88cc481 commit 94ca6b4
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
23 changes: 13 additions & 10 deletions src/key_io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class DestinationEncoder
std::string operator()(const CNoDestination& no) const { return {}; }
};

CTxDestination DecodeDestination(const std::string& str, const CChainParams& params, std::string& error_str, std::vector<int>* error_locations)
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;
Expand Down Expand Up @@ -185,12 +185,7 @@ CTxDestination DecodeDestination(const std::string& str, const CChainParams& par
}

// 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);
}
error_str = bech32::LocateErrors(str, error_locations);

return CNoDestination();
}
Expand Down Expand Up @@ -279,21 +274,29 @@ std::string EncodeDestination(const CTxDestination& dest)
return std::visit(DestinationEncoder(Params()), dest);
}

CTxDestination DecodeDestination(const std::string& str, std::string& error_msg, std::vector<int>* error_locations)
CTxDestination DecodeDestination(const std::string& str, std::string& error_msg)
{
std::vector<int> error_locations;
return DecodeDestination(str, Params(), error_msg, error_locations);
}

CTxDestination DecodeDestination(const std::string& str, std::string& error_msg, std::vector<int>& error_locations)
{
return DecodeDestination(str, Params(), error_msg, error_locations);
}

CTxDestination DecodeDestination(const std::string& str)
{
std::string error_msg;
return DecodeDestination(str, error_msg);
std::vector<int> error_locations;
return DecodeDestination(str, Params(), error_msg, error_locations);
}

bool IsValidDestinationString(const std::string& str, const CChainParams& params)
{
std::string error_msg;
return IsValidDestination(DecodeDestination(str, params, error_msg, nullptr));
std::vector<int> error_locations;
return IsValidDestination(DecodeDestination(str, params, error_msg, error_locations));
}

bool IsValidDestinationString(const std::string& str)
Expand Down
3 changes: 2 additions & 1 deletion src/key_io.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ std::string EncodeExtPubKey(const CExtPubKey& extpubkey);

std::string EncodeDestination(const CTxDestination& dest);
CTxDestination DecodeDestination(const std::string& str);
CTxDestination DecodeDestination(const std::string& str, std::string& error_msg, std::vector<int>* error_locations = nullptr);
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);
bool IsValidDestinationString(const std::string& str);
bool IsValidDestinationString(const std::string& str, const CChainParams& params);

Expand Down
2 changes: 1 addition & 1 deletion src/rpc/misc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ static RPCHelpMan validateaddress()
{
std::string error_msg;
std::vector<int> error_locations;
CTxDestination dest = DecodeDestination(request.params[0].get_str(), error_msg, &error_locations);
CTxDestination dest = DecodeDestination(request.params[0].get_str(), error_msg, error_locations);
const bool isValid = IsValidDestination(dest);
CHECK_NONFATAL(isValid == error_msg.empty());

Expand Down

0 comments on commit 94ca6b4

Please sign in to comment.