diff --git a/src/feed/impl/TransactionFeed.cpp b/src/feed/impl/TransactionFeed.cpp index 0b2b9207..be79956b 100644 --- a/src/feed/impl/TransactionFeed.cpp +++ b/src/feed/impl/TransactionFeed.cpp @@ -209,8 +209,9 @@ TransactionFeed::pub( rpc::insertDeliveredAmount(pubObj[JS(meta)].as_object(), tx, meta, txMeta.date); auto& txnPubobj = pubObj[txKey].as_object(); + auto& metaPubobj = pubObj[JS(meta)].as_object(); rpc::insertDeliverMaxAlias(txnPubobj, version); - rpc::insertMPTIssuanceID(txnPubobj, meta); + rpc::insertMPTIssuanceID(txnPubobj, tx, metaPubobj, meta); Json::Value nftJson; ripple::RPC::insertNFTSyntheticInJson(nftJson, tx, *meta); diff --git a/src/rpc/RPCHelpers.cpp b/src/rpc/RPCHelpers.cpp index eea6c9ea..08e16798 100644 --- a/src/rpc/RPCHelpers.cpp +++ b/src/rpc/RPCHelpers.cpp @@ -258,7 +258,7 @@ toExpandedJson( auto metaJson = toJson(*meta); insertDeliveredAmount(metaJson, txn, meta, blobs.date); insertDeliverMaxAlias(txnJson, apiVersion); - insertMPTIssuanceID(txnJson, meta); + insertMPTIssuanceID(txnJson, txn, metaJson, meta); if (nftEnabled == NFTokenjson::ENABLE) { Json::Value nftJson; @@ -343,36 +343,41 @@ getMPTIssuanceID(std::shared_ptr const& meta) /** * @brief Check if transaction has a new MPToken created * - * @param txnJson The transaction Json - * @param meta The metadata + * @param txn The transaction object + * @param meta The metadata object * @return true if the transaction can have a mpt_issuance_id */ static bool -canHaveMPTIssuanceID(boost::json::object const& txnJson, std::shared_ptr const& meta) +canHaveMPTIssuanceID(std::shared_ptr const& txn, std::shared_ptr const& meta) { - if (txnJson.at(JS(TransactionType)).is_string() and - not boost::iequals(txnJson.at(JS(TransactionType)).as_string(), JS(MPTokenIssuanceCreate))) + if (txn->getTxnType() != ripple::ttMPTOKEN_ISSUANCE_CREATE) return false; - if (meta->getResultTER() != ripple::tesSUCCESS) - return false; - - return true; + return (meta->getResultTER() == ripple::tesSUCCESS); } bool -insertMPTIssuanceID(boost::json::object& txnJson, std::shared_ptr const& meta) +insertMPTIssuanceID( + boost::json::object& txnJson, + std::shared_ptr const& txn, + boost::json::object& metaJson, + std::shared_ptr const& meta +) { - if (!canHaveMPTIssuanceID(txnJson, meta)) - return false; - - if (txnJson.contains(JS(TransactionType)) && txnJson.at(JS(TransactionType)).is_string() and - txnJson.at(JS(TransactionType)).as_string() == JS(MPTokenIssuanceCreate)) + if (!canHaveMPTIssuanceID(txn, meta)) return false; auto const id = getMPTIssuanceID(meta); ASSERT(id.has_value(), "MPTIssuanceID must have value"); - txnJson[JS(mpt_issuance_id)] = ripple::to_string(*id); + + // For mpttokenissuance create, add mpt_issuance_id to metajson + // Otherwise, add it to txn json + if (txnJson.contains(JS(TransactionType)) && txnJson.at(JS(TransactionType)).is_string() and + txnJson.at(JS(TransactionType)).as_string() == JS(MPTokenIssuanceCreate)) { + metaJson[JS(mpt_issuance_id)] = ripple::to_string(*id); + } else { + txnJson[JS(mpt_issuance_id)] = ripple::to_string(*id); + } return true; } diff --git a/src/rpc/RPCHelpers.hpp b/src/rpc/RPCHelpers.hpp index 9dfe4e55..5d3f9bb9 100644 --- a/src/rpc/RPCHelpers.hpp +++ b/src/rpc/RPCHelpers.hpp @@ -201,15 +201,23 @@ insertDeliveredAmount( /** * @brief Add "mpt_issuance_id" into various MPTToken transaction json. - * @note We exclude "mpt_issuance_id" for MPTokenIssuanceCreate only. The reason is because the mpt_issuance_id - * is generated only after one submits MPTokenIssuanceCreate, so there’s no way to know what the id is. (rippled) + * @note We add "mpt_issuance_id" into the meta part of MPTokenIssuanceCreate only. The reason is because the + * mpt_issuance_id is generated only after one submits MPTokenIssuanceCreate, so there’s no way to know what the id is. + * (rippled) * * @param txnJson The transaction Json object + * @param txn The txn object + * @param metaJson The metadata Json object * @param meta The metadata object - * @return true if the "mpt_issuance_id" is added to the txnJson JSON object + * @return true if the "mpt_issuance_id" is added to either txnJson or metaJson object */ bool -insertMPTIssuanceID(boost::json::object& txnJson, std::shared_ptr const& meta); +insertMPTIssuanceID( + boost::json::object& txnJson, + std::shared_ptr const& txn, + boost::json::object& metaJson, + std::shared_ptr const& meta +); /** * @brief Convert STBase object to JSON diff --git a/tests/unit/feed/TransactionFeedTests.cpp b/tests/unit/feed/TransactionFeedTests.cpp index 3002c572..673f6632 100644 --- a/tests/unit/feed/TransactionFeedTests.cpp +++ b/tests/unit/feed/TransactionFeedTests.cpp @@ -1282,7 +1282,8 @@ TEST_F(FeedTransactionTest, PublishesMPTokenIssuanceCreateTx) } ], "TransactionIndex": 0, - "TransactionResult": "tesSUCCESS" + "TransactionResult": "tesSUCCESS", + "mpt_issuance_id": "000000014B4E9C06F24296074F7BC48F92A97916C6DC5EA9" }, "ctid": "C000002100000000", "type": "transaction", diff --git a/tests/unit/rpc/handlers/AccountTxTests.cpp b/tests/unit/rpc/handlers/AccountTxTests.cpp index 6e9acdbe..20c6d983 100644 --- a/tests/unit/rpc/handlers/AccountTxTests.cpp +++ b/tests/unit/rpc/handlers/AccountTxTests.cpp @@ -1625,7 +1625,8 @@ TEST_F(RPCAccountTxHandlerTest, MPTTxs_API_v2) }} ], "TransactionIndex": 0, - "TransactionResult": "tesSUCCESS" + "TransactionResult": "tesSUCCESS", + "mpt_issuance_id": "000000014B4E9C06F24296074F7BC48F92A97916C6DC5EA9" }}, "hash": "A52221F4003C281D3C83F501F418B55A1F9DC1C6A129EF13E1A8F0E5C008DAE3", "ledger_index": 11,