rippled
Loading...
Searching...
No Matches
MPTokenIssuanceID.cpp
1#include <xrpld/rpc/MPTokenIssuanceID.h>
2
3namespace xrpl {
4
5namespace RPC {
6
7bool
8canHaveMPTokenIssuanceID(std::shared_ptr<STTx const> const& serializedTx, TxMeta const& transactionMeta)
9{
10 if (!serializedTx)
11 return false;
12
13 TxType const tt = serializedTx->getTxnType();
14 if (tt != ttMPTOKEN_ISSUANCE_CREATE)
15 return false;
16
17 // if the transaction failed nothing could have been delivered.
18 if (transactionMeta.getResultTER() != tesSUCCESS)
19 return false;
20
21 return true;
22}
23
25getIDFromCreatedIssuance(TxMeta const& transactionMeta)
26{
27 for (STObject const& node : transactionMeta.getNodes())
28 {
29 if (node.getFieldU16(sfLedgerEntryType) != ltMPTOKEN_ISSUANCE || node.getFName() != sfCreatedNode)
30 continue;
31
32 auto const& mptNode = node.peekAtField(sfNewFields).downcast<STObject>();
33 return makeMptID(mptNode.getFieldU32(sfSequence), mptNode.getAccountID(sfIssuer));
34 }
35
36 return std::nullopt;
37}
38
39void
41 Json::Value& response,
42 std::shared_ptr<STTx const> const& transaction,
43 TxMeta const& transactionMeta)
44{
45 if (!canHaveMPTokenIssuanceID(transaction, transactionMeta))
46 return;
47
48 std::optional<uint192> result = getIDFromCreatedIssuance(transactionMeta);
49 if (result)
50 response[jss::mpt_issuance_id] = to_string(result.value());
51}
52
53} // namespace RPC
54} // namespace xrpl
Represents a JSON value.
Definition json_value.h:131
TER getResultTER() const
Definition TxMeta.h:38
STArray & getNodes()
Definition TxMeta.h:70
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:6
TxType
Transaction type identifiers.
Definition TxFormats.h:38
std::string to_string(base_uint< Bits, Tag > const &a)
Definition base_uint.h:598
MPTID makeMptID(std::uint32_t sequence, AccountID const &account)
Definition Indexes.cpp:146
@ tesSUCCESS
Definition TER.h:226
T value(T... args)