Skip to content

Commit

Permalink
fix: accept all valid currency codes in API (XRPLF#4566)
Browse files Browse the repository at this point in the history
A few methods, including `book_offers`, take currency codes as
parameters. The XRPL doesn't care if the letters in those codes are
lowercase or uppercase, as long as they come from an alphabet defined
internally. rippled doesn't care either, when they are submitted in a
hex representation. When they are submitted in an ASCII string
representation, rippled, but not XRPL, is more restrictive, preventing
clients from interacting with some currencies already in the XRPL.

This change gets rippled out of the way and lets clients submit currency
codes in ASCII using the full alphabet.

Fixes XRPLF#4112
  • Loading branch information
thejohnfreeman authored Sep 22, 2023
1 parent e4db0fb commit 6b61505
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
8 changes: 7 additions & 1 deletion src/ripple/net/impl/RPCCall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,13 @@ class RPCParser
static Json::Value
jvParseCurrencyIssuer(std::string const& strCurrencyIssuer)
{
static boost::regex reCurIss("\\`([[:alpha:]]{3})(?:/(.+))?\\'");
// Matches a sequence of 3 characters from
// `ripple::detail::isoCharSet` (the currency),
// optionally followed by a forward slash and some other characters
// (the issuer).
// https://www.boost.org/doc/libs/1_82_0/libs/regex/doc/html/boost_regex/syntax/perl_syntax.html
static boost::regex reCurIss(
"\\`([][:alnum:]<>(){}[|?!@#$%^&*]{3})(?:/(.+))?\\'");

boost::smatch smMatch;

Expand Down
10 changes: 2 additions & 8 deletions src/ripple/protocol/impl/UintTypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,8 @@ to_currency(Currency& currency, std::string const& code)

currency = beast::zero;

std::transform(
code.begin(),
code.end(),
currency.begin() + detail::isoCodeOffset,
[](auto c) {
return static_cast<unsigned char>(
::toupper(static_cast<unsigned char>(c)));
});
std::copy(
code.begin(), code.end(), currency.begin() + detail::isoCodeOffset);

return true;
}
Expand Down

0 comments on commit 6b61505

Please sign in to comment.