add nft_history and mark certain APIs as clio-only to improve error (#255)

This commit is contained in:
ledhed2222
2022-09-15 21:11:29 -04:00
committed by GitHub
parent 777ae24f62
commit 1764f3524e
12 changed files with 346 additions and 240 deletions

View File

@@ -89,24 +89,15 @@ doNFTInfo(Context const& context)
auto request = context.params;
boost::json::object response = {};
if (!request.contains("nft_id"))
return Status{Error::rpcINVALID_PARAMS, "Missing nft_id"};
auto const& jsonTokenID = request.at("nft_id");
if (!jsonTokenID.is_string())
return Status{Error::rpcINVALID_PARAMS, "nft_id is not a string"};
ripple::uint256 tokenID;
if (!tokenID.parseHex(jsonTokenID.as_string().c_str()))
return Status{Error::rpcINVALID_PARAMS, "Malformed nft_id"};
// We only need to fetch the ledger header because the ledger hash is
// supposed to be included in the response. The ledger sequence is specified
// in the request
auto v = ledgerInfoFromRequest(context);
if (auto status = std::get_if<Status>(&v))
auto const maybeTokenID = getNFTID(request);
if (auto const status = std::get_if<Status>(&maybeTokenID); status)
return *status;
ripple::LedgerInfo lgrInfo = std::get<ripple::LedgerInfo>(v);
auto const tokenID = std::get<ripple::uint256>(maybeTokenID);
auto const maybeLedgerInfo = ledgerInfoFromRequest(context);
if (auto status = std::get_if<Status>(&maybeLedgerInfo); status)
return *status;
auto const lgrInfo = std::get<ripple::LedgerInfo>(maybeLedgerInfo);
std::optional<Backend::NFT> dbResponse =
context.backend->fetchNFT(tokenID, lgrInfo.seq, context.yield);
@@ -130,10 +121,10 @@ doNFTInfo(Context const& context)
{
auto const maybeURI = getURI(*dbResponse, context);
// An error occurred
if (Status const* status = std::get_if<Status>(&maybeURI))
if (Status const* status = std::get_if<Status>(&maybeURI); status)
return *status;
// A URI was found
if (std::string const* uri = std::get_if<std::string>(&maybeURI))
if (std::string const* uri = std::get_if<std::string>(&maybeURI); uri)
response["uri"] = *uri;
// A URI was not found, explicitly set to null
else