Skip to content

Commit

Permalink
Add nftoken_id, nftoken_ids, offer_id to meta fields
Browse files Browse the repository at this point in the history
  • Loading branch information
tequdev committed Aug 29, 2023
1 parent b76d5b2 commit a9790e9
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 11 deletions.
2 changes: 1 addition & 1 deletion packages/xrpl/src/models/methods/tx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export interface TxResponse<T extends BaseTransaction = Transaction>
ledger_index?: number
/** Transaction metadata, which describes the results of the transaction.
* Can be undefined if a transaction has not been validated yet. */
meta?: TransactionMetadata | string
meta?: TransactionMetadata<T> | string
/**
* If true, this data comes from a validated ledger version; if omitted or.
* Set to false, this data is not final.
Expand Down
38 changes: 36 additions & 2 deletions packages/xrpl/src/models/transactions/metadata.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
import { Amount } from '../common'
import { NFTokenAcceptOffer } from './NFTokenAcceptOffer'
import { NFTokenCancelOffer } from './NFTokenCancelOffer'
import { NFTokenCreateOffer } from './NFTokenCreateOffer'
import { NFTokenMint } from './NFTokenMint'

import { BaseTransaction } from './common'
import { Payment } from './payment'
import { Transaction } from './transaction'

export interface CreatedNode {
CreatedNode: {
Expand Down Expand Up @@ -59,11 +67,37 @@ export function isDeletedNode(node: Node): node is DeletedNode {
return Object.prototype.hasOwnProperty.call(node, `DeletedNode`)
}

export interface TransactionMetadata {
export type TransactionMetadata<T extends BaseTransaction = Transaction> = {
AffectedNodes: Node[]
DeliveredAmount?: Amount
// "unavailable" possible for transactions before 2014-01-20
delivered_amount?: Amount | 'unavailable'
TransactionIndex: number
TransactionResult: string
}
} &
(
T extends Payment ?
{
delivered_amount?: Amount | 'unavailable'
} :
T extends NFTokenMint ?
{
// rippled 1.11.0 or later
nftoken_id?: string
} :
T extends NFTokenCreateOffer ?
{
// rippled 1.11.0 or later
offer_id?: string
} :
T extends NFTokenAcceptOffer ?
{
// rippled 1.11.0 or later
nftoken_id?: string
} :
T extends NFTokenCancelOffer ?
{
// rippled 1.11.0 or later
nftoken_ids?: string[]
} :
{})
8 changes: 4 additions & 4 deletions packages/xrpl/src/models/transactions/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { CheckCancel, validateCheckCancel } from './checkCancel'
import { CheckCash, validateCheckCash } from './checkCash'
import { CheckCreate, validateCheckCreate } from './checkCreate'
import { Clawback, validateClawback } from './clawback'
import { isIssuedCurrency } from './common'
import { BaseTransaction, isIssuedCurrency } from './common'
import { DepositPreauth, validateDepositPreauth } from './depositPreauth'
import { EscrowCancel, validateEscrowCancel } from './escrowCancel'
import { EscrowCreate, validateEscrowCreate } from './escrowCreate'
Expand Down Expand Up @@ -97,9 +97,9 @@ export type Transaction =
/**
* @category Transaction Models
*/
export interface TransactionAndMetadata {
transaction: Transaction
metadata: TransactionMetadata
export interface TransactionAndMetadata<T extends BaseTransaction = Transaction> {
transaction: T
metadata: TransactionMetadata<T>
}

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/xrpl/test/integration/requests/accountTx.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ describe('account_tx', function () {
assert.equal(response.type, expected.type)
assert.equal(response.result.account, expected.result.account)
assert.equal(
(response.result.transactions[0].meta as TransactionMetadata)
(response.result.transactions[0].meta as TransactionMetadata<Payment>)
.TransactionResult,
'tesSUCCESS',
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { assert } from 'chai'
import { TransactionMetadata, TxRequest } from 'xrpl'

import { convertStringToHex, getNFTokenID, NFTokenMint } from '../../../src'
import { convertStringToHex, getNFTokenID, NFTokenMint, TransactionMetadata, TxRequest, TxResponse } from '../../../src'
import { hashSignedTx } from '../../../src/utils/hashes'
import serverUrl from '../serverUrl'
import {
Expand Down Expand Up @@ -55,7 +54,7 @@ describe('NFTokenMint', function () {
})

const nftokenID =
getNFTokenID(txResponse.result.meta as TransactionMetadata) ??
getNFTokenID(txResponse.result.meta as TransactionMetadata<NFTokenMint>) ??
'undefined'

const accountHasNFT = accountNFTs.result.account_nfts.some(
Expand Down

0 comments on commit a9790e9

Please sign in to comment.