Skip to content

Commit

Permalink
[FOLD] Rename SFields to NFTokenOffers and NFTokenOffers
Browse files Browse the repository at this point in the history
  • Loading branch information
scottschurr committed Mar 28, 2022
1 parent 5c6e8a9 commit 8f9167f
Show file tree
Hide file tree
Showing 27 changed files with 270 additions and 254 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 @@ -524,7 +524,7 @@ ValidNFTokenPage::visitEntry(

for (auto const& obj : sle->getFieldArray(sfNonFungibleTokens))
{
if ((obj[sfTokenID] & pageBits) >= limit)
if ((obj[sfNFTokenID] & pageBits) >= limit)
badEntry_ = true;

if (auto uri = obj[~sfURI]; uri && uri->empty())
Expand Down
26 changes: 13 additions & 13 deletions src/ripple/app/tx/impl/NFTokenAcceptOffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ NFTokenAcceptOffer::preclaim(PreclaimContext const& ctx)
auto const so = ctx.view.read(keylet::nftoffer(*sell));

// The two offers being brokered must be for the same token:
if ((*bo)[sfTokenID] != (*so)[sfTokenID])
if ((*bo)[sfNFTokenID] != (*so)[sfNFTokenID])
return tecNFTOKEN_BUY_SELL_MISMATCH;

// The two offers being brokered must be for the same asset:
Expand Down Expand Up @@ -144,7 +144,7 @@ NFTokenAcceptOffer::preclaim(PreclaimContext const& ctx)

// If not in bridged mode, the account must own the token:
if (!sell &&
!nft::findToken(ctx.view, ctx.tx[sfAccount], (*bo)[sfTokenID]))
!nft::findToken(ctx.view, ctx.tx[sfAccount], (*bo)[sfNFTokenID]))
return tecNO_PERMISSION;

// The account offering to buy must have funds:
Expand Down Expand Up @@ -172,7 +172,7 @@ NFTokenAcceptOffer::preclaim(PreclaimContext const& ctx)
return tecCANT_ACCEPT_OWN_NFTOKEN_OFFER;

// The seller must own the token.
if (!nft::findToken(ctx.view, (*so)[sfOwner], (*so)[sfTokenID]))
if (!nft::findToken(ctx.view, (*so)[sfOwner], (*so)[sfNFTokenID]))
return tecNO_PERMISSION;

// If not in bridged mode...
Expand Down Expand Up @@ -222,16 +222,16 @@ NFTokenAcceptOffer::acceptOffer(std::shared_ptr<SLE> const& offer)
AccountID const& seller = isSell ? owner : account_;
AccountID const& buyer = isSell ? account_ : owner;

auto const tokenID = (*offer)[sfTokenID];
auto const nftokenID = (*offer)[sfNFTokenID];

if (auto amount = offer->getFieldAmount(sfAmount); amount != beast::zero)
{
// Calculate the issuer's cut from this sale, if any:
if (auto const fee = nft::getTransferFee(tokenID); fee != 0)
if (auto const fee = nft::getTransferFee(nftokenID); fee != 0)
{
auto const cut = multiply(amount, nft::transferFeeAsRate(fee));

if (auto const issuer = nft::getIssuer(tokenID);
if (auto const issuer = nft::getIssuer(nftokenID);
cut != beast::zero && seller != issuer && buyer != issuer)
{
if (auto const r = pay(buyer, issuer, cut); !isTesSuccess(r))
Expand All @@ -246,13 +246,13 @@ NFTokenAcceptOffer::acceptOffer(std::shared_ptr<SLE> const& offer)
}

// Now transfer the NFT:
auto tokenAndPage = nft::findTokenAndPage(view(), seller, tokenID);
auto tokenAndPage = nft::findTokenAndPage(view(), seller, nftokenID);

if (!tokenAndPage)
return tecINTERNAL;

if (auto const ret = nft::removeToken(
view(), seller, tokenID, std::move(tokenAndPage->page));
view(), seller, nftokenID, std::move(tokenAndPage->page));
!isTesSuccess(ret))
return ret;

Expand Down Expand Up @@ -292,7 +292,7 @@ NFTokenAcceptOffer::doApply()
AccountID const buyer = (*bo)[sfOwner];
AccountID const seller = (*so)[sfOwner];

auto const tokenID = (*so)[sfTokenID];
auto const nftokenID = (*so)[sfNFTokenID];

// The amount is what the buyer of the NFT pays:
STAmount amount = (*bo)[sfAmount];
Expand Down Expand Up @@ -322,12 +322,12 @@ NFTokenAcceptOffer::doApply()
}

// Calculate the issuer's cut, if any.
if (auto const fee = nft::getTransferFee(tokenID);
if (auto const fee = nft::getTransferFee(nftokenID);
amount != beast::zero && fee != 0)
{
auto cut = multiply(amount, nft::transferFeeAsRate(fee));

if (auto const issuer = nft::getIssuer(tokenID);
if (auto const issuer = nft::getIssuer(nftokenID);
seller != issuer && buyer != issuer)
{
if (auto const r = pay(buyer, issuer, cut); !isTesSuccess(r))
Expand All @@ -344,13 +344,13 @@ NFTokenAcceptOffer::doApply()
return r;
}

auto tokenAndPage = nft::findTokenAndPage(view(), seller, tokenID);
auto tokenAndPage = nft::findTokenAndPage(view(), seller, nftokenID);

if (!tokenAndPage)
return tecINTERNAL;

if (auto const ret = nft::removeToken(
view(), seller, tokenID, std::move(tokenAndPage->page));
view(), seller, nftokenID, std::move(tokenAndPage->page));
!isTesSuccess(ret))
return ret;

Expand Down
16 changes: 8 additions & 8 deletions src/ripple/app/tx/impl/NFTokenBurn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,17 @@ NFTokenBurn::preclaim(PreclaimContext const& ctx)
return ctx.tx[sfAccount];
}();

if (!nft::findToken(ctx.view, owner, ctx.tx[sfTokenID]))
if (!nft::findToken(ctx.view, owner, ctx.tx[sfNFTokenID]))
return tecNO_ENTRY;

// The owner of a token can always burn it, but the issuer can only
// do so if the token is marked as burnable.
if (auto const account = ctx.tx[sfAccount]; owner != account)
{
if (!(nft::getFlags(ctx.tx[sfTokenID]) & nft::flagBurnable))
if (!(nft::getFlags(ctx.tx[sfNFTokenID]) & nft::flagBurnable))
return tecNO_PERMISSION;

if (auto const issuer = nft::getIssuer(ctx.tx[sfTokenID]);
if (auto const issuer = nft::getIssuer(ctx.tx[sfNFTokenID]);
issuer != account)
{
if (auto const sle = ctx.view.read(keylet::account(issuer)); sle)
Expand All @@ -76,7 +76,7 @@ NFTokenBurn::preclaim(PreclaimContext const& ctx)
}
}

auto const id = ctx.tx[sfTokenID];
auto const id = ctx.tx[sfNFTokenID];

std::size_t totalOffers = 0;

Expand Down Expand Up @@ -107,23 +107,23 @@ NFTokenBurn::doApply()
view(),
ctx_.tx.isFieldPresent(sfOwner) ? ctx_.tx.getAccountID(sfOwner)
: ctx_.tx.getAccountID(sfAccount),
ctx_.tx[sfTokenID]);
ctx_.tx[sfNFTokenID]);

// Should never happen since preclaim() verified the token is present.
if (!isTesSuccess(ret))
return ret;

if (auto issuer =
view().peek(keylet::account(nft::getIssuer(ctx_.tx[sfTokenID]))))
view().peek(keylet::account(nft::getIssuer(ctx_.tx[sfNFTokenID]))))
{
(*issuer)[~sfBurnedNFTokens] =
(*issuer)[~sfBurnedNFTokens].value_or(0) + 1;
view().update(issuer);
}

// Optimized deletion of all offers.
nft::removeAllTokenOffers(view(), keylet::nft_sells(ctx_.tx[sfTokenID]));
nft::removeAllTokenOffers(view(), keylet::nft_buys(ctx_.tx[sfTokenID]));
nft::removeAllTokenOffers(view(), keylet::nft_sells(ctx_.tx[sfNFTokenID]));
nft::removeAllTokenOffers(view(), keylet::nft_buys(ctx_.tx[sfNFTokenID]));

return tesSUCCESS;
}
Expand Down
8 changes: 4 additions & 4 deletions src/ripple/app/tx/impl/NFTokenCancelOffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ NFTokenCancelOffer::preflight(PreflightContext const& ctx)
if (ctx.tx.getFlags() & tfNFTokenCancelOfferMask)
return temINVALID_FLAG;

