Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions xrpl/core/binarycodec/definitions/definitions.json
Original file line number Diff line number Diff line change
Expand Up @@ -2568,6 +2568,7 @@
"AccountDelete": 21,
"SetHook": 22,
"NFTokenMint": 25,
"NFTokenModify": 61,
"NFTokenBurn": 26,
"NFTokenCreateOffer": 27,
"NFTokenCancelOffer": 28,
Expand Down
2 changes: 1 addition & 1 deletion xrpl/models/base_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def from_dict(cls: Type[BM], value: Dict[str, XRPL_VALUE_TYPE]) -> BM:
for param in value:
if param not in class_types:
# Do not fail parsing if we encounter an unknown arg
logging.warn(
logging.debug(
f"{param} not a valid parameter for {cls.__name__}"
)
continue
Expand Down
2 changes: 2 additions & 0 deletions xrpl/models/transactions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
NFTokenMintFlag,
NFTokenMintFlagInterface,
)
from xrpl.models.transactions.nftoken_modify import NFTokenModify
from xrpl.models.transactions.offer_cancel import OfferCancel
from xrpl.models.transactions.offer_create import (
OfferCreate,
Expand Down Expand Up @@ -129,6 +130,7 @@
"NFTokenMint",
"NFTokenMintFlag",
"NFTokenMintFlagInterface",
"NFTokenModify",
"OfferCancel",
"OfferCreate",
"OfferCreateFlag",
Expand Down
72 changes: 72 additions & 0 deletions xrpl/models/transactions/nftoken_modify.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
"""Model for NFTokenModify transaction type."""

from __future__ import annotations

from dataclasses import dataclass, field
from typing import Dict, Optional

from typing_extensions import Final, Self

from xrpl.models.required import REQUIRED
from xrpl.models.transactions.transaction import Transaction
from xrpl.models.transactions.types import TransactionType
from xrpl.models.utils import HEX_REGEX, KW_ONLY_DATACLASS, require_kwargs_on_init

_MAX_URI_LENGTH: Final[int] = 512


@require_kwargs_on_init
@dataclass(frozen=True, **KW_ONLY_DATACLASS)
class NFTokenModify(Transaction):
"""
The NFTokenModify transaction modifies an NFToken's URI
if its tfMutable is set to true.
"""

nftoken_id: str = REQUIRED # type: ignore
"""
Identifies the TokenID of the NFToken object that the
offer references. This field is required.
"""

owner: Optional[str] = None
"""
Indicates the AccountID of the account that owns the
corresponding NFToken.
"""

uri: Optional[str] = None
"""
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.

This field must be hex-encoded. You can use `xrpl.utils.str_to_hex` to
convert a UTF-8 string to hex.
"""

transaction_type: TransactionType = field(
default=TransactionType.NFTOKEN_MODIFY,
init=False,
)

def _get_errors(self: Self) -> Dict[str, str]:
return {
key: value
for key, value in {
**super()._get_errors(),
"uri": self._get_uri_error(),
}.items()
if value is not None
}

def _get_uri_error(self: Self) -> Optional[str]:
if not self.uri:
return "URI must not be empty string"
elif len(self.uri) > _MAX_URI_LENGTH:
return f"URI must not be longer than {_MAX_URI_LENGTH} characters"

if not HEX_REGEX.fullmatch(self.uri):
return "URI must be encoded in hex"
return None
3 changes: 2 additions & 1 deletion xrpl/models/transactions/types/transaction_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class TransactionType(str, Enum):
PAYMENT_CHANNEL_CLAIM = "PaymentChannelClaim"
PAYMENT_CHANNEL_CREATE = "PaymentChannelCreate"
PAYMENT_CHANNEL_FUND = "PaymentChannelFund"
NFTOKEN_MODIFY = "NFTokenModify"
SET_REGULAR_KEY = "SetRegularKey"
SIGNER_LIST_SET = "SignerListSet"
TICKET_CREATE = "TicketCreate"
Expand All @@ -48,4 +49,4 @@ class TransactionType(str, Enum):
XCHAIN_COMMIT = "XChainCommit"
XCHAIN_CREATE_BRIDGE = "XChainCreateBridge"
XCHAIN_CREATE_CLAIM_ID = "XChainCreateClaimID"
XCHAIN_MODIFY_BRIDGE = "XChainModifyBridge"
XCHAIN_MODIFY_BRIDGE = "XChainModifyBridge"
8 changes: 7 additions & 1 deletion xrpl/models/utils.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
"""Helper util functions for the models module."""
import re
from dataclasses import dataclass, is_dataclass
from typing import Any, Dict, List, Type, TypeVar, cast
from typing import Any, Dict, List, Optional, Pattern, Type, TypeVar, cast

from typing_extensions import Final

from xrpl.models.exceptions import XRPLModelException

HEX_REGEX: Final[Pattern[str]] = re.compile("[a-fA-F0-9]*")


# Code source for requiring kwargs:
# https://gist.github.com/mikeholler/4be180627d3f8fceb55704b729464adb

Expand Down
Loading