fix: Add mpt_issuance_id to meta of MPTIssuanceCreate (#2701)

fixes #2332
This commit is contained in:
Peter Chen
2025-10-17 09:58:38 -04:00
committed by GitHub
parent 685f611434
commit 7538efb01e
5 changed files with 40 additions and 24 deletions

View File

@@ -209,8 +209,9 @@ TransactionFeed::pub(
rpc::insertDeliveredAmount(pubObj[JS(meta)].as_object(), tx, meta, txMeta.date); rpc::insertDeliveredAmount(pubObj[JS(meta)].as_object(), tx, meta, txMeta.date);
auto& txnPubobj = pubObj[txKey].as_object(); auto& txnPubobj = pubObj[txKey].as_object();
auto& metaPubobj = pubObj[JS(meta)].as_object();
rpc::insertDeliverMaxAlias(txnPubobj, version); rpc::insertDeliverMaxAlias(txnPubobj, version);
rpc::insertMPTIssuanceID(txnPubobj, meta); rpc::insertMPTIssuanceID(txnPubobj, tx, metaPubobj, meta);
Json::Value nftJson; Json::Value nftJson;
ripple::RPC::insertNFTSyntheticInJson(nftJson, tx, *meta); ripple::RPC::insertNFTSyntheticInJson(nftJson, tx, *meta);

View File

@@ -258,7 +258,7 @@ toExpandedJson(
auto metaJson = toJson(*meta); auto metaJson = toJson(*meta);
insertDeliveredAmount(metaJson, txn, meta, blobs.date); insertDeliveredAmount(metaJson, txn, meta, blobs.date);
insertDeliverMaxAlias(txnJson, apiVersion); insertDeliverMaxAlias(txnJson, apiVersion);
insertMPTIssuanceID(txnJson, meta); insertMPTIssuanceID(txnJson, txn, metaJson, meta);
if (nftEnabled == NFTokenjson::ENABLE) { if (nftEnabled == NFTokenjson::ENABLE) {
Json::Value nftJson; Json::Value nftJson;
@@ -343,36 +343,41 @@ getMPTIssuanceID(std::shared_ptr<ripple::TxMeta const> const& meta)
/** /**
* @brief Check if transaction has a new MPToken created * @brief Check if transaction has a new MPToken created
* *
* @param txnJson The transaction Json * @param txn The transaction object
* @param meta The metadata * @param meta The metadata object
* @return true if the transaction can have a mpt_issuance_id * @return true if the transaction can have a mpt_issuance_id
*/ */
static bool static bool
canHaveMPTIssuanceID(boost::json::object const& txnJson, std::shared_ptr<ripple::TxMeta const> const& meta) canHaveMPTIssuanceID(std::shared_ptr<ripple::STTx const> const& txn, std::shared_ptr<ripple::TxMeta const> const& meta)
{ {
if (txnJson.at(JS(TransactionType)).is_string() and if (txn->getTxnType() != ripple::ttMPTOKEN_ISSUANCE_CREATE)
not boost::iequals(txnJson.at(JS(TransactionType)).as_string(), JS(MPTokenIssuanceCreate)))
return false; return false;
if (meta->getResultTER() != ripple::tesSUCCESS) return (meta->getResultTER() == ripple::tesSUCCESS);
return false;
return true;
} }
bool bool
insertMPTIssuanceID(boost::json::object& txnJson, std::shared_ptr<ripple::TxMeta const> const& meta) insertMPTIssuanceID(
boost::json::object& txnJson,
std::shared_ptr<ripple::STTx const> const& txn,
boost::json::object& metaJson,
std::shared_ptr<ripple::TxMeta const> const& meta
)
{ {
if (!canHaveMPTIssuanceID(txnJson, meta)) if (!canHaveMPTIssuanceID(txn, meta))
return false;
if (txnJson.contains(JS(TransactionType)) && txnJson.at(JS(TransactionType)).is_string() and
txnJson.at(JS(TransactionType)).as_string() == JS(MPTokenIssuanceCreate))
return false; return false;
auto const id = getMPTIssuanceID(meta); auto const id = getMPTIssuanceID(meta);
ASSERT(id.has_value(), "MPTIssuanceID must have value"); ASSERT(id.has_value(), "MPTIssuanceID must have value");
// 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); txnJson[JS(mpt_issuance_id)] = ripple::to_string(*id);
}
return true; return true;
} }

View File

@@ -201,15 +201,23 @@ insertDeliveredAmount(
/** /**
* @brief Add "mpt_issuance_id" into various MPTToken transaction json. * @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 * @note We add "mpt_issuance_id" into the meta part of MPTokenIssuanceCreate only. The reason is because the
* is generated only after one submits MPTokenIssuanceCreate, so theres no way to know what the id is. (rippled) * mpt_issuance_id is generated only after one submits MPTokenIssuanceCreate, so theres no way to know what the id is.
* (rippled)
* *
* @param txnJson The transaction Json object * @param txnJson The transaction Json object
* @param txn The txn object
* @param metaJson The metadata Json object
* @param meta The metadata 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 bool
insertMPTIssuanceID(boost::json::object& txnJson, std::shared_ptr<ripple::TxMeta const> const& meta); insertMPTIssuanceID(
boost::json::object& txnJson,
std::shared_ptr<ripple::STTx const> const& txn,
boost::json::object& metaJson,
std::shared_ptr<ripple::TxMeta const> const& meta
);
/** /**
* @brief Convert STBase object to JSON * @brief Convert STBase object to JSON

View File

@@ -1282,7 +1282,8 @@ TEST_F(FeedTransactionTest, PublishesMPTokenIssuanceCreateTx)
} }
], ],
"TransactionIndex": 0, "TransactionIndex": 0,
"TransactionResult": "tesSUCCESS" "TransactionResult": "tesSUCCESS",
"mpt_issuance_id": "000000014B4E9C06F24296074F7BC48F92A97916C6DC5EA9"
}, },
"ctid": "C000002100000000", "ctid": "C000002100000000",
"type": "transaction", "type": "transaction",

View File

@@ -1625,7 +1625,8 @@ TEST_F(RPCAccountTxHandlerTest, MPTTxs_API_v2)
}} }}
], ],
"TransactionIndex": 0, "TransactionIndex": 0,
"TransactionResult": "tesSUCCESS" "TransactionResult": "tesSUCCESS",
"mpt_issuance_id": "000000014B4E9C06F24296074F7BC48F92A97916C6DC5EA9"
}}, }},
"hash": "A52221F4003C281D3C83F501F418B55A1F9DC1C6A129EF13E1A8F0E5C008DAE3", "hash": "A52221F4003C281D3C83F501F418B55A1F9DC1C6A129EF13E1A8F0E5C008DAE3",
"ledger_index": 11, "ledger_index": 11,