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

XLS-52 support #733

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
33 changes: 33 additions & 0 deletions tests/unit/models/transactions/test_nftoken_mint.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from xrpl.models.transactions import NFTokenMint

_ACCOUNT = "r9LqNeG6qHxjeUocjvVki2XR35weJ9mZgQ"
_ANOTHER_ACCOUNT = "rsA2LpzuawewSBQXkiju3YQTMzW13pAAdW"
_FEE = "0.00001"
_SEQUENCE = 19048

Expand Down Expand Up @@ -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",
)
Original file line number Diff line number Diff line change
Expand Up @@ -477,4 +477,4 @@
"hash": "1C57BFD847DBBAB78211229AA9AC8965B8EF705390ABAD8C2E79C98520EE9B10",
"ledger_index": 77781462,
"date": 1676330052000
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -345,4 +345,4 @@
"hash": "77130966274E7DB385AC262A944AC20178611EE694EE0CA75A32C8760791521F",
"ledger_index": 77804695,
"date": 1676421542000
}
}
41 changes: 41 additions & 0 deletions xrpl/models/transactions/nftoken_mint.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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
}
Expand All @@ -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
Loading