#include "util/MPTIssuanceUtils.hpp" #include #include #include #include #include #include #include #include #include #include #include #include #include namespace util { std::optional getMPTokenIssuanceIDFromNode(xrpl::STObject const& node) { auto const entryType = node.getFieldU16(xrpl::sfLedgerEntryType); if (entryType != xrpl::ltMPTOKEN && entryType != xrpl::ltMPTOKEN_ISSUANCE) return std::nullopt; auto const& fieldsName = node.getFName() == xrpl::sfCreatedNode ? xrpl::sfNewFields : xrpl::sfFinalFields; if (not node.isFieldPresent(fieldsName)) return std::nullopt; auto const& fields = node.peekAtField(fieldsName).downcast(); if (entryType == xrpl::ltMPTOKEN) { if (not fields.isFieldPresent(xrpl::sfMPTokenIssuanceID)) return std::nullopt; return fields[xrpl::sfMPTokenIssuanceID]; } // MPTokenIssuance objects carry no sfMPTokenIssuanceID, and the node's ledger key is a // one-way hash that does not embed the ID, so reconstruct it from sfSequence and sfIssuer if (not fields.isFieldPresent(xrpl::sfSequence) || not fields.isFieldPresent(xrpl::sfIssuer)) return std::nullopt; return xrpl::makeMptID( fields.getFieldU32(xrpl::sfSequence), fields.getAccountID(xrpl::sfIssuer) ); } void addMPTokenIssuanceIDsFromTx(MPTokenIssuanceIDs& issuanceIDs, xrpl::STTx const& sttx) { if (sttx.isFieldPresent(xrpl::sfMPTokenIssuanceID)) issuanceIDs.insert(sttx.getFieldH192(xrpl::sfMPTokenIssuanceID)); for (xrpl::STBase const& field : sttx) { switch (field.getSType()) { case xrpl::STI_AMOUNT: { auto const& amount = field.downcast(); if (amount.holds()) issuanceIDs.insert(amount.get().getMptID()); break; } case xrpl::STI_ISSUE: { auto const& issue = field.downcast(); if (issue.holds()) issuanceIDs.insert(issue.value().get().getMptID()); break; } default: break; } } } bool referencesMptIssuance( xrpl::TxMeta const& txMeta, xrpl::STTx const& sttx, xrpl::uint192 const& mptIssuanceID ) { if (txMeta.getResultTER() == xrpl::tesSUCCESS) { for (auto const& node : txMeta.getNodes()) { if (getMPTokenIssuanceIDFromNode(node) == mptIssuanceID) return true; } } MPTokenIssuanceIDs issuanceIDs; addMPTokenIssuanceIDsFromTx(issuanceIDs, sttx); return issuanceIDs.contains(mptIssuanceID); } } // namespace util