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
23#include <xrpl/ledger/View.h>
24#include <xrpl/protocol/Feature.h>
25#include <xrpl/protocol/TxFlags.h>
26
27namespace ripple {
28
34
37{
38 auto const txFlags = ctx.tx.getFlags();
39
40 auto const nftFlags = nft::getFlags(ctx.tx[sfNFTokenID]);
41
42 // Use implementation shared with NFTokenMint
44 ctx.tx[sfAccount],
45 ctx.tx[sfAmount],
46 ctx.tx[~sfDestination],
47 ctx.tx[~sfExpiration],
48 nftFlags,
49 ctx.rules,
50 ctx.tx[~sfOwner],
51 txFlags);
52 !isTesSuccess(notTec))
53 return notTec;
54
55 return tesSUCCESS;
56}
57
58TER
60{
61 if (hasExpired(ctx.view, ctx.tx[~sfExpiration]))
62 return tecEXPIRED;
63
64 uint256 const nftokenID = ctx.tx[sfNFTokenID];
65 std::uint32_t const txFlags = {ctx.tx.getFlags()};
66
67 if (!nft::findToken(
68 ctx.view,
69 ctx.tx[(txFlags & tfSellNFToken) ? sfAccount : sfOwner],
70 nftokenID))
71 return tecNO_ENTRY;
72
73 // Use implementation shared with NFTokenMint
75 ctx.view,
76 ctx.tx[sfAccount],
77 nft::getIssuer(nftokenID),
78 ctx.tx[sfAmount],
79 ctx.tx[~sfDestination],
80 nft::getFlags(nftokenID),
81 nft::getTransferFee(nftokenID),
82 ctx.j,
83 ctx.tx[~sfOwner],
84 txFlags);
85}
86
87TER
89{
90 // Use implementation shared with NFTokenMint
92 view(),
93 ctx_.tx[sfAccount],
94 ctx_.tx[sfAmount],
95 ctx_.tx[~sfDestination],
96 ctx_.tx[~sfExpiration],
98 ctx_.tx[sfNFTokenID],
100 j_,
101 ctx_.tx.getFlags());
102}
103
104} // namespace ripple
static NotTEC preflight(PreflightContext const &ctx)
static TER preclaim(PreclaimContext const &ctx)
static std::uint32_t getFlagsMask(PreflightContext const &ctx)
std::uint32_t getFlags() const
Definition STObject.cpp:537
SeqProxy getSeqProxy() const
Definition STTx.cpp:216
ApplyView & view()
Definition Transactor.h:163
beast::Journal const j_
Definition Transactor.h:145
XRPAmount mPriorBalance
Definition Transactor.h:148
ApplyContext & ctx_
Definition Transactor.h:143
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:25
constexpr std::uint32_t const tfNFTokenCreateOfferMask
Definition TxFlags.h:231
constexpr std::uint32_t const tfSellNFToken
Definition TxFlags.h:230
bool hasExpired(ReadView const &view, std::optional< std::uint32_t > const &exp)
Determines whether the given expiration time has passed.
Definition View.cpp:173
@ tecNO_ENTRY
Definition TER.h:307
@ tecEXPIRED
Definition TER.h:315
@ tesSUCCESS
Definition TER.h:245
bool isTesSuccess(TER x) noexcept
Definition TER.h:678
State information when determining if a tx is likely to claim a fee.
Definition Transactor.h:80
ReadView const & view
Definition Transactor.h:83
beast::Journal const j
Definition Transactor.h:88
State information when preflighting a tx.
Definition Transactor.h:35