Skip to content

Commit

Permalink
Support NFTokenMintOffer
Browse files Browse the repository at this point in the history
  • Loading branch information
tequdev committed Jan 10, 2025
1 parent 84943ae commit c1a73fe
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 0 deletions.
3 changes: 3 additions & 0 deletions packages/xrpl/HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ Subscribe to [the **xrpl-announce** mailing list](https://groups.google.com/g/xr

## Unreleased Changes

### Added
* Support for XLS-52 (NFTokenMintOffer)

## 4.1.0 (2024-12-23)

### Added
Expand Down
37 changes: 37 additions & 0 deletions packages/xrpl/src/models/transactions/NFTokenMint.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import { ValidationError } from '../../errors'
import { Amount } from '../common'
import { isHex } from '../utils'

import {
Account,
BaseTransaction,
GlobalFlags,
isAccount,
isAmount,
isNumber,
validateBaseTransaction,
validateOptionalField,
} from './common'
Expand Down Expand Up @@ -99,12 +102,34 @@ export interface NFTokenMint extends BaseTransaction {
* set to `undefined` value if you do not use it.
*/
URI?: string | null
/**
* Indicates the amount for the Token.
*
* The amount can be zero. This would indicate that the account is giving
* the token away free, either to anyone at all, or to the account identified
* by the Destination field.
*/
Amount?: Amount
/**
* Indicates the time after which the offer will no longer
* be valid. The value is the number of seconds since the
* Ripple Epoch.
*/
Expiration?: number
/**
* If present, indicates that this offer may only be
* accepted by the specified account. Attempts by other
* accounts to accept this offer MUST fail.
*/
Destination?: Account
Flags?: number | NFTokenMintFlagsInterface
}

export interface NFTokenMintMetadata extends TransactionMetadataBase {
// rippled 1.11.0 or later
nftoken_id?: string
// if Amount is present
offer_id?: string
}

/**
Expand Down Expand Up @@ -135,4 +160,16 @@ export function validateNFTokenMint(tx: Record<string, unknown>): void {
if (tx.NFTokenTaxon == null) {
throw new ValidationError('NFTokenMint: missing field NFTokenTaxon')
}

if (tx.Amount == null) {
if (tx.Expiration != null || tx.Destination != null) {
throw new ValidationError(
'NFTokenMint: Amount is required when Expiration or Destination is present',
)
}
}

validateOptionalField(tx, 'Amount', isAmount)
validateOptionalField(tx, 'Expiration', isNumber)
validateOptionalField(tx, 'Destination', isAccount)
}
52 changes: 52 additions & 0 deletions packages/xrpl/test/models/NFTokenMint.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,56 @@ describe('NFTokenMint', function () {
'NFTokenMint: URI must be in hex format',
)
})

it(`throws when Amount is null but Expiration is present`, function () {
const invalid = {
TransactionType: 'NFTokenMint',
Account: 'rWYkbWkCeg8dP6rXALnjgZSjjLyih5NXm',
Fee: '5000000',
Sequence: 2470665,
NFTokenTaxon: 0,
Issuer: 'r9LqNeG6qHxjeUocjvVki2XR35weJ9mZgQ',
Expiration: 123456,
} as any

assert.throws(
() => validate(invalid),
ValidationError,
'NFTokenMint: Amount is required when Expiration or Destination is present',
)
})

it(`throws when Amount is null but Destination is present`, function () {
const invalid = {
TransactionType: 'NFTokenMint',
Account: 'rWYkbWkCeg8dP6rXALnjgZSjjLyih5NXm',
Fee: '5000000',
Sequence: 2470665,
NFTokenTaxon: 0,
Issuer: 'r9LqNeG6qHxjeUocjvVki2XR35weJ9mZgQ',
Destination: 'rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn',
} as any

assert.throws(
() => validate(invalid),
ValidationError,
'NFTokenMint: Amount is required when Expiration or Destination is present',
)
})

it(`verifies valid NFTokenMint with Amount, Destination and Expiration`, function () {
const valid = {
TransactionType: 'NFTokenMint',
Account: 'rWYkbWkCeg8dP6rXALnjgZSjjLyih5NXm',
Fee: '5000000',
Sequence: 2470665,
NFTokenTaxon: 0,
Issuer: 'r9LqNeG6qHxjeUocjvVki2XR35weJ9mZgQ',
Amount: '1000000',
Destination: 'rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn',
Expiration: 123456,
} as any

assert.doesNotThrow(() => validate(valid))
})
})

0 comments on commit c1a73fe

Please sign in to comment.