|
| 1 | +import { ValidationError } from '../../errors' |
| 2 | +import { isHex } from '../utils' |
| 3 | + |
| 4 | +import { |
| 5 | + BaseTransaction, |
| 6 | + validateBaseTransaction, |
| 7 | + isAccount, |
| 8 | + isString, |
| 9 | + validateOptionalField, |
| 10 | + Account, |
| 11 | + validateRequiredField, |
| 12 | +} from './common' |
| 13 | + |
| 14 | +/** |
| 15 | + * The NFTokenModify transaction modifies an NFToken's URI |
| 16 | + * if its tfMutable is set to true. |
| 17 | + */ |
| 18 | +export interface NFTokenModify extends BaseTransaction { |
| 19 | + TransactionType: 'NFTokenModify' |
| 20 | + /** |
| 21 | + * Identifies the NFTokenID of the NFToken object that the |
| 22 | + * offer references. |
| 23 | + */ |
| 24 | + NFTokenID: string |
| 25 | + /** |
| 26 | + * Indicates the AccountID of the account that owns the corresponding NFToken. |
| 27 | + * Can be omitted if the owner is the account submitting this transaction |
| 28 | + */ |
| 29 | + Owner?: Account |
| 30 | + /** |
| 31 | + * URI that points to the data and/or metadata associated with the NFT. |
| 32 | + * This field need not be an HTTP or HTTPS URL; it could be an IPFS URI, a |
| 33 | + * magnet link, immediate data encoded as an RFC2379 "data" URL, or even an |
| 34 | + * opaque issuer-specific encoding. The URI is NOT checked for validity, but |
| 35 | + * the field is limited to a maximum length of 256 bytes. |
| 36 | + * |
| 37 | + * This field must be hex-encoded. You can use `convertStringToHex` to |
| 38 | + * convert this field to the proper encoding. |
| 39 | + * |
| 40 | + * This field must not be an empty string. Omit it from the transaction or |
| 41 | + * set to `undefined` value if you do not use it. |
| 42 | + */ |
| 43 | + URI?: string | null |
| 44 | +} |
| 45 | + |
| 46 | +/** |
| 47 | + * Verify the form and type of an NFTokenModify at runtime. |
| 48 | + * |
| 49 | + * @param tx - An NFTokenModify Transaction. |
| 50 | + * @throws When the NFTokenModify is Malformed. |
| 51 | + */ |
| 52 | +export function validateNFTokenModify(tx: Record<string, unknown>): void { |
| 53 | + validateBaseTransaction(tx) |
| 54 | + |
| 55 | + validateRequiredField(tx, 'NFTokenID', isString) |
| 56 | + validateOptionalField(tx, 'Owner', isAccount) |
| 57 | + validateOptionalField(tx, 'URI', isString) |
| 58 | + |
| 59 | + if (tx.URI !== undefined && typeof tx.URI === 'string') { |
| 60 | + if (tx.URI === '') { |
| 61 | + throw new ValidationError('NFTokenModify: URI must not be empty string') |
| 62 | + } |
| 63 | + if (!isHex(tx.URI)) { |
| 64 | + throw new ValidationError('NFTokenModify: URI must be in hex format') |
| 65 | + } |
| 66 | + } |
| 67 | +} |
0 commit comments