-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Amendment] If you set a destination on an NFT offer, only that destination can settle through brokerage (fix #4373) #4399
Merged
intelliot
merged 5 commits into
XRPLF:feature/nft-fixes
from
Transia-RnD:xls20brokerfix
Feb 13, 2023
+104
−49
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -112,20 +112,40 @@ NFTokenAcceptOffer::preclaim(PreclaimContext const& ctx) | |
if ((*so)[sfAmount] > (*bo)[sfAmount]) | ||
return tecINSUFFICIENT_PAYMENT; | ||
|
||
// If the buyer specified a destination, that destination must be | ||
// the seller or the broker. | ||
// If the buyer specified a destination | ||
if (auto const dest = bo->at(~sfDestination)) | ||
{ | ||
if (*dest != so->at(sfOwner) && *dest != ctx.tx[sfAccount]) | ||
return tecNFTOKEN_BUY_SELL_MISMATCH; | ||
// fixUnburnableNFToken | ||
if (ctx.view.rules().enabled(fixUnburnableNFToken)) | ||
{ | ||
// the destination may only be the account brokering the offer | ||
if (*dest != ctx.tx[sfAccount]) | ||
return tecNO_PERMISSION; | ||
} | ||
else | ||
{ | ||
// the destination must be the seller or the broker. | ||
if (*dest != so->at(sfOwner) && *dest != ctx.tx[sfAccount]) | ||
return tecNFTOKEN_BUY_SELL_MISMATCH; | ||
} | ||
} | ||
|
||
// If the seller specified a destination, that destination must be | ||
// the buyer or the broker. | ||
// If the seller specified a destination | ||
if (auto const dest = so->at(~sfDestination)) | ||
{ | ||
if (*dest != bo->at(sfOwner) && *dest != ctx.tx[sfAccount]) | ||
return tecNFTOKEN_BUY_SELL_MISMATCH; | ||
// fixUnburnableNFToken | ||
if (ctx.view.rules().enabled(fixUnburnableNFToken)) | ||
{ | ||
// the destination may only be the account brokering the offer | ||
if (*dest != ctx.tx[sfAccount]) | ||
return tecNO_PERMISSION; | ||
} | ||
else | ||
{ | ||
// the destination must be the buyer or the broker. | ||
if (*dest != bo->at(sfOwner) && *dest != ctx.tx[sfAccount]) | ||
return tecNFTOKEN_BUY_SELL_MISMATCH; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto |
||
} | ||
|
||
// The broker can specify an amount that represents their cut; if they | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2872,15 +2872,20 @@ class NFToken_test : public beast::unit_test::suite | |
BEAST_EXPECT(ownerCount(env, minter) == 2); | ||
BEAST_EXPECT(ownerCount(env, buyer) == 1); | ||
|
||
// issuer cannot broker the offers, because they are not the | ||
// Destination. | ||
env(token::brokerOffers( | ||
issuer, offerBuyerToMinter, offerMinterToBroker), | ||
ter(tecNFTOKEN_BUY_SELL_MISMATCH)); | ||
env.close(); | ||
BEAST_EXPECT(ownerCount(env, issuer) == 0); | ||
BEAST_EXPECT(ownerCount(env, minter) == 2); | ||
BEAST_EXPECT(ownerCount(env, buyer) == 1); | ||
{ | ||
// issuer cannot broker the offers, because they are not the | ||
// Destination. | ||
TER const expectTer = features[fixUnburnableNFToken] | ||
? tecNO_PERMISSION | ||
: tecNFTOKEN_BUY_SELL_MISMATCH; | ||
env(token::brokerOffers( | ||
issuer, offerBuyerToMinter, offerMinterToBroker), | ||
ter(expectTer)); | ||
env.close(); | ||
BEAST_EXPECT(ownerCount(env, issuer) == 0); | ||
BEAST_EXPECT(ownerCount(env, minter) == 2); | ||
BEAST_EXPECT(ownerCount(env, buyer) == 1); | ||
} | ||
|
||
// Since broker is the sell offer's destination, they can broker | ||
// the two offers. | ||
|
@@ -2917,29 +2922,52 @@ class NFToken_test : public beast::unit_test::suite | |
BEAST_EXPECT(ownerCount(env, minter) == 1); | ||
BEAST_EXPECT(ownerCount(env, buyer) == 2); | ||
|
||
// Cannot broker offers when the sell destination is not the buyer. | ||
env(token::brokerOffers( | ||
broker, offerIssuerToBuyer, offerBuyerToMinter), | ||
ter(tecNFTOKEN_BUY_SELL_MISMATCH)); | ||
env.close(); | ||
BEAST_EXPECT(ownerCount(env, issuer) == 1); | ||
BEAST_EXPECT(ownerCount(env, minter) == 1); | ||
BEAST_EXPECT(ownerCount(env, buyer) == 2); | ||
{ | ||
// Cannot broker offers when the sell destination is not the | ||
// buyer. | ||
TER const expectTer = features[fixUnburnableNFToken] | ||
? tecNO_PERMISSION | ||
: tecNFTOKEN_BUY_SELL_MISMATCH; | ||
env(token::brokerOffers( | ||
broker, offerIssuerToBuyer, offerBuyerToMinter), | ||
ter(expectTer)); | ||
env.close(); | ||
|
||
// Broker is successful when destination is buyer. | ||
env(token::brokerOffers( | ||
broker, offerMinterToBuyer, offerBuyerToMinter)); | ||
env.close(); | ||
BEAST_EXPECT(ownerCount(env, issuer) == 1); | ||
BEAST_EXPECT(ownerCount(env, minter) == 1); | ||
BEAST_EXPECT(ownerCount(env, buyer) == 0); | ||
BEAST_EXPECT(ownerCount(env, issuer) == 1); | ||
BEAST_EXPECT(ownerCount(env, minter) == 1); | ||
BEAST_EXPECT(ownerCount(env, buyer) == 2); | ||
|
||
// Clean out the unconsumed offer. | ||
env(token::cancelOffer(issuer, {offerIssuerToBuyer})); | ||
env.close(); | ||
BEAST_EXPECT(ownerCount(env, issuer) == 0); | ||
BEAST_EXPECT(ownerCount(env, minter) == 1); | ||
BEAST_EXPECT(ownerCount(env, buyer) == 0); | ||
// amendment switch: When enabled the broker fails, when | ||
// disabled the broker succeeds if the destination is the buyer. | ||
TER const eexpectTer = features[fixUnburnableNFToken] | ||
? tecNO_PERMISSION | ||
: TER(tesSUCCESS); | ||
env(token::brokerOffers( | ||
broker, offerMinterToBuyer, offerBuyerToMinter), | ||
ter(eexpectTer)); | ||
env.close(); | ||
|
||
if (features[fixUnburnableNFToken]) | ||
// Buyer is successful with acceptOffer. | ||
env(token::acceptBuyOffer(buyer, offerMinterToBuyer)); | ||
env.close(); | ||
|
||
// Clean out the unconsumed offer. | ||
env(token::cancelOffer(buyer, {offerBuyerToMinter})); | ||
env.close(); | ||
|
||
BEAST_EXPECT(ownerCount(env, issuer) == 1); | ||
BEAST_EXPECT(ownerCount(env, minter) == 1); | ||
BEAST_EXPECT(ownerCount(env, buyer) == 0); | ||
|
||
// Clean out the unconsumed offer. | ||
env(token::cancelOffer(issuer, {offerIssuerToBuyer})); | ||
env.close(); | ||
BEAST_EXPECT(ownerCount(env, issuer) == 0); | ||
BEAST_EXPECT(ownerCount(env, minter) == 1); | ||
BEAST_EXPECT(ownerCount(env, buyer) == 0); | ||
return; | ||
} | ||
} | ||
|
||
// Show that if a buy and a sell offer both have the same destination, | ||
|
@@ -2957,15 +2985,20 @@ class NFToken_test : public beast::unit_test::suite | |
token::owner(minter), | ||
token::destination(broker)); | ||
|
||
// Cannot broker offers when the sell destination is not the buyer | ||
// or the broker. | ||
env(token::brokerOffers( | ||
issuer, offerBuyerToBroker, offerMinterToBroker), | ||
ter(tecNFTOKEN_BUY_SELL_MISMATCH)); | ||
env.close(); | ||
BEAST_EXPECT(ownerCount(env, issuer) == 0); | ||
BEAST_EXPECT(ownerCount(env, minter) == 2); | ||
BEAST_EXPECT(ownerCount(env, buyer) == 1); | ||
{ | ||
// Cannot broker offers when the sell destination is not the | ||
// buyer or the broker. | ||
TER const expectTer = features[fixUnburnableNFToken] | ||
? tecNO_PERMISSION | ||
: tecNFTOKEN_BUY_SELL_MISMATCH; | ||
env(token::brokerOffers( | ||
issuer, offerBuyerToBroker, offerMinterToBroker), | ||
ter(expectTer)); | ||
env.close(); | ||
BEAST_EXPECT(ownerCount(env, issuer) == 0); | ||
BEAST_EXPECT(ownerCount(env, minter) == 2); | ||
BEAST_EXPECT(ownerCount(env, buyer) == 1); | ||
} | ||
|
||
// Broker is successful if they are the destination of both offers. | ||
env(token::brokerOffers( | ||
|
@@ -5088,4 +5121,4 @@ class NFToken_test : public beast::unit_test::suite | |
|
||
BEAST_DEFINE_TESTSUITE_PRIO(NFToken, tx, ripple, 2); | ||
|
||
} // namespace ripple | ||
} // namespace ripple | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. missing a newline but not a blocker |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's not a blocker, but you are checking the rule twice when you could check it just once with some conditional re-ordering
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I refactored this if you want to check it out.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's better looking to me! this is fine for merge, but IMO I would do this to remove a level of indentation: