diff --git a/src/models/transactions/NFTokenBurn.ts b/src/models/transactions/NFTokenBurn.ts new file mode 100644 index 00000000..f70042c7 --- /dev/null +++ b/src/models/transactions/NFTokenBurn.ts @@ -0,0 +1,46 @@ +import { ValidationError } from '../../errors' + +import { BaseTransaction, validateBaseTransaction } from './common' + +/** + * The NFTokenBurn transaction is used to remove an NFToken object from the + * NFTokenPage in which it is being held, effectively removing the token from + * the ledger ("burning" it). + * + * If this operation succeeds, the corresponding NFToken is removed. If this + * operation empties the NFTokenPage holding the NFToken or results in the + * consolidation, thus removing an NFTokenPage, the owner’s reserve requirement + * is reduced by one. + */ +export interface NFTokenBurn extends BaseTransaction { + TransactionType: 'NFTokenBurn' + /** + * Indicates the AccountID that submitted this transaction. The account MUST + * be either the present owner of the token or, if the lsfBurnable flag is set + * in the NFToken, either the issuer account or an account authorized by the + * issuer, i.e. MintAccount. + */ + Account: string + /** + * Identifies the NFToken object to be removed by the transaction. + */ + TokenID: string +} + +/** + * Verify the form and type of an NFTokenBurn at runtime. + * + * @param tx - An NFTokenBurn Transaction. + * @throws When the NFTokenBurn is Malformed. + */ +export function validateNFTokenBurn(tx: Record): void { + validateBaseTransaction(tx) + + if (tx.Account == null) { + throw new ValidationError('NFTokenBurn: missing field Account') + } + + if (tx.TokenID == null) { + throw new ValidationError('NFTokenBurn: missing field TokenID') + } +} diff --git a/src/models/transactions/NFTokenMint.ts b/src/models/transactions/NFTokenMint.ts new file mode 100644 index 00000000..84efd2a6 --- /dev/null +++ b/src/models/transactions/NFTokenMint.ts @@ -0,0 +1,109 @@ +import { ValidationError } from '../../errors' + +import { BaseTransaction, GlobalFlags, validateBaseTransaction } from './common' + +/** + * Transaction Flags for an NFTokenMint Transaction. + * + * @category Transaction Flags + */ +export enum NFTokenMintFlags { + /** + * If set, indicates that the minted token may be burned by the issuer even + * if the issuer does not currently hold the token. The current holder of + * the token may always burn it. + */ + tfBurnable = 0x00000001, + /** + * If set, indicates that the token may only be offered or sold for XRP. + */ + tfOnlyXRP = 0x00000002, + /** + * If set, indicates that the issuer wants a trustline to be automatically + * created. + */ + tfTrustLine = 0x00000004, + /** + * If set, indicates that this NFT can be transferred. This flag has no + * effect if the token is being transferred from the issuer or to the + * issuer. + */ + tfTransferable = 0x00000008, +} + +/** + * Map of flags to boolean values representing {@link NFTokenMint} transaction + * flags. + * + * @category Transaction Flags + */ +export interface NFTokenMintFlagsInterface extends GlobalFlags { + tfBurnable?: boolean + tfOnlyXRP?: boolean + tfTrustLine?: boolean + tfTransferable?: boolean +} + +/** + * The NFTokenMint transaction creates an NFToken object and adds it to the + * relevant NFTokenPage object of the minter. If the transaction is + * successful, the newly minted token will be owned by the minter account + * specified by the transaction. + */ +export interface NFTokenMint extends BaseTransaction { + TransactionType: 'NFTokenMint' + /** + * Indicates the account that is minting the token. + */ + Account: string + /** + * Indicates the taxon associated with this token. The taxon is generally a + * value chosen by the minter of the token and a given taxon may be used for + * multiple tokens. The implementation reserves taxon identifiers greater + * than or equal to 2147483648 (0x80000000). + */ + TokenTaxon: number + /** + * Indicates the account that should be the issuer of this token. This value + * is optional and should only be specified if the account executing the + * transaction is not the `Issuer` of the `NFToken` object. If it is + * present, the `MintAccount` field in the `AccountRoot` of the `Issuer` + * field must match the `Account`, otherwise the transaction will fail. + */ + Issuer?: string + /** + * Specifies the fee charged by the issuer for secondary sales of the Token, + * if such sales are allowed. Valid values for this field are between 0 and + * 50000 inclusive, allowing transfer rates between 0.000% and 50.000% in + * increments of 0.001%. This field must NOT be present if the + * `tfTransferable` flag is not set. + */ + TransferFee?: number + /** + * URI that points to the data and/or metadata associated with the NFT. + * This field need not be an HTTP or HTTPS URL; it could be an IPFS URI, a + * magnet link, immediate data encoded as an RFC2379 "data" URL, or even an + * opaque issuer-specific encoding. The URI is NOT checked for validity, but + * the field is limited to a maximum length of 256 bytes. + */ + URI?: string + Flags?: number | NFTokenMintFlagsInterface +} + +/** + * Verify the form and type of an NFTokenMint at runtime. + * + * @param tx - An NFTokenMint Transaction. + * @throws When the NFTokenMint is Malformed. + */ +export function validateNFTokenMint(tx: Record): void { + validateBaseTransaction(tx) + + if (tx.Account == null) { + throw new ValidationError('NFTokenMint: missing field Account') + } + + if (tx.TokenTaxon == null) { + throw new ValidationError('NFTokenMint: missing field TokenTaxon') + } +} diff --git a/src/models/transactions/index.ts b/src/models/transactions/index.ts index b78d2cb9..7af68ffc 100644 --- a/src/models/transactions/index.ts +++ b/src/models/transactions/index.ts @@ -14,6 +14,12 @@ export { DepositPreauth } from './depositPreauth' export { EscrowCancel } from './escrowCancel' export { EscrowCreate } from './escrowCreate' export { EscrowFinish } from './escrowFinish' +export { NFTokenBurn } from './NFTokenBurn' +export { + NFTokenMint, + NFTokenMintFlags, + NFTokenMintFlagsInterface, +} from './NFTokenMint' export { OfferCancel } from './offerCancel' export { OfferCreateFlags, diff --git a/src/models/transactions/transaction.ts b/src/models/transactions/transaction.ts index dbae85fd..4a899b5b 100644 --- a/src/models/transactions/transaction.ts +++ b/src/models/transactions/transaction.ts @@ -17,6 +17,8 @@ import { EscrowCancel, validateEscrowCancel } from './escrowCancel' import { EscrowCreate, validateEscrowCreate } from './escrowCreate' import { EscrowFinish, validateEscrowFinish } from './escrowFinish' import { TransactionMetadata } from './metadata' +import { NFTokenBurn, validateNFTokenBurn } from './NFTokenBurn' +import { NFTokenMint, validateNFTokenMint } from './NFTokenMint' import { OfferCancel, validateOfferCancel } from './offerCancel' import { OfferCreate, validateOfferCreate } from './offerCreate' import { Payment, validatePayment } from './payment' @@ -50,6 +52,8 @@ export type Transaction = | EscrowCancel | EscrowCreate | EscrowFinish + | NFTokenBurn + | NFTokenMint | OfferCancel | OfferCreate | Payment @@ -124,6 +128,14 @@ export function validate(transaction: Record): void { validateEscrowFinish(tx) break + case 'NFTokenBurn': + validateNFTokenBurn(tx) + break + + case 'NFTokenMint': + validateNFTokenMint(tx) + break + case 'OfferCancel': validateOfferCancel(tx) break