Skip to content

Commit

Permalink
[FOLD] Rename SFields to NFToken and NFTokens
Browse files Browse the repository at this point in the history
  • Loading branch information
scottschurr committed Mar 29, 2022
1 parent 7b5ecf3 commit af7c54e
Show file tree
Hide file tree
Showing 18 changed files with 70 additions and 78 deletions.
2 changes: 1 addition & 1 deletion src/ripple/app/tx/impl/InvariantCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ ValidNFTokenPage::visitEntry(
badLink_ = true;
}

for (auto const& obj : sle->getFieldArray(sfNonFungibleTokens))
for (auto const& obj : sle->getFieldArray(sfNFTokens))
{
if ((obj[sfNFTokenID] & pageBits) >= limit)
badEntry_ = true;
Expand Down
6 changes: 3 additions & 3 deletions src/ripple/app/tx/impl/NFTokenAcceptOffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ NFTokenAcceptOffer::preclaim(PreclaimContext const& ctx)
{
auto const bo = ctx.view.read(keylet::nftoffer(*buy));

if (((*bo)[sfFlags] & lsfSellToken) == lsfSellToken)
if (((*bo)[sfFlags] & lsfSellNFToken) == lsfSellNFToken)
return tecNFTOKEN_OFFER_TYPE_MISMATCH;

// An account can't accept an offer it placed:
Expand Down Expand Up @@ -164,7 +164,7 @@ NFTokenAcceptOffer::preclaim(PreclaimContext const& ctx)
{
auto const so = ctx.view.read(keylet::nftoffer(*sell));

if (((*so)[sfFlags] & lsfSellToken) != lsfSellToken)
if (((*so)[sfFlags] & lsfSellNFToken) != lsfSellNFToken)
return tecNFTOKEN_OFFER_TYPE_MISMATCH;

// An account can't accept an offer it placed:
Expand Down Expand Up @@ -217,7 +217,7 @@ NFTokenAcceptOffer::pay(
TER
NFTokenAcceptOffer::acceptOffer(std::shared_ptr<SLE> const& offer)
{
bool const isSell = offer->isFlag(lsfSellToken);
bool const isSell = offer->isFlag(lsfSellNFToken);
AccountID const owner = (*offer)[sfOwner];
AccountID const& seller = isSell ? owner : account_;
AccountID const& buyer = isSell ? account_ : owner;
Expand Down
6 changes: 3 additions & 3 deletions src/ripple/app/tx/impl/NFTokenCreateOffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,8 @@ NFTokenCreateOffer::doApply()
: keylet::nft_buys(nftokenID),
offerID,
[&nftokenID, isSellOffer](std::shared_ptr<SLE> const& sle) {
(*sle)[sfFlags] = isSellOffer ? lsfNonFungibleTokenSellOffers
: lsfNonFungibleTokenBuyOffers;
(*sle)[sfFlags] =
isSellOffer ? lsfNFTokenSellOffers : lsfNFTokenBuyOffers;
(*sle)[sfNFTokenID] = nftokenID;
});

Expand All @@ -206,7 +206,7 @@ NFTokenCreateOffer::doApply()
std::uint32_t sleFlags = 0;

if (isSellOffer)
sleFlags |= lsfSellToken;
sleFlags |= lsfSellNFToken;

auto offer = std::make_shared<SLE>(offerID);
(*offer)[sfOwner] = account_;
Expand Down
5 changes: 2 additions & 3 deletions src/ripple/app/tx/impl/NFTokenMint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,16 +165,15 @@ NFTokenMint::doApply()

// Assemble the new NFToken.
SOTemplate const* nfTokenTemplate =
InnerObjectFormats::getInstance().findSOTemplateBySField(
sfNonFungibleToken);
InnerObjectFormats::getInstance().findSOTemplateBySField(sfNFToken);

if (nfTokenTemplate == nullptr)
// Should never happen.
return tecINTERNAL;

STObject newToken(
*nfTokenTemplate,
sfNonFungibleToken,
sfNFToken,
[this, &issuer, &tokenSeq](STObject& object) {
object.setFieldH256(
sfNFTokenID,
Expand Down
26 changes: 13 additions & 13 deletions src/ripple/app/tx/impl/details/NFTokenUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,13 @@ getPageForToken(
{
STArray arr;
cp = std::make_shared<SLE>(last);
cp->setFieldArray(sfNonFungibleTokens, arr);
cp->setFieldArray(sfNFTokens, arr);
view.insert(cp);
createCallback(view, owner);
return cp;
}

STArray narr = cp->getFieldArray(sfNonFungibleTokens);
STArray narr = cp->getFieldArray(sfNFTokens);

// The right page still has space: we're good.
if (narr.size() != dirMaxTokensPerPage)
Expand Down Expand Up @@ -150,7 +150,7 @@ getPageForToken(

auto np = std::make_shared<SLE>(
keylet::nftpage(base, carr[0].getFieldH256(sfNFTokenID)));
np->setFieldArray(sfNonFungibleTokens, narr);
np->setFieldArray(sfNFTokens, narr);
np->setFieldH256(sfNextPageMin, cp->key());

if (auto ppm = (*cp)[~sfPreviousPageMin])
Expand All @@ -166,7 +166,7 @@ getPageForToken(

view.insert(np);

cp->setFieldArray(sfNonFungibleTokens, carr);
cp->setFieldArray(sfNFTokens, carr);
cp->setFieldH256(sfPreviousPageMin, np->key());
view.update(cp);

Expand Down Expand Up @@ -215,15 +215,15 @@ insertToken(ApplyView& view, AccountID owner, STObject&& nft)
return tecNO_SUITABLE_NFTOKEN_PAGE;

{
auto arr = page->getFieldArray(sfNonFungibleTokens);
auto arr = page->getFieldArray(sfNFTokens);
arr.push_back(std::move(nft));

arr.sort([](STObject const& o1, STObject const& o2) {
return compareTokens(
o1.getFieldH256(sfNFTokenID), o2.getFieldH256(sfNFTokenID));
});

page->setFieldArray(sfNonFungibleTokens, arr);
page->setFieldArray(sfNFTokens, arr);
}

view.update(page);
Expand All @@ -246,8 +246,8 @@ mergePages(
if ((*p2)[~sfPreviousPageMin] != p1->key())
Throw<std::runtime_error>("mergePages: previous link broken!");

auto const p1arr = p1->getFieldArray(sfNonFungibleTokens);
auto const p2arr = p2->getFieldArray(sfNonFungibleTokens);
auto const p1arr = p1->getFieldArray(sfNFTokens);
auto const p2arr = p2->getFieldArray(sfNFTokens);

// Now check whether to merge the two pages; it only makes sense to do
// this it would mean that one of them can be deleted as a result of
Expand All @@ -269,7 +269,7 @@ mergePages(
a.getFieldH256(sfNFTokenID), b.getFieldH256(sfNFTokenID));
});

p2->setFieldArray(sfNonFungibleTokens, x);
p2->setFieldArray(sfNFTokens, x);

// So, at this point we need to unlink "p1" (since we just emptied it) but
// we need to first relink the directory: if p1 has a previous page (p0),
Expand Down Expand Up @@ -318,7 +318,7 @@ removeToken(
std::shared_ptr<SLE>&& curr)
{
// We found a page, but the given NFT may not be in it.
auto arr = curr->getFieldArray(sfNonFungibleTokens);
auto arr = curr->getFieldArray(sfNFTokens);

{
auto x = std::find_if(
Expand Down Expand Up @@ -359,7 +359,7 @@ removeToken(
// The current page isn't empty. Update it and then try to consolidate
// pages. Note that this consolidation attempt may actually merge three
// pages into one!
curr->setFieldArray(sfNonFungibleTokens, arr);
curr->setFieldArray(sfNFTokens, arr);
view.update(curr);

int cnt = 0;
Expand Down Expand Up @@ -444,7 +444,7 @@ findToken(
return std::nullopt;

// We found a candidate page, but the given NFT may not be in it.
for (auto const& t : page->getFieldArray(sfNonFungibleTokens))
for (auto const& t : page->getFieldArray(sfNFTokens))
{
if (t[sfNFTokenID] == nftokenID)
return t;
Expand All @@ -466,7 +466,7 @@ findTokenAndPage(
return std::nullopt;

// We found a candidate page, but the given NFT may not be in it.
for (auto const& t : page->getFieldArray(sfNonFungibleTokens))
for (auto const& t : page->getFieldArray(sfNFTokens))
{
if (t[sfNFTokenID] == nftokenID)
// This std::optional constructor is explicit, so it is spelled out.
Expand Down
2 changes: 1 addition & 1 deletion src/ripple/proto/org/xrpl/rpc/v1/common.proto
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,7 @@ message URI
// *** Aggregate type messages

// Next field: 3
message NonFungibleToken
message NFToken
{
NFTokenID nftoken_id = 1;

Expand Down
2 changes: 1 addition & 1 deletion src/ripple/proto/org/xrpl/rpc/v1/ledger_objects.proto
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ message NFTokenPage

NextPageMin next_page_min = 3;

repeated NonFungibleToken non_fungible_tokens = 4;
repeated NFToken nftokens = 4;

PreviousTransactionID previous_transaction_id = 5;

Expand Down
6 changes: 3 additions & 3 deletions src/ripple/protocol/LedgerFormats.h
Original file line number Diff line number Diff line change
Expand Up @@ -251,11 +251,11 @@ enum LedgerSpecificFlags {
lsfOneOwnerCount = 0x00010000, // True, uses only one OwnerCount

// ltDIR_NODE
lsfNonFungibleTokenBuyOffers = 0x00000001,
lsfNonFungibleTokenSellOffers = 0x00000002,
lsfNFTokenBuyOffers = 0x00000001,
lsfNFTokenSellOffers = 0x00000002,

// ltNFTOKEN_OFFER
lsfSellToken = 0x00000001,
lsfSellNFToken = 0x00000001,
};

//------------------------------------------------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions src/ripple/protocol/SField.h
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ extern SField const sfNewFields;
extern SField const sfTemplateEntry;
extern SField const sfMemo;
extern SField const sfSignerEntry;
extern SField const sfNonFungibleToken;
extern SField const sfNFToken;

extern SField const sfSigner;
extern SField const sfMajority;
Expand All @@ -533,7 +533,7 @@ extern SField const sfAffectedNodes;
extern SField const sfMemos;
extern SField const sfMajorities;
extern SField const sfDisabledValidators;
extern SField const sfNonFungibleTokens;
extern SField const sfNFTokens;

//------------------------------------------------------------------------------

Expand Down
4 changes: 2 additions & 2 deletions src/ripple/protocol/impl/InnerObjectFormats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ InnerObjectFormats::InnerObjectFormats()
{sfFirstLedgerSequence, soeREQUIRED},
});

add(sfNonFungibleToken.jsonName.c_str(),
sfNonFungibleToken.getCode(),
add(sfNFToken.jsonName.c_str(),
sfNFToken.getCode(),
{
{sfNFTokenID, soeREQUIRED},
{sfURI, soeOPTIONAL},
Expand Down
2 changes: 1 addition & 1 deletion src/ripple/protocol/impl/LedgerFormats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ LedgerFormats::LedgerFormats()
{
{sfPreviousPageMin, soeOPTIONAL},
{sfNextPageMin, soeOPTIONAL},
{sfNonFungibleTokens, soeREQUIRED},
{sfNFTokens, soeREQUIRED},
{sfPreviousTxnID, soeREQUIRED},
{sfPreviousTxnLgrSeq, soeREQUIRED}
},
Expand Down
4 changes: 2 additions & 2 deletions src/ripple/protocol/impl/SField.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ CONSTRUCT_UNTYPED_SFIELD(sfNewFields, "NewFields", OBJECT,
CONSTRUCT_UNTYPED_SFIELD(sfTemplateEntry, "TemplateEntry", OBJECT, 9);
CONSTRUCT_UNTYPED_SFIELD(sfMemo, "Memo", OBJECT, 10);
CONSTRUCT_UNTYPED_SFIELD(sfSignerEntry, "SignerEntry", OBJECT, 11);
CONSTRUCT_UNTYPED_SFIELD(sfNonFungibleToken, "NonFungibleToken", OBJECT, 12);
CONSTRUCT_UNTYPED_SFIELD(sfNFToken, "NFToken", OBJECT, 12);

// inner object (uncommon)
CONSTRUCT_UNTYPED_SFIELD(sfSigner, "Signer", OBJECT, 16);
Expand All @@ -287,7 +287,7 @@ CONSTRUCT_UNTYPED_SFIELD(sfNecessary, "Necessary", ARRAY,
CONSTRUCT_UNTYPED_SFIELD(sfSufficient, "Sufficient", ARRAY, 7);
CONSTRUCT_UNTYPED_SFIELD(sfAffectedNodes, "AffectedNodes", ARRAY, 8);
CONSTRUCT_UNTYPED_SFIELD(sfMemos, "Memos", ARRAY, 9);
CONSTRUCT_UNTYPED_SFIELD(sfNonFungibleTokens, "NonFungibleTokens", ARRAY, 10);
CONSTRUCT_UNTYPED_SFIELD(sfNFTokens, "NFTokens", ARRAY, 10);

// array of objects (uncommon)
CONSTRUCT_UNTYPED_SFIELD(sfMajorities, "Majorities", ARRAY, 16);
Expand Down
5 changes: 2 additions & 3 deletions src/ripple/rpc/handlers/AccountObjects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,7 @@ doAccountNFTs(RPC::JsonContext& context)
return rpcError(rpcACT_NOT_FOUND);

unsigned int limit;
if (auto err = readLimitField(
limit, RPC::Tuning::accountNonFungibleTokens, context))
if (auto err = readLimitField(limit, RPC::Tuning::accountNFTokens, context))
return *err;

uint256 marker;
Expand Down Expand Up @@ -105,7 +104,7 @@ doAccountNFTs(RPC::JsonContext& context)

while (cp)
{
auto arr = cp->getFieldArray(sfNonFungibleTokens);
auto arr = cp->getFieldArray(sfNFTokens);

for (auto const& o : arr)
{
Expand Down
10 changes: 5 additions & 5 deletions src/ripple/rpc/impl/GRPCHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1078,17 +1078,17 @@ populateMajorities(T& to, STObject const& from)

template <class T>
void
populateNonFungibleTokens(T& to, STObject const& from)
populateNFTokens(T& to, STObject const& from)
{
populateProtoArray(
[&to]() { return to.add_non_fungible_tokens(); },
[&to]() { return to.add_nftokens(); },
[](auto innerObj, auto innerProto) {
populateNFTokenID(innerProto, innerObj);
populateURI(innerProto, innerObj);
},
from,
sfNonFungibleTokens,
sfNonFungibleToken);
sfNFTokens,
sfNFToken);
}

void
Expand Down Expand Up @@ -1742,7 +1742,7 @@ convert(org::xrpl::rpc::v1::NFTokenPage& to, STObject const& from)

populateNextPageMin(to, from);

populateNonFungibleTokens(to, from);
populateNFTokens(to, from);

populatePreviousTransactionID(to, from);

Expand Down
2 changes: 1 addition & 1 deletion src/ripple/rpc/impl/Tuning.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ static LimitRange constexpr bookOffers = {0, 60, 100};
static LimitRange constexpr noRippleCheck = {10, 300, 400};

/** Limits for the account_nftokens command, in pages. */
static LimitRange constexpr accountNonFungibleTokens = {20, 100, 400};
static LimitRange constexpr accountNFTokens = {20, 100, 400};

/** Limits for the nft_buy_offers & nft_sell_offers commands. */
static LimitRange constexpr nftOffers = {50, 250, 500};
Expand Down
Loading

0 comments on commit af7c54e

Please sign in to comment.