Skip to content

Commit

Permalink
[FOLD] Rename jss::tokenid to jss::nft_id for RPC field consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
scottschurr committed Mar 23, 2022
1 parent 043afbd commit 1a932bf
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/ripple/protocol/jss.h
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,7 @@ JSS(needed_transaction_hashes); // out: InboundLedger
JSS(network_id); // out: NetworkOPs
JSS(network_ledger); // out: NetworkOPs
JSS(next_refresh_time); // out: ValidatorSite
JSS(nft_id); // in: nft_sell_offers, nft_buy_offers
JSS(nft_offer); // in: LedgerEntry
JSS(nft_page); // in: LedgerEntry
JSS(nft_serial); // out: account_nfts
Expand Down Expand Up @@ -564,7 +565,6 @@ JSS(time);
JSS(timeouts); // out: InboundLedger
JSS(track); // out: PeerImp
JSS(traffic); // out: Overlay
JSS(tokenid); // in: nft_sell_offers, nft_buy_offers
JSS(total); // out: counters
JSS(totalCoins); // out: LedgerToJson
JSS(total_bytes_recv); // out: Peers
Expand Down
50 changes: 34 additions & 16 deletions src/ripple/rpc/handlers/NFTOffers.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
//------------------------------------------------------------------------------
/*
This file is part of rippled: https://github.com/ripple/rippled
Copyright (c) 2022 Ripple Labs Inc.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
//==============================================================================

#include <ripple/app/main/Application.h>
#include <ripple/json/json_value.h>
Expand Down Expand Up @@ -37,7 +55,7 @@ appendNftOfferJson(
}

// {
// tokenid: <token hash>
// nft_id: <token hash>
// ledger_hash : <ledger>
// ledger_index : <ledger_index>
// limit: integer // optional
Expand All @@ -46,7 +64,7 @@ appendNftOfferJson(
static Json::Value
enumerateNFTOffers(
RPC::JsonContext& context,
uint256 const& tokenid,
uint256 const& nftId,
Keylet const& directory)
{
unsigned int limit;
Expand All @@ -62,7 +80,7 @@ enumerateNFTOffers(
return rpcError(rpcOBJECT_NOT_FOUND);

Json::Value result;
result[jss::tokenid] = to_string(tokenid);
result[jss::nft_id] = to_string(nftId);

Json::Value& jsonOffers(result[jss::offers] = Json::arrayValue);

Expand All @@ -85,7 +103,7 @@ enumerateNFTOffers(

auto const sle = ledger->read(keylet::nftoffer(startAfter));

if (!sle || tokenid != sle->getFieldH256(sfTokenID))
if (!sle || nftId != sle->getFieldH256(sfTokenID))
return rpcError(rpcINVALID_PARAMS);

startHint = sle->getFieldU64(sfOfferNode);
Expand Down Expand Up @@ -134,29 +152,29 @@ enumerateNFTOffers(
Json::Value
doNFTSellOffers(RPC::JsonContext& context)
{
if (!context.params.isMember(jss::tokenid))
return RPC::missing_field_error(jss::tokenid);
if (!context.params.isMember(jss::nft_id))
return RPC::missing_field_error(jss::nft_id);

uint256 tokenid;
uint256 nftId;

if (!tokenid.parseHex(context.params[jss::tokenid].asString()))
return RPC::invalid_field_error(jss::tokenid);
if (!nftId.parseHex(context.params[jss::nft_id].asString()))
return RPC::invalid_field_error(jss::nft_id);

return enumerateNFTOffers(context, tokenid, keylet::nft_sells(tokenid));
return enumerateNFTOffers(context, nftId, keylet::nft_sells(nftId));
}

Json::Value
doNFTBuyOffers(RPC::JsonContext& context)
{
if (!context.params.isMember(jss::tokenid))
return RPC::missing_field_error(jss::tokenid);
if (!context.params.isMember(jss::nft_id))
return RPC::missing_field_error(jss::nft_id);

uint256 tokenid;
uint256 nftId;

if (!tokenid.parseHex(context.params[jss::tokenid].asString()))
return RPC::invalid_field_error(jss::tokenid);
if (!nftId.parseHex(context.params[jss::nft_id].asString()))
return RPC::invalid_field_error(jss::nft_id);

return enumerateNFTOffers(context, tokenid, keylet::nft_buys(tokenid));
return enumerateNFTOffers(context, nftId, keylet::nft_buys(nftId));
}

} // namespace ripple

0 comments on commit 1a932bf

Please sign in to comment.