mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-28 08:05:51 +00:00
Add nftoken_id, nftoken_ids, offer_id to meta fields (#2450)
Add type for metadata for specific transactions(`Payment`, `NFTokenMint`, `NFTokenCreateOffer`, `NFTokenAcceptOffer`, `NFTokenCancelOffer`) Closes #2316
This commit is contained in:
@@ -33,6 +33,7 @@ Subscribe to [the **xrpl-announce** mailing list](https://groups.google.com/g/xr
|
||||
* Remove `lodash` as a dependency
|
||||
* Remove many polyfills that were only used for testing in the browser
|
||||
* Remove `util` from bundle by switching `inspect` to `JSON.stringify`
|
||||
* Add type for metadata for specific transactions(`Payment`, `NFTokenMint`, `NFTokenCreateOffer`, `NFTokenAcceptOffer`, `NFTokenCancelOffer`)
|
||||
|
||||
### Fixed
|
||||
* Fixed Wallet.generate() ignoring the `algorithm` parameter (Only a problem once binary-codec fix for `derive_keypair` is added)
|
||||
|
||||
@@ -61,7 +61,7 @@ export interface TxResponse<
|
||||
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.
|
||||
|
||||
@@ -6,6 +6,7 @@ import {
|
||||
parseAmountValue,
|
||||
validateBaseTransaction,
|
||||
} from './common'
|
||||
import type { TransactionMetadataBase } from './metadata'
|
||||
|
||||
/**
|
||||
* The NFTokenOfferAccept transaction is used to accept offers
|
||||
@@ -64,6 +65,11 @@ export interface NFTokenAcceptOffer extends BaseTransaction {
|
||||
NFTokenBrokerFee?: Amount
|
||||
}
|
||||
|
||||
export interface NFTokenAcceptOfferMetadata extends TransactionMetadataBase {
|
||||
// rippled 1.11.0 or later
|
||||
nftoken_id?: string
|
||||
}
|
||||
|
||||
function validateNFTokenBrokerFee(tx: Record<string, unknown>): void {
|
||||
const value = parseAmountValue(tx.NFTokenBrokerFee)
|
||||
if (Number.isNaN(value)) {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { ValidationError } from '../../errors'
|
||||
|
||||
import { BaseTransaction, validateBaseTransaction } from './common'
|
||||
import type { TransactionMetadataBase } from './metadata'
|
||||
|
||||
/**
|
||||
* The NFTokenCancelOffer transaction deletes existing NFTokenOffer objects.
|
||||
@@ -26,6 +27,11 @@ export interface NFTokenCancelOffer extends BaseTransaction {
|
||||
NFTokenOffers: string[]
|
||||
}
|
||||
|
||||
export interface NFTokenCancelOfferMetadata extends TransactionMetadataBase {
|
||||
// rippled 1.11.0 or later
|
||||
nftoken_ids?: string[]
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify the form and type of an NFTokenCancelOffer at runtime.
|
||||
*
|
||||
|
||||
@@ -12,6 +12,7 @@ import {
|
||||
validateOptionalField,
|
||||
Account,
|
||||
} from './common'
|
||||
import type { TransactionMetadataBase } from './metadata'
|
||||
|
||||
/**
|
||||
* Transaction Flags for an NFTokenCreateOffer Transaction.
|
||||
@@ -86,6 +87,11 @@ export interface NFTokenCreateOffer extends BaseTransaction {
|
||||
Flags?: number | NFTokenCreateOfferFlagsInterface
|
||||
}
|
||||
|
||||
export interface NFTokenCreateOfferMetadata extends TransactionMetadataBase {
|
||||
// rippled 1.11.0 or later
|
||||
offer_id?: string
|
||||
}
|
||||
|
||||
function validateNFTokenSellOfferCases(tx: Record<string, unknown>): void {
|
||||
if (tx.Owner != null) {
|
||||
throw new ValidationError(
|
||||
|
||||
@@ -9,6 +9,7 @@ import {
|
||||
validateBaseTransaction,
|
||||
validateOptionalField,
|
||||
} from './common'
|
||||
import type { TransactionMetadataBase } from './metadata'
|
||||
|
||||
/**
|
||||
* Transaction Flags for an NFTokenMint Transaction.
|
||||
@@ -101,6 +102,11 @@ export interface NFTokenMint extends BaseTransaction {
|
||||
Flags?: number | NFTokenMintFlagsInterface
|
||||
}
|
||||
|
||||
export interface NFTokenMintMetadata extends TransactionMetadataBase {
|
||||
// rippled 1.11.0 or later
|
||||
nftoken_id?: string
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify the form and type of an NFTokenMint at runtime.
|
||||
*
|
||||
|
||||
@@ -1,5 +1,22 @@
|
||||
import { Amount } from '../common'
|
||||
|
||||
import { BaseTransaction } from './common'
|
||||
import {
|
||||
NFTokenAcceptOffer,
|
||||
NFTokenAcceptOfferMetadata,
|
||||
} from './NFTokenAcceptOffer'
|
||||
import {
|
||||
NFTokenCancelOffer,
|
||||
NFTokenCancelOfferMetadata,
|
||||
} from './NFTokenCancelOffer'
|
||||
import {
|
||||
NFTokenCreateOffer,
|
||||
NFTokenCreateOfferMetadata,
|
||||
} from './NFTokenCreateOffer'
|
||||
import { NFTokenMint, NFTokenMintMetadata } from './NFTokenMint'
|
||||
import { Payment, PaymentMetadata } from './payment'
|
||||
import type { Transaction } from './transaction'
|
||||
|
||||
export interface CreatedNode {
|
||||
CreatedNode: {
|
||||
LedgerEntryType: string
|
||||
@@ -59,7 +76,7 @@ export function isDeletedNode(node: Node): node is DeletedNode {
|
||||
return Object.prototype.hasOwnProperty.call(node, `DeletedNode`)
|
||||
}
|
||||
|
||||
export interface TransactionMetadata {
|
||||
export interface TransactionMetadataBase {
|
||||
AffectedNodes: Node[]
|
||||
DeliveredAmount?: Amount
|
||||
// "unavailable" possible for transactions before 2014-01-20
|
||||
@@ -67,3 +84,16 @@ export interface TransactionMetadata {
|
||||
TransactionIndex: number
|
||||
TransactionResult: string
|
||||
}
|
||||
|
||||
export type TransactionMetadata<T extends BaseTransaction = Transaction> =
|
||||
T extends Payment
|
||||
? PaymentMetadata
|
||||
: T extends NFTokenMint
|
||||
? NFTokenMintMetadata
|
||||
: T extends NFTokenCreateOffer
|
||||
? NFTokenCreateOfferMetadata
|
||||
: T extends NFTokenAcceptOffer
|
||||
? NFTokenAcceptOfferMetadata
|
||||
: T extends NFTokenCancelOffer
|
||||
? NFTokenCancelOfferMetadata
|
||||
: TransactionMetadataBase
|
||||
|
||||
@@ -13,6 +13,7 @@ import {
|
||||
isNumber,
|
||||
Account,
|
||||
} from './common'
|
||||
import type { TransactionMetadataBase } from './metadata'
|
||||
|
||||
/**
|
||||
* Enum representing values for Payment Transaction Flags.
|
||||
@@ -151,6 +152,11 @@ export interface Payment extends BaseTransaction {
|
||||
Flags?: number | PaymentFlagsInterface
|
||||
}
|
||||
|
||||
export interface PaymentMetadata extends TransactionMetadataBase {
|
||||
DeliveredAmount?: Amount
|
||||
delivered_amount?: Amount | 'unavailable'
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify the form and type of a Payment at runtime.
|
||||
*
|
||||
|
||||
@@ -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 { DIDDelete, validateDIDDelete } from './DIDDelete'
|
||||
import { DIDSet, validateDIDSet } from './DIDSet'
|
||||
@@ -140,9 +140,11 @@ export type PseudoTransaction = EnableAmendment | SetFee | UNLModify
|
||||
/**
|
||||
* @category Transaction Models
|
||||
*/
|
||||
export interface TransactionAndMetadata {
|
||||
transaction: Transaction
|
||||
metadata: TransactionMetadata
|
||||
export interface TransactionAndMetadata<
|
||||
T extends BaseTransaction = Transaction,
|
||||
> {
|
||||
transaction: T
|
||||
metadata: TransactionMetadata<T>
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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',
|
||||
)
|
||||
|
||||
@@ -1,7 +1,12 @@
|
||||
import { assert } from 'chai'
|
||||
import { TransactionMetadata, TxRequest } from 'xrpl'
|
||||
|
||||
import { convertStringToHex, getNFTokenID, NFTokenMint } from '../../../src'
|
||||
import {
|
||||
convertStringToHex,
|
||||
getNFTokenID,
|
||||
NFTokenMint,
|
||||
TransactionMetadata,
|
||||
TxRequest,
|
||||
} from '../../../src'
|
||||
import { hashSignedTx } from '../../../src/utils/hashes'
|
||||
import serverUrl from '../serverUrl'
|
||||
import {
|
||||
@@ -55,8 +60,9 @@ describe('NFTokenMint', function () {
|
||||
})
|
||||
|
||||
const nftokenID =
|
||||
getNFTokenID(txResponse.result.meta as TransactionMetadata) ??
|
||||
'undefined'
|
||||
getNFTokenID(
|
||||
txResponse.result.meta as TransactionMetadata<NFTokenMint>,
|
||||
) ?? 'undefined'
|
||||
|
||||
const accountHasNFT = accountNFTs.result.account_nfts.some(
|
||||
(value) => value.NFTokenID === nftokenID,
|
||||
|
||||
Reference in New Issue
Block a user