fix: Add synthetic NFT fields to ledger RPC, refactor to have common helper function#5706
fix: Add synthetic NFT fields to ledger RPC, refactor to have common helper function#5706
ledger RPC, refactor to have common helper function#5706Conversation
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
ledger RPC, refactor to have common helper functionledger RPC, refactor to have common helper function
5bc27f9 to
202e96d
Compare
This comment was marked as resolved.
This comment was marked as resolved.
| RPC::insertMPTokenIssuanceID( | ||
| txJson[jss::metaData], txn, {txn->getTransactionID(), fill.ledger.seq(), *stMeta}); | ||
| // Insert all synthetic fields | ||
| RPC::insertAllSyntheticInJson( |
There was a problem hiding this comment.
There's a change in behaviour. We'll insert delivered amount for ttACCOUNT_DELETE after the change, as per canHaveDeliveredAmount
There was a problem hiding this comment.
Is that a problem? That seems like a fix to me
There was a problem hiding this comment.
Yes, this is an intentional behavioral change. The old ttPAYMENT || ttCHECK_CASH conditional in LedgerToJson.cpp was outdated — canHaveDeliveredAmount (used internally by insertDeliveredAmount) already correctly handles ttACCOUNT_DELETE, and the other RPC endpoints (tx, account_tx) have always included delivered amount for ttACCOUNT_DELETE transactions. This change makes ledger RPC consistent with the rest.
| RPC::insertMPTokenIssuanceID( | ||
| txJson[jss::meta], txn, {txn->getTransactionID(), fill.ledger.seq(), *stMeta}); | ||
| // Insert all synthetic fields | ||
| RPC::insertAllSyntheticInJson( |
There was a problem hiding this comment.
Same as above — the ttACCOUNT_DELETE delivered amount behavior change is intentional, making ledger RPC consistent with tx and account_tx endpoints.
|
@copilot please fix the merge conflicts and update the branch |
Merged the develop branch into this branch to resolve the merge conflicts (commit 3559f06). The only actual conflict was in |
|
All conflicts have been resolved. Assigned reviewers can now start or resume their review. |
|
If only the most recent commit is unsigned, you can run:
If multiple commits are unsigned, you can run:
If you're new to commit signing, there are different ways to set it up: Sign commits with
|
|
This PR has conflicts, please resolve them in order for the PR to be reviewed. |
Fix NFT synthetic field insertion for different API versions Fix NFT test failures by handling API version metadata field differences [Claude] replace with a helper function [Claude] fix tests pre-commit fixes refactor: replace individual synthetic field functions with insertAllSyntheticInJson helper in simulate RPC Co-authored-by: mvadari <8029314+mvadari@users.noreply.github.com>
3559f06 to
3706565
Compare
|
All conflicts have been resolved. Assigned reviewers can now start or resume their review. |
High Level Overview of Change
Refactor synthetic field injection by consolidating three commonly-called functions (
insertDeliveredAmount,insertNFTSyntheticInJson, andinsertMPTokenIssuanceID) into a single helper functioninsertAllSyntheticInJson. This improves code maintainability by reducing duplication and providing a single point of update for synthetic field processing.This results in adding the synthetic
nftoken_idandnftoken_offer_idto theledgerRPC.Context of Change
Previously, the same three synthetic field injection functions were called together in multiple locations throughout the codebase:
src/xrpld/app/misc/NetworkOPs.cppsrc/xrpld/rpc/handlers/Tx.cppsrc/xrpld/rpc/handlers/AccountTx.cppsrc/xrpld/app/ledger/detail/LedgerToJson.cppsrc/xrpld/rpc/handlers/Simulate.cppThis pattern created maintenance overhead, as any changes to synthetic field processing would need to be replicated across all locations. Additionally,
LedgerToJson.cppcontained an outdated conditional check that only appliedinsertDeliveredAmountfor PAYMENT and CHECK_CASH transactions. Removing this outdated check now also causesdelivered_amountto be included forttACCOUNT_DELETEtransactions in theledgerRPC, making it consistent with thetxandaccount_txRPC endpoints (which already usedcanHaveDeliveredAmountto correctly handlettACCOUNT_DELETE).The refactor consolidates this logic into a reusable helper function with two overloads to handle different parameter signatures (
ReadViewvsJsonContext).API Impact
The
ledgerRPC now returnsnftoken_id,nftoken_offer_id, anddelivered_amount(forttACCOUNT_DELETEtransactions) in transaction metadata, consistent with other RPC endpoints.Before / After
Before: Each location manually called three functions:
After: Single helper function call:
insertAllSyntheticInJson(response, ledger, transaction, transactionMeta);Test Plan
The change preserves existing functionality by calling the same underlying functions in the same order. All synthetic field injection behavior remains identical. The consolidation was tested across all five modified files to ensure consistent usage of the new helper function.
This also involved adding tests to ensure that the NFT synthetic fields were added to the
ledgerandaccount_txRPC.💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.