rippled
Loading...
Searching...
No Matches
MPTokenIssuanceID.cpp
1#include <xrpld/rpc/MPTokenIssuanceID.h>
2
3namespace ripple {
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 =
36 node.peekAtField(sfNewFields).downcast<STObject>();
37 return makeMptID(
38 mptNode.getFieldU32(sfSequence), mptNode.getAccountID(sfIssuer));
39 }
40
41 return std::nullopt;
42}
43
44void
46 Json::Value& response,
47 std::shared_ptr<STTx const> const& transaction,
48 TxMeta const& transactionMeta)
49{
50 if (!canHaveMPTokenIssuanceID(transaction, transactionMeta))
51 return;
52
53 std::optional<uint192> result = getIDFromCreatedIssuance(transactionMeta);
54 if (result)
55 response[jss::mpt_issuance_id] = to_string(result.value());
56}
57
58} // namespace RPC
59} // namespace ripple
Represents a JSON value.
Definition json_value.h:130
STArray & getNodes()
Definition TxMeta.h:70
TER getResultTER() const
Definition TxMeta.h:38
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
@ tesSUCCESS
Definition TER.h:226
std::string to_string(base_uint< Bits, Tag > const &a)
Definition base_uint.h:611
MPTID makeMptID(std::uint32_t sequence, AccountID const &account)
Definition Indexes.cpp:151
T value(T... args)