rippled
Loading...
Searching...
No Matches
MPTokenIssuanceID.cpp
1#include <xrpld/rpc/MPTokenIssuanceID.h>
2
3namespace xrpl {
4
5namespace RPC {
6
7bool
9 std::shared_ptr<STTx const> const& serializedTx,
10 TxMeta const& transactionMeta)
11{
12 if (!serializedTx)
13 return false;
14
15 TxType const tt = serializedTx->getTxnType();
16 if (tt != ttMPTOKEN_ISSUANCE_CREATE)
17 return false;
18
19 // if the transaction failed nothing could have been delivered.
20 if (transactionMeta.getResultTER() != tesSUCCESS)
21 return false;
22
23 return true;
24}
25
27getIDFromCreatedIssuance(TxMeta const& transactionMeta)
28{
29 for (STObject const& node : transactionMeta.getNodes())
30 {
31 if (node.getFieldU16(sfLedgerEntryType) != ltMPTOKEN_ISSUANCE ||
32 node.getFName() != sfCreatedNode)
33 continue;
34
35 auto const& mptNode = node.peekAtField(sfNewFields).downcast<STObject>();
36 return makeMptID(mptNode.getFieldU32(sfSequence), mptNode.getAccountID(sfIssuer));
37 }
38
39 return std::nullopt;
40}
41
42void
44 Json::Value& response,
45 std::shared_ptr<STTx const> const& transaction,
46 TxMeta const& transactionMeta)
47{
48 if (!canHaveMPTokenIssuanceID(transaction, transactionMeta))
49 return;
50
51 std::optional<uint192> result = getIDFromCreatedIssuance(transactionMeta);
52 if (result)
53 response[jss::mpt_issuance_id] = to_string(result.value());
54}
55
56} // namespace RPC
57} // namespace xrpl
Represents a JSON value.
Definition json_value.h:130
TER getResultTER() const
Definition TxMeta.h:37
STArray & getNodes()
Definition TxMeta.h:69
T is_same_v
std::optional< uint192 > getIDFromCreatedIssuance(TxMeta const &transactionMeta)
void insertMPTokenIssuanceID(Json::Value &response, std::shared_ptr< STTx const > const &transaction, TxMeta const &transactionMeta)
bool canHaveMPTokenIssuanceID(std::shared_ptr< STTx const > const &serializedTx, TxMeta const &transactionMeta)
Add a mpt_issuance_id field to the meta input/output parameter.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
TxType
Transaction type identifiers.
Definition TxFormats.h:37
std::string to_string(base_uint< Bits, Tag > const &a)
Definition base_uint.h:600
MPTID makeMptID(std::uint32_t sequence, AccountID const &account)
Definition Indexes.cpp:151
@ tesSUCCESS
Definition TER.h:225
T value(T... args)