From 16c3676d2b650816f468eeb5a0815d7dae50212b Mon Sep 17 00:00:00 2001 From: achowdhry-ripple Date: Thu, 18 Jul 2024 18:44:16 -0400 Subject: [PATCH 1/2] Leverage nftoken_id, nftoken_ids and offer_id meta fields in transaction parsers (#1018) ## High Level Overview of Change utilize added ID fields based on [this rippled PR](https://github.com/XRPLF/rippled/pull/4447), rather than manually parsing for NFToken transactions. ### Context of Change https://github.com/ripple/explorer/issues/708 --- .../Transaction/NFTokenAcceptOffer/parser.ts | 4 +- .../mock_data/NFTokenAcceptOffer_Broker.json | 3 +- .../mock_data/NFTokenAcceptOffer_Buy.json | 3 +- .../mock_data/NFTokenAcceptOffer_Sell.json | 3 +- .../Transaction/NFTokenCancelOffer/parser.ts | 2 +- .../test/mock_data/NFTokenCancelOffer.json | 3 +- .../Transaction/NFTokenCreateOffer/parser.ts | 3 +- .../mock_data/NFTokenCreateOffer_Buy.json | 3 +- .../mock_data/NFTokenCreateOffer_Sell.json | 3 +- .../Transaction/NFTokenMint/parser.ts | 53 +++---------------- .../NFTokenMintModified1Created1.json | 3 +- .../test/mock_data/NFTokenMintModified2.json | 3 +- .../NFTokenMintModified4Created1.json | 3 +- .../NFTokenMintMostModified2Created1.json | 3 +- .../test/mock_data/NFTokenMintWithIssuer.json | 3 +- 15 files changed, 33 insertions(+), 62 deletions(-) diff --git a/src/containers/shared/components/Transaction/NFTokenAcceptOffer/parser.ts b/src/containers/shared/components/Transaction/NFTokenAcceptOffer/parser.ts index 85abfdaa6..5586be0c8 100644 --- a/src/containers/shared/components/Transaction/NFTokenAcceptOffer/parser.ts +++ b/src/containers/shared/components/Transaction/NFTokenAcceptOffer/parser.ts @@ -35,7 +35,7 @@ export const parser: TransactionParser< return { amount: formatAmount(buyOfferNode.Amount), - tokenID: buyOfferNode.NFTokenID, + tokenID: meta.nftoken_id, seller: sellOfferNode.Owner, buyer: buyOfferNode.Owner, acceptedOfferIDs, @@ -51,7 +51,7 @@ export const parser: TransactionParser< } const amount = formatAmount(acceptedOfferNode.Amount) - const tokenID = acceptedOfferNode.NFTokenID + const tokenID = meta.nftoken_id const offerer = acceptedOfferNode.Owner const accepter = tx.Account const isSellOffer = determineIsSellOffer(acceptedOfferNode.Flags) diff --git a/src/containers/shared/components/Transaction/NFTokenAcceptOffer/test/mock_data/NFTokenAcceptOffer_Broker.json b/src/containers/shared/components/Transaction/NFTokenAcceptOffer/test/mock_data/NFTokenAcceptOffer_Broker.json index 4a2ab29ab..f1bc90003 100644 --- a/src/containers/shared/components/Transaction/NFTokenAcceptOffer/test/mock_data/NFTokenAcceptOffer_Broker.json +++ b/src/containers/shared/components/Transaction/NFTokenAcceptOffer/test/mock_data/NFTokenAcceptOffer_Broker.json @@ -255,7 +255,8 @@ } ], "TransactionIndex": 7, - "TransactionResult": "tesSUCCESS" + "TransactionResult": "tesSUCCESS", + "nftoken_id": "00081B581189F5687DBB7516339D6CCB5593D96622AD82DF08CFDA8600000A17" }, "hash": "E6CE3C3C554BA01891A9D12E89062C34BBEA6282CF8AA4D9AF8BF7D0E7D26B7D", "ledger_index": 76208251, diff --git a/src/containers/shared/components/Transaction/NFTokenAcceptOffer/test/mock_data/NFTokenAcceptOffer_Buy.json b/src/containers/shared/components/Transaction/NFTokenAcceptOffer/test/mock_data/NFTokenAcceptOffer_Buy.json index d984fc1f7..6bb4a8973 100644 --- a/src/containers/shared/components/Transaction/NFTokenAcceptOffer/test/mock_data/NFTokenAcceptOffer_Buy.json +++ b/src/containers/shared/components/Transaction/NFTokenAcceptOffer/test/mock_data/NFTokenAcceptOffer_Buy.json @@ -439,7 +439,8 @@ } ], "TransactionIndex": 4, - "TransactionResult": "tesSUCCESS" + "TransactionResult": "tesSUCCESS", + "nftoken_id": "000800006203F49C21D5D6E022CB16DE3538F248662FC73C29ABA6A90000000D" }, "hash": "21C60F255B29D0034B9EBA2ED1F7523635C61DED1D6BDBCFFD67703C45F7072D", "ledger_index": 1799495, diff --git a/src/containers/shared/components/Transaction/NFTokenAcceptOffer/test/mock_data/NFTokenAcceptOffer_Sell.json b/src/containers/shared/components/Transaction/NFTokenAcceptOffer/test/mock_data/NFTokenAcceptOffer_Sell.json index 3f78b0426..77fe997f5 100644 --- a/src/containers/shared/components/Transaction/NFTokenAcceptOffer/test/mock_data/NFTokenAcceptOffer_Sell.json +++ b/src/containers/shared/components/Transaction/NFTokenAcceptOffer/test/mock_data/NFTokenAcceptOffer_Sell.json @@ -392,7 +392,8 @@ } ], "TransactionIndex": 0, - "TransactionResult": "tesSUCCESS" + "TransactionResult": "tesSUCCESS", + "nftoken_id": "000800006203F49C21D5D6E022CB16DE3538F248662FC73C216B9CBF00000023" }, "hash": "553922B202932DD500C6E0D6905BA1D8ACC0DF746519DD6AAA724AF70D23F1E6", "ledger_index": 1889191, diff --git a/src/containers/shared/components/Transaction/NFTokenCancelOffer/parser.ts b/src/containers/shared/components/Transaction/NFTokenCancelOffer/parser.ts index f2a8debe2..4857fb442 100644 --- a/src/containers/shared/components/Transaction/NFTokenCancelOffer/parser.ts +++ b/src/containers/shared/components/Transaction/NFTokenCancelOffer/parser.ts @@ -10,7 +10,7 @@ export const parser: TransactionParser< const cancelledOffers = meta.AffectedNodes.filter( (node: any) => node.DeletedNode?.LedgerEntryType === 'NFTokenOffer', ).map((node: any) => ({ - offerID: node.DeletedNode.LedgerIndex, + offerID: meta.offer_id, amount: formatAmount(node.DeletedNode.FinalFields.Amount), tokenID: node.DeletedNode.FinalFields.NFTokenID, offerer: node.DeletedNode.FinalFields.Owner, diff --git a/src/containers/shared/components/Transaction/NFTokenCancelOffer/test/mock_data/NFTokenCancelOffer.json b/src/containers/shared/components/Transaction/NFTokenCancelOffer/test/mock_data/NFTokenCancelOffer.json index ee6e5472d..d625ca873 100644 --- a/src/containers/shared/components/Transaction/NFTokenCancelOffer/test/mock_data/NFTokenCancelOffer.json +++ b/src/containers/shared/components/Transaction/NFTokenCancelOffer/test/mock_data/NFTokenCancelOffer.json @@ -81,7 +81,8 @@ } ], "TransactionIndex": 2, - "TransactionResult": "tesSUCCESS" + "TransactionResult": "tesSUCCESS", + "offer_id": "35F3D6D99548FA5F5315580FBF8BA6B15CAA2CAE93023D5CE4FDC130602BC5C3" }, "hash": "AF12B2694896ADE0F93C8C3D09602B242F08C50854A0C600E0E7A2E18586C8C3", "ledger_index": 1799491, diff --git a/src/containers/shared/components/Transaction/NFTokenCreateOffer/parser.ts b/src/containers/shared/components/Transaction/NFTokenCreateOffer/parser.ts index e818c0294..deaaacffe 100644 --- a/src/containers/shared/components/Transaction/NFTokenCreateOffer/parser.ts +++ b/src/containers/shared/components/Transaction/NFTokenCreateOffer/parser.ts @@ -2,7 +2,6 @@ import type { NFTokenCreateOffer } from 'xrpl' import { NFTokenCreateOfferInstructions } from './types' import { TransactionParser } from '../types' import { formatAmount } from '../../../../../rippled/lib/txSummary/formatAmount' -import { findNode } from '../../../transactionUtils' export const parser: TransactionParser< NFTokenCreateOffer, @@ -13,7 +12,7 @@ export const parser: TransactionParser< const tokenID = tx.NFTokenID const isSellOffer = ((tx.Flags as number)! & 1) !== 0 const owner = tx.Owner - const offerID = findNode(meta, 'CreatedNode', 'NFTokenOffer')?.LedgerIndex + const offerID = meta.offer_id const destination = tx.Destination return { diff --git a/src/containers/shared/components/Transaction/NFTokenCreateOffer/test/mock_data/NFTokenCreateOffer_Buy.json b/src/containers/shared/components/Transaction/NFTokenCreateOffer/test/mock_data/NFTokenCreateOffer_Buy.json index 57b78b9c9..546e25bc7 100644 --- a/src/containers/shared/components/Transaction/NFTokenCreateOffer/test/mock_data/NFTokenCreateOffer_Buy.json +++ b/src/containers/shared/components/Transaction/NFTokenCreateOffer/test/mock_data/NFTokenCreateOffer_Buy.json @@ -70,7 +70,8 @@ } ], "TransactionIndex": 0, - "TransactionResult": "tesSUCCESS" + "TransactionResult": "tesSUCCESS", + "offer_id": "3D1C297DA5B831267CCF692F8A023688D6A4BD5AFAE9A746D5C4E0B15D256B29" }, "hash": "385DC0497AAF8061549A7DC04EB20C2B387A167792796F5806A13E0422125563", "ledger_index": 1887982, diff --git a/src/containers/shared/components/Transaction/NFTokenCreateOffer/test/mock_data/NFTokenCreateOffer_Sell.json b/src/containers/shared/components/Transaction/NFTokenCreateOffer/test/mock_data/NFTokenCreateOffer_Sell.json index ca2b485e1..01a6427e6 100644 --- a/src/containers/shared/components/Transaction/NFTokenCreateOffer/test/mock_data/NFTokenCreateOffer_Sell.json +++ b/src/containers/shared/components/Transaction/NFTokenCreateOffer/test/mock_data/NFTokenCreateOffer_Sell.json @@ -80,7 +80,8 @@ } ], "TransactionIndex": 1, - "TransactionResult": "tesSUCCESS" + "TransactionResult": "tesSUCCESS", + "offer_id": "F660CA62E16B8067649052E8FCE947049FC6EF0D8B42EF7E5819997EC5AE45B6" }, "hash": "47DCA082AE5920D672B32E63623B799899B91B77D68365711B07376E5ACFC8DB", "ledger_index": 1799495, diff --git a/src/containers/shared/components/Transaction/NFTokenMint/parser.ts b/src/containers/shared/components/Transaction/NFTokenMint/parser.ts index 998ab089f..acb0cd7c1 100644 --- a/src/containers/shared/components/Transaction/NFTokenMint/parser.ts +++ b/src/containers/shared/components/Transaction/NFTokenMint/parser.ts @@ -7,49 +7,10 @@ import { convertHexToString } from '../../../../../rippled/lib/utils' export const parser: TransactionParser = ( tx, meta, -) => { - // When a mint results in splitting an existing page, - // it results in a created page and a modified node. Sometimes, - // the created node needs to be linked to a third page, resulting - // in modifying that third page's PreviousPageMin or NextPageMin - // field changing, but no NFTs within that page changing. In this - // case, there will be no previous NFTs and we need to skip. - // However, there will always be NFTs listed in the final fields, - // as rippled outputs all fields in final fields even if they were - // not changed. Thus why we add the additional condition to check - // if the PreviousFields contains NFTokens - const affectedNodes = meta.AffectedNodes.filter( - (node: any) => - node.CreatedNode?.LedgerEntryType === 'NFTokenPage' || - (node.ModifiedNode?.LedgerEntryType === 'NFTokenPage' && - !!node.ModifiedNode?.PreviousFields.NFTokens), - ) - - const previousTokenIDSet = new Set( - affectedNodes - .flatMap((node: any) => - node.ModifiedNode?.PreviousFields?.NFTokens?.map( - (token: any) => token.NFToken.NFTokenID, - ), - ) - .filter((id: any) => id), - ) - - const finalTokenIDs = affectedNodes - .flatMap((node: any) => - ( - node.ModifiedNode?.FinalFields ?? node.CreatedNode?.NewFields - )?.NFTokens?.map((token: any) => token.NFToken.NFTokenID), - ) - .filter((id: any) => id) - - const tokenID = finalTokenIDs.find((id: any) => !previousTokenIDSet.has(id)) - - return { - tokenID, - tokenTaxon: tx.NFTokenTaxon, - uri: convertHexToString(tx.URI), - transferFee: tx.TransferFee, - issuer: tx.Issuer, - } -} +) => ({ + tokenID: meta.nftoken_id, + tokenTaxon: tx.NFTokenTaxon, + uri: convertHexToString(tx.URI), + transferFee: tx.TransferFee, + issuer: tx.Issuer, +}) diff --git a/src/containers/shared/components/Transaction/NFTokenMint/test/mock_data/NFTokenMintModified1Created1.json b/src/containers/shared/components/Transaction/NFTokenMint/test/mock_data/NFTokenMintModified1Created1.json index d19662a65..2fb674b4e 100644 --- a/src/containers/shared/components/Transaction/NFTokenMint/test/mock_data/NFTokenMintModified1Created1.json +++ b/src/containers/shared/components/Transaction/NFTokenMint/test/mock_data/NFTokenMintModified1Created1.json @@ -53,7 +53,8 @@ } ], "TransactionIndex": 1, - "TransactionResult": "tesSUCCESS" + "TransactionResult": "tesSUCCESS", + "nftoken_id": "0008000085D33F9C5481D3515029C9904D16F0109414D3A00000099A00000000" }, "hash": "B0AAA46053F2570200CA1E12978EFFBB124374276669CC3F68602A6788182172", "ledger_index": 5605230, diff --git a/src/containers/shared/components/Transaction/NFTokenMint/test/mock_data/NFTokenMintModified2.json b/src/containers/shared/components/Transaction/NFTokenMint/test/mock_data/NFTokenMintModified2.json index 27f0ad378..4cb746d3d 100644 --- a/src/containers/shared/components/Transaction/NFTokenMint/test/mock_data/NFTokenMintModified2.json +++ b/src/containers/shared/components/Transaction/NFTokenMint/test/mock_data/NFTokenMintModified2.json @@ -301,7 +301,8 @@ } ], "TransactionIndex": 0, - "TransactionResult": "tesSUCCESS" + "TransactionResult": "tesSUCCESS", + "nftoken_id": "000800006203F49C21D5D6E022CB16DE3538F248662FC73C535743B40000001A" }, "hash": "B9A20167DC30985ABD983912F29DE81CB4579FAF9672C9D68BEC5219C19C7E50", "ledger_index": 1861436, diff --git a/src/containers/shared/components/Transaction/NFTokenMint/test/mock_data/NFTokenMintModified4Created1.json b/src/containers/shared/components/Transaction/NFTokenMint/test/mock_data/NFTokenMintModified4Created1.json index 2c9a62634..2156f52bb 100644 --- a/src/containers/shared/components/Transaction/NFTokenMint/test/mock_data/NFTokenMintModified4Created1.json +++ b/src/containers/shared/components/Transaction/NFTokenMint/test/mock_data/NFTokenMintModified4Created1.json @@ -690,7 +690,8 @@ } ], "TransactionIndex": 337, - "TransactionResult": "tesSUCCESS" + "TransactionResult": "tesSUCCESS", + "nftoken_id": "000D0000B9BD7D214128A91ECECE5FCFF9BDB0D043567C51CFBEC443000063A7" }, "hash": "4E0EB5F23D248740CB8FC28D1003CEFE841E21811FE2EA4B195CFE1B0BC54219", "ledger_index": 6453184, diff --git a/src/containers/shared/components/Transaction/NFTokenMint/test/mock_data/NFTokenMintMostModified2Created1.json b/src/containers/shared/components/Transaction/NFTokenMint/test/mock_data/NFTokenMintMostModified2Created1.json index 7278c7c13..f2ccdcc36 100644 --- a/src/containers/shared/components/Transaction/NFTokenMint/test/mock_data/NFTokenMintMostModified2Created1.json +++ b/src/containers/shared/components/Transaction/NFTokenMint/test/mock_data/NFTokenMintMostModified2Created1.json @@ -457,7 +457,8 @@ } ], "TransactionIndex": 0, - "TransactionResult": "tesSUCCESS" + "TransactionResult": "tesSUCCESS", + "nftoken_id": "0008000085D33F9C5481D3515029C9904D16F0109414D3A0DCBA29BA00000020" }, "hash": "C4E598099A8B13C5C8D2B8C86385A37B64C2F62BFA1FB87196401BB6ACB67A69", "ledger_index": 5605289, diff --git a/src/containers/shared/components/Transaction/NFTokenMint/test/mock_data/NFTokenMintWithIssuer.json b/src/containers/shared/components/Transaction/NFTokenMint/test/mock_data/NFTokenMintWithIssuer.json index db644a078..d0dad91c5 100644 --- a/src/containers/shared/components/Transaction/NFTokenMint/test/mock_data/NFTokenMintWithIssuer.json +++ b/src/containers/shared/components/Transaction/NFTokenMint/test/mock_data/NFTokenMintWithIssuer.json @@ -72,7 +72,8 @@ } ], "TransactionIndex": 0, - "TransactionResult": "tesSUCCESS" + "TransactionResult": "tesSUCCESS", + "nftoken_id": "000861A8A99B4460C2A4CCC90634FD9C7F51940AD9450BE30000099B00000000" }, "hash": "73629D3E84AC18C06350A9A4A0B2EF15AB52E5A62AECDAB4A0579DEF342FC61F", "ledger_index": 4997948, From d63f04372d408622f686c20a3f2584266d9f563f Mon Sep 17 00:00:00 2001 From: Chenna Keshava B S Date: Mon, 22 Jul 2024 12:04:20 -0700 Subject: [PATCH 2/2] Fix jest compatibility issues via force upgrade of ts-jest --- package-lock.json | 1 + package.json | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/package-lock.json b/package-lock.json index 774723f74..f5de6efea 100644 --- a/package-lock.json +++ b/package-lock.json @@ -7,6 +7,7 @@ "": { "name": "explorer", "version": "1.5.0", + "hasInstallScript": true, "dependencies": { "@google-cloud/bigquery": "^7.6.1", "@paystring/utils": "^2.0.0", diff --git a/package.json b/package.json index 1b8768b72..1dc467a90 100644 --- a/package.json +++ b/package.json @@ -109,7 +109,7 @@ "xrpl": "^3.1.0" }, "resolutions": { - "jest-environment-jsdom": "29.3.1" + "jest-environment-jsdom": "29.7.0" }, "lint-staged": { "src/**/*.{js,jsx,json,scss}": [ @@ -120,6 +120,7 @@ "main": "index", "private": true, "scripts": { + "preinstall": "npx npm-force-resolutions", "analyze": "source-map-explorer build/static/js/main.*", "build": "vite build", "build-ts": "tsc --build",