Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dnft support #728

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Add `nfts_by_issuer` clio-only API definition
- Included `ctid` field in the `tx` request.
- `from_xrpl` method accepts input dictionary keys exclusively in the proper XRPL format.
- Add `NFTokenModify` transaction and add `TF_MUTABLE` flag in `NFTokenMintFlag`

### Fixed
- Added support for `XChainModifyBridge` flag maps (fixing an issue with `NFTokenCreateOffer` flag names)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ def test_nftoken_mint_flags(self):
TF_ONLY_XRP=True,
TF_TRANSFERABLE=True,
TF_TRUSTLINE=True,
TF_MUTABLE=True,
),
)
self.assertTrue(actual.has_flag(flag=0x00000001))
Expand Down
28 changes: 28 additions & 0 deletions tests/unit/models/transactions/test_nftoken_modify.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from unittest import TestCase

from xrpl.models.exceptions import XRPLModelException
from xrpl.models.transactions.nftoken_modify import NFTokenModify

_ACCOUNT = "r9LqNeG6qHxjeUocjvVki2XR35weJ9mZgQ"
_SEQUENCE = 19048

_NFTOKEN_ID = "00090032B5F762798A53D543A014CAF8B297CFF8F2F937E844B17C9E00000003"


class TestNFTokenModify(TestCase):
def test_nftoken_miss(self):
with self.assertRaises(XRPLModelException):
NFTokenModify(
owner=_ACCOUNT,
sequence=_SEQUENCE,
uri=_ACCOUNT * 1000,
)

def test_uri_empty(self):
with self.assertRaises(XRPLModelException):
NFTokenModify(
owner=_ACCOUNT,
sequence=_SEQUENCE,
nftoken_id=_NFTOKEN_ID,
uri="",
)
1 change: 1 addition & 0 deletions xrpl/models/requests/ledger_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ class LedgerEntry(Request, LookupByLedgerRequest):
binary: bool = False
nft_page: Optional[str] = None
"""Must be the object ID of the NFToken page, as hexadecimal"""
include_deleted: Optional[bool] = None

def _get_errors(self: Self) -> Dict[str, str]:
errors = super()._get_errors()
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
6 changes: 6 additions & 0 deletions xrpl/models/transactions/nftoken_mint.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ class NFTokenMintFlag(int, Enum):
issuer.
"""

TF_MUTABLE = 0x00000010
"""
If set, indicates that this NFT's URI can be modified.
"""


class NFTokenMintFlagInterface(FlagInterface):
"""Transaction Flags for an NFTokenMint Transaction."""
Expand All @@ -54,6 +59,7 @@ class NFTokenMintFlagInterface(FlagInterface):
TF_ONLY_XRP: bool
TF_TRUSTLINE: bool
TF_TRANSFERABLE: bool
TF_MUTABLE: bool


@require_kwargs_on_init
Expand Down
65 changes: 65 additions & 0 deletions xrpl/models/transactions/nftoken_modify.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
"""Model for NFTokenModify transaction type and related flags."""

from __future__ import annotations

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

from typing_extensions import 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 KW_ONLY_DATACLASS, require_kwargs_on_init


@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 "NFTokenModify: URI must not be empty string"
return None
1 change: 1 addition & 0 deletions xrpl/models/transactions/types/transaction_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class TransactionType(str, Enum):
NFTOKEN_CANCEL_OFFER = "NFTokenCancelOffer"
NFTOKEN_CREATE_OFFER = "NFTokenCreateOffer"
NFTOKEN_MINT = "NFTokenMint"
NFTOKEN_MODIFY = "NFTokenModify"
OFFER_CANCEL = "OfferCancel"
OFFER_CREATE = "OfferCreate"
ORACLE_SET = "OracleSet"
Expand Down
Loading