Skip to content

Commit

Permalink
APIv2(ledger_entry): return invalidParams for bad parameters (XRPLF#4630
Browse files Browse the repository at this point in the history
)

- Verify "check", used to retrieve a Check object, is a string.
- Verify "nft_page", used to retrieve an NFT Page, is a string.
- Verify "index", used to retrieve any type of ledger object by its
  unique ID, is a string.
- Verify "directory", used to retrieve a DirectoryNode, is a string or
  an object.

This change only impacts api_version 2 since it is a breaking change.

https://xrpl.org/ledger_entry.html

Fix XRPLF#4550
  • Loading branch information
PeterChen13579 authored and gregtatcam committed Sep 8, 2023
1 parent ec80dd2 commit f26b69f
Show file tree
Hide file tree
Showing 3 changed files with 503 additions and 279 deletions.
16 changes: 7 additions & 9 deletions src/ripple/protocol/impl/Issue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

#include <ripple/protocol/Issue.h>

#include <ripple/json/json_errors.h>
#include <ripple/protocol/AccountID.h>
#include <ripple/protocol/UintTypes.h>
#include <ripple/protocol/jss.h>
Expand Down Expand Up @@ -78,7 +79,7 @@ issueFromJson(Json::Value const& v)
{
if (!v.isObject())
{
Throw<std::runtime_error>(
Throw<Json::error>(
"issueFromJson can only be specified with a 'object' Json value");
}

Expand All @@ -87,37 +88,34 @@ issueFromJson(Json::Value const& v)

if (!curStr.isString())
{
Throw<std::runtime_error>(
Throw<Json::error>(
"issueFromJson currency must be a string Json value");
}

auto const currency = to_currency(curStr.asString());
if (currency == badCurrency() || currency == noCurrency())
{
Throw<std::runtime_error>(
"issueFromJson currency must be a valid currency");
Throw<Json::error>("issueFromJson currency must be a valid currency");
}

if (isXRP(currency))
{
if (!issStr.isNull())
{
Throw<std::runtime_error>("Issue, XRP should not have issuer");
Throw<Json::error>("Issue, XRP should not have issuer");
}
return xrpIssue();
}

if (!issStr.isString())
{
Throw<std::runtime_error>(
"issueFromJson issuer must be a string Json value");
Throw<Json::error>("issueFromJson issuer must be a string Json value");
}
auto const issuer = parseBase58<AccountID>(issStr.asString());

if (!issuer)
{
Throw<std::runtime_error>(
"issueFromJson issuer must be a valid account");
Throw<Json::error>("issueFromJson issuer must be a valid account");
}

return Issue{currency, *issuer};
Expand Down
Loading

0 comments on commit f26b69f

Please sign in to comment.