-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add nfts_by_issuer * update Changelog * added nfts_by_issuer to Request's get_method * reformat changelog and add required comment for nfts_by_issuer.py * add include_delete field * update change log * another conflict fixed * create DNFT support * update changelog * fix dynamic nft * add more test * resolve comments * resolve comment --------- Co-authored-by: Kassaking <[email protected]> Co-authored-by: Kassaking7 <[email protected]> Co-authored-by: Zhiyuan Wang <[email protected]>
- Loading branch information
1 parent
eab5f67
commit a12b672
Showing
8 changed files
with
167 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
from unittest import TestCase | ||
|
||
from xrpl.models.exceptions import XRPLModelException | ||
from xrpl.models.transactions.nftoken_modify import NFTokenModify | ||
|
||
_ACCOUNT = "r9LqNeG6qHxjeUocjvVki2XR35weJ9mZgQ" | ||
_SEQUENCE = 19048 | ||
_FEE = "0.00001" | ||
_URI = "ABC" | ||
_NFTOKEN_ID = "00090032B5F762798A53D543A014CAF8B297CFF8F2F937E844B17C9E00000003" | ||
|
||
|
||
class TestNFTokenModify(TestCase): | ||
def test_nftoken_miss(self): | ||
with self.assertRaises(XRPLModelException) as error: | ||
NFTokenModify( | ||
account=_ACCOUNT, | ||
owner=_ACCOUNT, | ||
sequence=_SEQUENCE, | ||
fee=_FEE, | ||
uri=_URI, | ||
) | ||
self.assertEqual( | ||
error.exception.args[0], | ||
"{'nftoken_id': 'nftoken_id is not set'}", | ||
) | ||
|
||
def test_uri_empty(self): | ||
with self.assertRaises(XRPLModelException) as error: | ||
NFTokenModify( | ||
account=_ACCOUNT, | ||
owner=_ACCOUNT, | ||
sequence=_SEQUENCE, | ||
fee=_FEE, | ||
nftoken_id=_NFTOKEN_ID, | ||
uri="", | ||
) | ||
self.assertEqual( | ||
error.exception.args[0], | ||
"{'uri': 'URI must not be empty string'}", | ||
) | ||
|
||
def test_uri_too_long(self): | ||
with self.assertRaises(XRPLModelException) as error: | ||
NFTokenModify( | ||
account=_ACCOUNT, | ||
owner=_ACCOUNT, | ||
sequence=_SEQUENCE, | ||
fee=_FEE, | ||
nftoken_id=_NFTOKEN_ID, | ||
uri=_URI * 1000, | ||
) | ||
self.assertEqual( | ||
error.exception.args[0], | ||
"{'uri': 'URI must not be longer than 512 characters'}", | ||
) | ||
|
||
def test_uri_not_hex(self): | ||
with self.assertRaises(XRPLModelException) as error: | ||
NFTokenModify( | ||
account=_ACCOUNT, | ||
owner=_ACCOUNT, | ||
sequence=_SEQUENCE, | ||
fee=_FEE, | ||
nftoken_id=_NFTOKEN_ID, | ||
uri="not-hex-encoded", | ||
) | ||
self.assertEqual( | ||
error.exception.args[0], | ||
"{'uri': 'URI must be encoded in hex'}", | ||
) | ||
|
||
def test_valid(self): | ||
obj = NFTokenModify( | ||
account=_ACCOUNT, | ||
owner=_ACCOUNT, | ||
sequence=_SEQUENCE, | ||
fee=_FEE, | ||
uri=_URI, | ||
nftoken_id=_NFTOKEN_ID, | ||
) | ||
self.assertTrue(obj.is_valid()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters