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#include <xrpl/protocol/Feature.h>
24#include <xrpl/protocol/TxFlags.h>
25#include <xrpl/protocol/st.h>
26#include <boost/endian/conversion.hpp>
27
28namespace ripple {
29
32{
33 if (!ctx.rules.enabled(featureNonFungibleTokensV1))
34 return temDISABLED;
35
36 if (auto const ret = preflight1(ctx); !isTesSuccess(ret))
37 return ret;
38
39 auto const txFlags = ctx.tx.getFlags();
40
41 if (txFlags & tfNFTokenCreateOfferMask)
42 return temINVALID_FLAG;
43
44 auto const nftFlags = nft::getFlags(ctx.tx[sfNFTokenID]);
45
46 // Use implementation shared with NFTokenMint
48 ctx.tx[sfAccount],
49 ctx.tx[sfAmount],
50 ctx.tx[~sfDestination],
51 ctx.tx[~sfExpiration],
52 nftFlags,
53 ctx.rules,
54 ctx.tx[~sfOwner],
55 txFlags);
56 !isTesSuccess(notTec))
57 return notTec;
58
59 return preflight2(ctx);
60}
61
62TER
64{
65 if (hasExpired(ctx.view, ctx.tx[~sfExpiration]))
66 return tecEXPIRED;
67
68 uint256 const nftokenID = ctx.tx[sfNFTokenID];
69 std::uint32_t const txFlags = {ctx.tx.getFlags()};
70
71 if (!nft::findToken(
72 ctx.view,
73 ctx.tx[(txFlags & tfSellNFToken) ? sfAccount : sfOwner],
74 nftokenID))
75 return tecNO_ENTRY;
76
77 // Use implementation shared with NFTokenMint
79 ctx.view,
80 ctx.tx[sfAccount],
81 nft::getIssuer(nftokenID),
82 ctx.tx[sfAmount],
83 ctx.tx[~sfDestination],
84 nft::getFlags(nftokenID),
85 nft::getTransferFee(nftokenID),
86 ctx.j,
87 ctx.tx[~sfOwner],
88 txFlags);
89}
90
91TER
93{
94 // Use implementation shared with NFTokenMint
96 view(),
97 ctx_.tx[sfAccount],
98 ctx_.tx[sfAmount],
99 ctx_.tx[~sfDestination],
100 ctx_.tx[~sfExpiration],
102 ctx_.tx[sfNFTokenID],
104 j_,
105 ctx_.tx.getFlags());
106}
107
108} // 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:122
std::uint32_t getFlags() const
Definition: STObject.cpp:507
SeqProxy getSeqProxy() const
Definition: STTx.cpp:186
ApplyView & view()
Definition: Transactor.h:107
beast::Journal const j_
Definition: Transactor.h:89
XRPAmount mPriorBalance
Definition: Transactor.h:92
ApplyContext & ctx_
Definition: Transactor.h:88
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:190
constexpr std::uint32_t const tfSellNFToken
Definition: TxFlags.h:189
bool isTesSuccess(TER x)
Definition: TER.h:656
NotTEC preflight1(PreflightContext const &ctx)
Performs early sanity checks on the account and fee fields.
Definition: Transactor.cpp:82
NotTEC preflight2(PreflightContext const &ctx)
Checks whether the signature appears valid.
Definition: Transactor.cpp:134
@ tecNO_ENTRY
Definition: TER.h:293
@ tecEXPIRED
Definition: TER.h:301
bool hasExpired(ReadView const &view, std::optional< std::uint32_t > const &exp)
Determines whether the given expiration time has passed.
Definition: View.cpp:164
TERSubset< CanCvtToNotTEC > NotTEC
Definition: TER.h:587
@ 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:53
ReadView const & view
Definition: Transactor.h:56
beast::Journal const j
Definition: Transactor.h:60
State information when preflighting a tx.
Definition: Transactor.h:32