From 1fa153255217cbfedc7b354db143c40a4b3a517a Mon Sep 17 00:00:00 2001 From: xVet Date: Mon, 22 Jul 2024 04:16:24 +0200 Subject: [PATCH] modify ntoken_mint --- docs/conf.py | 1 + .../models/transactions/test_nftoken_mint.py | 33 +++++++++++++++ .../nftokenmint_response1.json | 2 +- .../nftokenmint_response2.json | 2 +- xrpl/models/transactions/nftoken_mint.py | 41 +++++++++++++++++++ 5 files changed, 77 insertions(+), 2 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index 105cef27b..540a0b795 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -13,6 +13,7 @@ # import os import sys + import sphinx_rtd_theme sys.path.insert(0, os.path.abspath("../")) diff --git a/tests/unit/models/transactions/test_nftoken_mint.py b/tests/unit/models/transactions/test_nftoken_mint.py index 912452e55..8dc3fc2e9 100644 --- a/tests/unit/models/transactions/test_nftoken_mint.py +++ b/tests/unit/models/transactions/test_nftoken_mint.py @@ -5,6 +5,7 @@ from xrpl.models.transactions import NFTokenMint _ACCOUNT = "r9LqNeG6qHxjeUocjvVki2XR35weJ9mZgQ" +_ANOTHER_ACCOUNT = "rsA2LpzuawewSBQXkiju3YQTMzW13pAAdW" _FEE = "0.00001" _SEQUENCE = 19048 @@ -39,3 +40,35 @@ def test_uri_too_long(self): nftoken_taxon=0, uri=_ACCOUNT * 1000, ) + + def test_nftoken_mint_sell_offer_with_zero_amount(self): + with self.assertRaises(XRPLModelException): + NFTokenMint( + account=_ACCOUNT, + fee=_FEE, + sequence=_SEQUENCE, + nftoken_taxon=0, + amount="0", + ) + + def test_destination_is_account(self): + with self.assertRaises(XRPLModelException): + NFTokenMint( + account=_ACCOUNT, + destination=_ACCOUNT, + fee=_FEE, + sequence=_SEQUENCE, + nftoken_taxon=0, + amount="1", + ) + + def test_nftoken_mint_sell_offer_with_negative_amount(self): + with self.assertRaises(XRPLModelException): + NFTokenMint( + account=_ACCOUNT, + destination=_ANOTHER_ACCOUNT, + fee=_FEE, + sequence=_SEQUENCE, + nftoken_taxon=0, + amount="-1", + ) diff --git a/tests/unit/utils/txn_parser/transaction_jsons/nftokenmint_response1.json b/tests/unit/utils/txn_parser/transaction_jsons/nftokenmint_response1.json index 9baf35420..8761341dc 100644 --- a/tests/unit/utils/txn_parser/transaction_jsons/nftokenmint_response1.json +++ b/tests/unit/utils/txn_parser/transaction_jsons/nftokenmint_response1.json @@ -477,4 +477,4 @@ "hash": "1C57BFD847DBBAB78211229AA9AC8965B8EF705390ABAD8C2E79C98520EE9B10", "ledger_index": 77781462, "date": 1676330052000 - } \ No newline at end of file + } diff --git a/tests/unit/utils/txn_parser/transaction_jsons/nftokenmint_response2.json b/tests/unit/utils/txn_parser/transaction_jsons/nftokenmint_response2.json index 9bac69321..533a46a37 100644 --- a/tests/unit/utils/txn_parser/transaction_jsons/nftokenmint_response2.json +++ b/tests/unit/utils/txn_parser/transaction_jsons/nftokenmint_response2.json @@ -345,4 +345,4 @@ "hash": "77130966274E7DB385AC262A944AC20178611EE694EE0CA75A32C8760791521F", "ledger_index": 77804695, "date": 1676421542000 - } \ No newline at end of file + } diff --git a/xrpl/models/transactions/nftoken_mint.py b/xrpl/models/transactions/nftoken_mint.py index 0e3154c41..ab45ed026 100644 --- a/xrpl/models/transactions/nftoken_mint.py +++ b/xrpl/models/transactions/nftoken_mint.py @@ -8,6 +8,7 @@ from typing_extensions import Final, Self +from xrpl.models.amounts import Amount, get_amount_value from xrpl.models.flags import FlagInterface from xrpl.models.required import REQUIRED from xrpl.models.transactions.transaction import Transaction @@ -106,6 +107,32 @@ class NFTokenMint(Transaction): convert a UTF-8 string to hex. """ + amount: Optional[Amount] = None + """ + Indicates the amount expected or offered for the Token. + + The amount must be non-zero, except when this is a sell + offer and the asset is XRP. This would indicate that the current + owner of the token is giving it away free, either to anyone at all, + or to the account identified by the Destination field. This field + is required. + + """ + + destination: Optional[str] = None + """ + If present, indicates that this offer may only be + accepted by the specified account. Attempts by other + accounts to accept this offer MUST fail. + """ + + expiration: Optional[int] = None + """ + Indicates the time after which the offer will no longer + be valid. The value is the number of seconds since the + Ripple Epoch. + """ + transaction_type: TransactionType = field( default=TransactionType.NFTOKEN_MINT, init=False, @@ -119,6 +146,8 @@ def _get_errors(self: Self) -> Dict[str, str]: "issuer": self._get_issuer_error(), "transfer_fee": self._get_transfer_fee_error(), "uri": self._get_uri_error(), + "amount": self._get_amount_error(), + "destination": self._get_destination_error(), }.items() if value is not None } @@ -137,3 +166,15 @@ def _get_uri_error(self: Self) -> Optional[str]: if self.uri is not None and len(self.uri) > _MAX_URI_LENGTH: return f"Must not be longer than {_MAX_URI_LENGTH} characters" return None + + def _get_amount_error(self: Self) -> Optional[str]: + if self.amount is None: + return "Amount must be provided" + elif get_amount_value(self.amount) <= 0: + return "Must be greater than 0 for a buy offer" + return None + + def _get_destination_error(self: Self) -> Optional[str]: + if self.destination == self.account: + return "Must not be equal to the account" + return None