Skip to content

Commit b3421c5

Browse files
fix: Add mpt_issuance_id to meta of MPTIssuanceCreate
1 parent b4e4055 commit b3421c5

File tree

5 files changed

+38
-22
lines changed

5 files changed

+38
-22
lines changed

src/feed/impl/TransactionFeed.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,9 @@ TransactionFeed::pub(
209209
rpc::insertDeliveredAmount(pubObj[JS(meta)].as_object(), tx, meta, txMeta.date);
210210

211211
auto& txnPubobj = pubObj[txKey].as_object();
212+
auto& metaPubobj = pubObj[JS(meta)].as_object();
212213
rpc::insertDeliverMaxAlias(txnPubobj, version);
213-
rpc::insertMPTIssuanceID(txnPubobj, meta);
214+
rpc::insertMPTIssuanceID(txnPubobj, tx, metaPubobj, meta);
214215

215216
Json::Value nftJson;
216217
ripple::RPC::insertNFTSyntheticInJson(nftJson, tx, *meta);

src/rpc/RPCHelpers.cpp

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ toExpandedJson(
258258
auto metaJson = toJson(*meta);
259259
insertDeliveredAmount(metaJson, txn, meta, blobs.date);
260260
insertDeliverMaxAlias(txnJson, apiVersion);
261-
insertMPTIssuanceID(txnJson, meta);
261+
insertMPTIssuanceID(txnJson, txn, metaJson, meta);
262262

263263
if (nftEnabled == NFTokenjson::ENABLE) {
264264
Json::Value nftJson;
@@ -348,31 +348,36 @@ getMPTIssuanceID(std::shared_ptr<ripple::TxMeta const> const& meta)
348348
* @return true if the transaction can have a mpt_issuance_id
349349
*/
350350
static bool
351-
canHaveMPTIssuanceID(boost::json::object const& txnJson, std::shared_ptr<ripple::TxMeta const> const& meta)
351+
canHaveMPTIssuanceID(std::shared_ptr<ripple::STTx const> const& txn, std::shared_ptr<ripple::TxMeta const> const& meta)
352352
{
353-
if (txnJson.at(JS(TransactionType)).is_string() and
354-
not boost::iequals(txnJson.at(JS(TransactionType)).as_string(), JS(MPTokenIssuanceCreate)))
353+
if (txn->getTxnType() != ripple::ttMPTOKEN_ISSUANCE_CREATE)
355354
return false;
356355

357-
if (meta->getResultTER() != ripple::tesSUCCESS)
358-
return false;
359-
360-
return true;
356+
return (meta->getResultTER() == ripple::tesSUCCESS);
361357
}
362358

363359
bool
364-
insertMPTIssuanceID(boost::json::object& txnJson, std::shared_ptr<ripple::TxMeta const> const& meta)
360+
insertMPTIssuanceID(
361+
boost::json::object& txnJson,
362+
std::shared_ptr<ripple::STTx const> const& txn,
363+
boost::json::object& metaJson,
364+
std::shared_ptr<ripple::TxMeta const> const& meta
365+
)
365366
{
366-
if (!canHaveMPTIssuanceID(txnJson, meta))
367-
return false;
368-
369-
if (txnJson.contains(JS(TransactionType)) && txnJson.at(JS(TransactionType)).is_string() and
370-
txnJson.at(JS(TransactionType)).as_string() == JS(MPTokenIssuanceCreate))
367+
if (!canHaveMPTIssuanceID(txn, meta))
371368
return false;
372369

373370
auto const id = getMPTIssuanceID(meta);
374371
ASSERT(id.has_value(), "MPTIssuanceID must have value");
375-
txnJson[JS(mpt_issuance_id)] = ripple::to_string(*id);
372+
373+
// For mpttokenissuance create, add mpt_issuance_id to metajson
374+
// Otherwise, add it to txn json
375+
if (txnJson.contains(JS(TransactionType)) && txnJson.at(JS(TransactionType)).is_string() and
376+
txnJson.at(JS(TransactionType)).as_string() == JS(MPTokenIssuanceCreate)) {
377+
metaJson[JS(mpt_issuance_id)] = ripple::to_string(*id);
378+
} else {
379+
txnJson[JS(mpt_issuance_id)] = ripple::to_string(*id);
380+
}
376381

377382
return true;
378383
}

src/rpc/RPCHelpers.hpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -201,15 +201,23 @@ insertDeliveredAmount(
201201

202202
/**
203203
* @brief Add "mpt_issuance_id" into various MPTToken transaction json.
204-
* @note We exclude "mpt_issuance_id" for MPTokenIssuanceCreate only. The reason is because the mpt_issuance_id
205-
* is generated only after one submits MPTokenIssuanceCreate, so there’s no way to know what the id is. (rippled)
204+
* @note We add "mpt_issuance_id" into the meta part of MPTokenIssuanceCreate only. The reason is because the
205+
* mpt_issuance_id is generated only after one submits MPTokenIssuanceCreate, so there’s no way to know what the id is.
206+
* (rippled)
206207
*
207208
* @param txnJson The transaction Json object
209+
* @param txn The txn object
210+
* @param metaJson The metadata Json object
208211
* @param meta The metadata object
209-
* @return true if the "mpt_issuance_id" is added to the txnJson JSON object
212+
* @return true if the "mpt_issuance_id" is added to either txnJson or metaJson object
210213
*/
211214
bool
212-
insertMPTIssuanceID(boost::json::object& txnJson, std::shared_ptr<ripple::TxMeta const> const& meta);
215+
insertMPTIssuanceID(
216+
boost::json::object& txnJson,
217+
std::shared_ptr<ripple::STTx const> const& txn,
218+
boost::json::object& metaJson,
219+
std::shared_ptr<ripple::TxMeta const> const& meta
220+
);
213221

214222
/**
215223
* @brief Convert STBase object to JSON

tests/unit/feed/TransactionFeedTests.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1282,7 +1282,8 @@ TEST_F(FeedTransactionTest, PublishesMPTokenIssuanceCreateTx)
12821282
}
12831283
],
12841284
"TransactionIndex": 0,
1285-
"TransactionResult": "tesSUCCESS"
1285+
"TransactionResult": "tesSUCCESS",
1286+
"mpt_issuance_id": "000000014B4E9C06F24296074F7BC48F92A97916C6DC5EA9"
12861287
},
12871288
"ctid": "C000002100000000",
12881289
"type": "transaction",

tests/unit/rpc/handlers/AccountTxTests.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1625,7 +1625,8 @@ TEST_F(RPCAccountTxHandlerTest, MPTTxs_API_v2)
16251625
}}
16261626
],
16271627
"TransactionIndex": 0,
1628-
"TransactionResult": "tesSUCCESS"
1628+
"TransactionResult": "tesSUCCESS",
1629+
"mpt_issuance_id": "000000014B4E9C06F24296074F7BC48F92A97916C6DC5EA9"
16291630
}},
16301631
"hash": "A52221F4003C281D3C83F501F418B55A1F9DC1C6A129EF13E1A8F0E5C008DAE3",
16311632
"ledger_index": 11,

0 commit comments

Comments
 (0)