Skip to content

Commit

Permalink
Leverage nftoken_id, nftoken_ids and offer_id meta fields in transact…
Browse files Browse the repository at this point in the history
…ion parsers (#1018)

## High Level Overview of Change
utilize added ID fields based on [this rippled
PR](XRPLF/rippled#4447), rather than manually
parsing for NFToken transactions.

### Context of Change
#708
  • Loading branch information
achowdhry-ripple authored Jul 18, 2024
1 parent 5498fa4 commit 16c3676
Show file tree
Hide file tree
Showing 15 changed files with 33 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,8 @@
}
],
"TransactionIndex": 7,
"TransactionResult": "tesSUCCESS"
"TransactionResult": "tesSUCCESS",
"nftoken_id": "00081B581189F5687DBB7516339D6CCB5593D96622AD82DF08CFDA8600000A17"
},
"hash": "E6CE3C3C554BA01891A9D12E89062C34BBEA6282CF8AA4D9AF8BF7D0E7D26B7D",
"ledger_index": 76208251,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,8 @@
}
],
"TransactionIndex": 4,
"TransactionResult": "tesSUCCESS"
"TransactionResult": "tesSUCCESS",
"nftoken_id": "000800006203F49C21D5D6E022CB16DE3538F248662FC73C29ABA6A90000000D"
},
"hash": "21C60F255B29D0034B9EBA2ED1F7523635C61DED1D6BDBCFFD67703C45F7072D",
"ledger_index": 1799495,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,8 @@
}
],
"TransactionIndex": 0,
"TransactionResult": "tesSUCCESS"
"TransactionResult": "tesSUCCESS",
"nftoken_id": "000800006203F49C21D5D6E022CB16DE3538F248662FC73C216B9CBF00000023"
},
"hash": "553922B202932DD500C6E0D6905BA1D8ACC0DF746519DD6AAA724AF70D23F1E6",
"ledger_index": 1889191,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@
}
],
"TransactionIndex": 2,
"TransactionResult": "tesSUCCESS"
"TransactionResult": "tesSUCCESS",
"offer_id": "35F3D6D99548FA5F5315580FBF8BA6B15CAA2CAE93023D5CE4FDC130602BC5C3"
},
"hash": "AF12B2694896ADE0F93C8C3D09602B242F08C50854A0C600E0E7A2E18586C8C3",
"ledger_index": 1799491,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@
}
],
"TransactionIndex": 0,
"TransactionResult": "tesSUCCESS"
"TransactionResult": "tesSUCCESS",
"offer_id": "3D1C297DA5B831267CCF692F8A023688D6A4BD5AFAE9A746D5C4E0B15D256B29"
},
"hash": "385DC0497AAF8061549A7DC04EB20C2B387A167792796F5806A13E0422125563",
"ledger_index": 1887982,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@
}
],
"TransactionIndex": 1,
"TransactionResult": "tesSUCCESS"
"TransactionResult": "tesSUCCESS",
"offer_id": "F660CA62E16B8067649052E8FCE947049FC6EF0D8B42EF7E5819997EC5AE45B6"
},
"hash": "47DCA082AE5920D672B32E63623B799899B91B77D68365711B07376E5ACFC8DB",
"ledger_index": 1799495,
Expand Down
53 changes: 7 additions & 46 deletions src/containers/shared/components/Transaction/NFTokenMint/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,49 +7,10 @@ import { convertHexToString } from '../../../../../rippled/lib/utils'
export const parser: TransactionParser<NFTokenMint, NFTokenMintInstructions> = (
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,
})
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@
}
],
"TransactionIndex": 1,
"TransactionResult": "tesSUCCESS"
"TransactionResult": "tesSUCCESS",
"nftoken_id": "0008000085D33F9C5481D3515029C9904D16F0109414D3A00000099A00000000"
},
"hash": "B0AAA46053F2570200CA1E12978EFFBB124374276669CC3F68602A6788182172",
"ledger_index": 5605230,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,8 @@
}
],
"TransactionIndex": 0,
"TransactionResult": "tesSUCCESS"
"TransactionResult": "tesSUCCESS",
"nftoken_id": "000800006203F49C21D5D6E022CB16DE3538F248662FC73C535743B40000001A"
},
"hash": "B9A20167DC30985ABD983912F29DE81CB4579FAF9672C9D68BEC5219C19C7E50",
"ledger_index": 1861436,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,8 @@
}
],
"TransactionIndex": 337,
"TransactionResult": "tesSUCCESS"
"TransactionResult": "tesSUCCESS",
"nftoken_id": "000D0000B9BD7D214128A91ECECE5FCFF9BDB0D043567C51CFBEC443000063A7"
},
"hash": "4E0EB5F23D248740CB8FC28D1003CEFE841E21811FE2EA4B195CFE1B0BC54219",
"ledger_index": 6453184,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,8 @@
}
],
"TransactionIndex": 0,
"TransactionResult": "tesSUCCESS"
"TransactionResult": "tesSUCCESS",
"nftoken_id": "0008000085D33F9C5481D3515029C9904D16F0109414D3A0DCBA29BA00000020"
},
"hash": "C4E598099A8B13C5C8D2B8C86385A37B64C2F62BFA1FB87196401BB6ACB67A69",
"ledger_index": 5605289,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@
}
],
"TransactionIndex": 0,
"TransactionResult": "tesSUCCESS"
"TransactionResult": "tesSUCCESS",
"nftoken_id": "000861A8A99B4460C2A4CCC90634FD9C7F51940AD9450BE30000099B00000000"
},
"hash": "73629D3E84AC18C06350A9A4A0B2EF15AB52E5A62AECDAB4A0579DEF342FC61F",
"ledger_index": 4997948,
Expand Down

0 comments on commit 16c3676

Please sign in to comment.