xrpld
Toggle main menu visibility
Loading...
Searching...
No Matches
libxrpl
protocol
NFTokenOfferID.cpp
1
#include <xrpl/protocol/NFTokenOfferID.h>
2
3
#include <xrpl/basics/base_uint.h>
4
#include <xrpl/json/json_value.h>
5
#include <xrpl/protocol/LedgerFormats.h>
6
#include <xrpl/protocol/SField.h>
7
#include <xrpl/protocol/STObject.h>
8
#include <xrpl/protocol/STTx.h>
9
#include <xrpl/protocol/TER.h>
10
#include <xrpl/protocol/TxFormats.h>
11
#include <xrpl/protocol/TxMeta.h>
12
#include <xrpl/protocol/jss.h>
13
14
#include <
memory
>
15
#include <
optional
>
16
17
namespace
xrpl
{
18
19
bool
20
canHaveNFTokenOfferID
(
21
std::shared_ptr<STTx const>
const
& serializedTx,
22
TxMeta
const
& transactionMeta)
23
{
24
if
(!serializedTx)
25
return
false
;
26
27
TxType
const
tt = serializedTx->getTxnType();
28
if
((tt != ttNFTOKEN_MINT || !serializedTx->isFieldPresent(sfAmount)) &&
29
tt != ttNFTOKEN_CREATE_OFFER)
30
return
false
;
31
32
// if the transaction failed nothing could have been delivered.
33
if
(!
isTesSuccess
(transactionMeta.
getResultTER
()))
34
return
false
;
35
36
return
true
;
37
}
38
39
std::optional<UInt256>
40
getOfferIDFromCreatedOffer
(
TxMeta
const
& transactionMeta)
41
{
42
for
(
STObject
const
& node : transactionMeta.
getNodes
())
43
{
44
if
(node.getFieldU16(sfLedgerEntryType) != ltNFTOKEN_OFFER ||
45
node.getFName() != sfCreatedNode)
46
continue
;
47
48
return
node.getFieldH256(sfLedgerIndex);
49
}
50
return
std::nullopt;
51
}
52
53
void
54
insertNFTokenOfferID
(
55
json::Value
& response,
56
std::shared_ptr<STTx const>
const
& transaction,
57
TxMeta
const
& transactionMeta)
58
{
59
if
(!
canHaveNFTokenOfferID
(transaction, transactionMeta))
60
return
;
61
62
std::optional<UInt256>
result =
getOfferIDFromCreatedOffer
(transactionMeta);
63
64
if
(result.
has_value
())
65
response[jss::offer_id] =
to_string
(result.
value
());
66
}
67
68
}
// namespace xrpl
json::Value
Represents a JSON value.
Definition
json_value.h:117
xrpl::STObject
Definition
STObject.h:49
xrpl::TxMeta
Definition
TxMeta.h:26
xrpl::TxMeta::getResultTER
TER getResultTER() const
Definition
TxMeta.h:48
xrpl::TxMeta::getNodes
STArray & getNodes()
Definition
TxMeta.h:82
memory
xrpl
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition
algorithm.h:5
xrpl::insertNFTokenOfferID
void insertNFTokenOfferID(json::Value &response, std::shared_ptr< STTx const > const &transaction, TxMeta const &transactionMeta)
Definition
NFTokenOfferID.cpp:54
xrpl::TxType
TxType
Transaction type identifiers.
Definition
TxFormats.h:45
xrpl::getOfferIDFromCreatedOffer
std::optional< UInt256 > getOfferIDFromCreatedOffer(TxMeta const &transactionMeta)
Definition
NFTokenOfferID.cpp:40
xrpl::to_string
std::string to_string(BaseUInt< Bits, Tag > const &a)
Definition
base_uint.h:657
xrpl::canHaveNFTokenOfferID
bool canHaveNFTokenOfferID(std::shared_ptr< STTx const > const &serializedTx, TxMeta const &transactionMeta)
Add an offer_id field to the meta output parameter.
Definition
NFTokenOfferID.cpp:20
xrpl::isTesSuccess
bool isTesSuccess(TER x) noexcept
Definition
TER.h:683
std::optional::has_value
T has_value(T... args)
optional
std::shared_ptr
std::optional::value
T value(T... args)
Generated by
1.17.0