rippled
Loading...
Searching...
No Matches
NFTokenCreateOffer.cpp
1//------------------------------------------------------------------------------
2/*
3 This file is part of rippled: https://github.com/ripple/rippled
4 Copyright (c) 2021 Ripple Labs Inc.
5
6 Permission to use, copy, modify, and/or distribute this software for any
7 purpose with or without fee is hereby granted, provided that the above
8 copyright notice and this permission notice appear in all copies.
9
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17*/
18//==============================================================================
19
20#include <xrpld/app/tx/detail/NFTokenCreateOffer.h>
21#include <xrpld/app/tx/detail/NFTokenUtils.h>
22#include <xrpld/ledger/View.h>
23
24#include <xrpl/protocol/Feature.h>
25#include <xrpl/protocol/TxFlags.h>
26
27namespace ripple {
28
31{
32 if (!ctx.rules.enabled(featureNonFungibleTokensV1))
33 return temDISABLED;
34
35 if (auto const ret = preflight1(ctx); !isTesSuccess(ret))
36 return ret;
37
38 auto const txFlags = ctx.tx.getFlags();
39
40 if (txFlags & tfNFTokenCreateOfferMask)
41 return temINVALID_FLAG;
42
43 auto const nftFlags = nft::getFlags(ctx.tx[sfNFTokenID]);
44
45 // Use implementation shared with NFTokenMint
47 ctx.tx[sfAccount],
48 ctx.tx[sfAmount],
49 ctx.tx[~sfDestination],
50 ctx.tx[~sfExpiration],
51 nftFlags,
52 ctx.rules,
53 ctx.tx[~sfOwner],
54 txFlags);
55 !isTesSuccess(notTec))
56 return notTec;
57
58 return preflight2(ctx);
59}
60
61TER
63{
64 if (hasExpired(ctx.view, ctx.tx[~sfExpiration]))
65 return tecEXPIRED;
66
67 uint256 const nftokenID = ctx.tx[sfNFTokenID];
68 std::uint32_t const txFlags = {ctx.tx.getFlags()};
69
70 if (!nft::findToken(
71 ctx.view,
72 ctx.tx[(txFlags & tfSellNFToken) ? sfAccount : sfOwner],
73 nftokenID))
74 return tecNO_ENTRY;
75
76 // Use implementation shared with NFTokenMint
78 ctx.view,
79 ctx.tx[sfAccount],
80 nft::getIssuer(nftokenID),
81 ctx.tx[sfAmount],
82 ctx.tx[~sfDestination],
83 nft::getFlags(nftokenID),
84 nft::getTransferFee(nftokenID),
85 ctx.j,
86 ctx.tx[~sfOwner],
87 txFlags);
88}
89
90TER
92{
93 // Use implementation shared with NFTokenMint
95 view(),
96 ctx_.tx[sfAccount],
97 ctx_.tx[sfAmount],
98 ctx_.tx[~sfDestination],
99 ctx_.tx[~sfExpiration],
101 ctx_.tx[sfNFTokenID],
103 j_,
104 ctx_.tx.getFlags());
105}
106
107} // namespace ripple
static NotTEC preflight(PreflightContext const &ctx)
static TER preclaim(PreclaimContext const &ctx)
bool enabled(uint256 const &feature) const
Returns true if a feature is enabled.
Definition: Rules.cpp:130
std::uint32_t getFlags() const
Definition: STObject.cpp:537
SeqProxy getSeqProxy() const
Definition: STTx.cpp:213
ApplyView & view()
Definition: Transactor.h:109
beast::Journal const j_
Definition: Transactor.h:91
XRPAmount mPriorBalance
Definition: Transactor.h:94
ApplyContext & ctx_
Definition: Transactor.h:90
std::uint16_t getTransferFee(uint256 const &id)
Definition: nft.h:68
std::uint16_t getFlags(uint256 const &id)
Definition: nft.h:60
NotTEC tokenOfferCreatePreflight(AccountID const &acctID, STAmount const &amount, std::optional< AccountID > const &dest, std::optional< std::uint32_t > const &expiration, std::uint16_t nftFlags, Rules const &rules, std::optional< AccountID > const &owner, std::uint32_t txFlags)
Preflight checks shared by NFTokenCreateOffer and NFTokenMint.
TER tokenOfferCreateApply(ApplyView &view, AccountID const &acctID, STAmount const &amount, std::optional< AccountID > const &dest, std::optional< std::uint32_t > const &expiration, SeqProxy seqProxy, uint256 const &nftokenID, XRPAmount const &priorBalance, beast::Journal j, std::uint32_t txFlags)
doApply implementation shared by NFTokenCreateOffer and NFTokenMint
AccountID getIssuer(uint256 const &id)
Definition: nft.h:120
TER tokenOfferCreatePreclaim(ReadView const &view, AccountID const &acctID, AccountID const &nftIssuer, STAmount const &amount, std::optional< AccountID > const &dest, std::uint16_t nftFlags, std::uint16_t xferFee, beast::Journal j, std::optional< AccountID > const &owner, std::uint32_t txFlags)
Preclaim checks shared by NFTokenCreateOffer and NFTokenMint.
std::optional< STObject > findToken(ReadView const &view, AccountID const &owner, uint256 const &nftokenID)
Finds the specified token in the owner's token directory.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: algorithm.h:26
constexpr std::uint32_t const tfNFTokenCreateOfferMask
Definition: TxFlags.h:199
constexpr std::uint32_t const tfSellNFToken
Definition: TxFlags.h:198
bool isTesSuccess(TER x)
Definition: TER.h:672
NotTEC preflight1(PreflightContext const &ctx)
Performs early sanity checks on the account and fee fields.
Definition: Transactor.cpp:83
NotTEC preflight2(PreflightContext const &ctx)
Checks whether the signature appears valid.
Definition: Transactor.cpp:144
@ tecNO_ENTRY
Definition: TER.h:306
@ tecEXPIRED
Definition: TER.h:314
bool hasExpired(ReadView const &view, std::optional< std::uint32_t > const &exp)
Determines whether the given expiration time has passed.
Definition: View.cpp:176
TERSubset< CanCvtToNotTEC > NotTEC
Definition: TER.h:603
@ temINVALID_FLAG
Definition: TER.h:111
@ temDISABLED
Definition: TER.h:114
State information when determining if a tx is likely to claim a fee.
Definition: Transactor.h:55
ReadView const & view
Definition: Transactor.h:58
beast::Journal const j
Definition: Transactor.h:62
State information when preflighting a tx.
Definition: Transactor.h:34