if (auto const& ids = ctx.tx[sfTokenOffers];
if (auto const& ids = ctx.tx[sfNFTokenOffers];
ids.empty() || (ids.size() > maxTokenOfferCancelCount))
return temMALFORMED;

// In order to prevent unnecessarily overlarge transactions, we
// disallow duplicates in the list of offers to cancel.
STVector256 ids = ctx.tx.getFieldV256(sfTokenOffers);
STVector256 ids = ctx.tx.getFieldV256(sfNFTokenOffers);
std::sort(ids.begin(), ids.end());
if (std::adjacent_find(ids.begin(), ids.end()) != ids.end())
return temMALFORMED;
Expand All @@ -58,7 +58,7 @@ NFTokenCancelOffer::preclaim(PreclaimContext const& ctx)
{
auto const account = ctx.tx[sfAccount];

auto const& ids = ctx.tx[sfTokenOffers];
auto const& ids = ctx.tx[sfNFTokenOffers];

auto ret = std::find_if(
ids.begin(), ids.end(), [&ctx, &account](uint256 const& id) {
Expand Down Expand Up @@ -98,7 +98,7 @@ NFTokenCancelOffer::preclaim(PreclaimContext const& ctx)
TER
NFTokenCancelOffer::doApply()
{
for (auto const& id : ctx_.tx[sfTokenOffers])
for (auto const& id : ctx_.tx[sfNFTokenOffers])
{
if (auto offer = view().peek(keylet::nftoffer(id));
offer && !nft::deleteTokenOffer(view(), offer))
Expand Down
24 changes: 12 additions & 12 deletions src/ripple/app/tx/impl/NFTokenCreateOffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ NFTokenCreateOffer::preflight(PreflightContext const& ctx)
return temINVALID_FLAG;

auto const account = ctx.tx[sfAccount];
auto const nftFlags = nft::getFlags(ctx.tx[sfTokenID]);
auto const nftFlags = nft::getFlags(ctx.tx[sfNFTokenID]);

{
auto const amount = ctx.tx[sfAmount];
Expand Down Expand Up @@ -97,19 +97,19 @@ NFTokenCreateOffer::preclaim(PreclaimContext const& ctx)
if (hasExpired(ctx.view, ctx.tx[~sfExpiration]))
return tecEXPIRED;

auto const tokenID = ctx.tx[sfTokenID];
auto const nftokenID = ctx.tx[sfNFTokenID];
bool const isSellOffer = ctx.tx.isFlag(tfSellToken);

if (!nft::findToken(
ctx.view, ctx.tx[isSellOffer ? sfAccount : sfOwner], tokenID))
ctx.view, ctx.tx[isSellOffer ? sfAccount : sfOwner], nftokenID))
return tecNO_ENTRY;

auto const nftFlags = nft::getFlags(tokenID);
auto const issuer = nft::getIssuer(tokenID);
auto const nftFlags = nft::getFlags(nftokenID);
auto const issuer = nft::getIssuer(nftokenID);
auto const amount = ctx.tx[sfAmount];

if (!(nftFlags & nft::flagCreateTrustLines) && !amount.native() &&
nft::getTransferFee(tokenID))
nft::getTransferFee(nftokenID))
{
if (!ctx.view.exists(keylet::account(issuer)))
return tecNO_ISSUER;
Expand Down Expand Up @@ -171,7 +171,7 @@ NFTokenCreateOffer::doApply()
mPriorBalance < view().fees().accountReserve((*acct)[sfOwnerCount] + 1))
return tecINSUFFICIENT_RESERVE;

auto const tokenID = ctx_.tx[sfTokenID];
auto const nftokenID = ctx_.tx[sfNFTokenID];

auto const offerID =
keylet::nftoffer(account_, ctx_.tx.getSeqProxy().value());
Expand All @@ -190,13 +190,13 @@ NFTokenCreateOffer::doApply()
// Token offers are also added to the token's buy or sell offer
// directory
auto const offerNode = view().dirInsert(
isSellOffer ? keylet::nft_sells(tokenID)
: keylet::nft_buys(tokenID),
isSellOffer ? keylet::nft_sells(nftokenID)
: keylet::nft_buys(nftokenID),
offerID,
[&tokenID, isSellOffer](std::shared_ptr<SLE> const& sle) {
[&nftokenID, isSellOffer](std::shared_ptr<SLE> const& sle) {
(*sle)[sfFlags] = isSellOffer ? lsfNonFungibleTokenSellOffers
: lsfNonFungibleTokenBuyOffers;
(*sle)[sfTokenID] = tokenID;
(*sle)[sfNFTokenID] = nftokenID;
});

if (!offerNode)
Expand All @@ -209,7 +209,7 @@ NFTokenCreateOffer::doApply()

auto offer = std::make_shared<SLE>(offerID);
(*offer)[sfOwner] = account_;
(*offer)[sfTokenID] = tokenID;
(*offer)[sfNFTokenID] = nftokenID;
(*offer)[sfAmount] = ctx_.tx[sfAmount];
(*offer)[sfFlags] = sleFlags;
(*offer)[sfOwnerNode] = *ownerNode;
Expand Down
6 changes: 3 additions & 3 deletions src/ripple/app/tx/impl/NFTokenMint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ NFTokenMint::preflight(PreflightContext const& ctx)
}

uint256
NFTokenMint::createTokenID(
NFTokenMint::createNFTokenID(
std::uint16_t flags,
std::uint16_t fee,
AccountID const& issuer,
Expand Down Expand Up @@ -176,8 +176,8 @@ NFTokenMint::doApply()
sfNonFungibleToken,
[this, &issuer, &tokenSeq](STObject& object) {
object.setFieldH256(
sfTokenID,
createTokenID(
sfNFTokenID,
createNFTokenID(
static_cast<std::uint16_t>(ctx_.tx.getFlags() & 0x0000FFFF),
ctx_.tx[~sfTransferFee].value_or(0),
issuer,
Expand Down
2 changes: 1 addition & 1 deletion src/ripple/app/tx/impl/NFTokenMint.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class NFTokenMint : public Transactor

// Public to support unit tests.
static uint256
createTokenID(
createNFTokenID(
std::uint16_t flags,
std::uint16_t fee,
AccountID const& issuer,
Expand Down
12 changes: 6 additions & 6 deletions src/ripple/app/tx/impl/Transactor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -718,7 +718,7 @@ removeUnfundedOffers(
}

static void
removeExpiredTokenOffers(
removeExpiredNFTokenOffers(
ApplyView& view,
std::vector<uint256> const& offers,
beast::Journal viewJ)
Expand Down Expand Up @@ -858,11 +858,11 @@ Transactor::operator()()
});
}

std::vector<uint256> expiredTokenOffers;
std::vector<uint256> expiredNFTokenOffers;

if (result == tecEXPIRED)
{
ctx_.visit([&expiredTokenOffers](
ctx_.visit([&expiredNFTokenOffers](
uint256 const& index,
bool isDelete,
std::shared_ptr<SLE const> const& before,
Expand All @@ -872,7 +872,7 @@ Transactor::operator()()
assert(before && after);
if (before && after &&
(before->getType() == ltNFTOKEN_OFFER))
expiredTokenOffers.push_back(index);
expiredNFTokenOffers.push_back(index);
}
});
}
Expand All @@ -892,8 +892,8 @@ Transactor::operator()()
view(), removedOffers, ctx_.app.journal("View"));

if (result == tecEXPIRED)
removeExpiredTokenOffers(
view(), expiredTokenOffers, ctx_.app.journal("View"));
removeExpiredNFTokenOffers(
view(), expiredNFTokenOffers, ctx_.app.journal("View"));

applied = isTecClaim(result);
}
Expand Down
Loading

0 comments on commit 8f9167f

Please sign in to comment.