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

feat: added ticket_sequence to Transaction class common fields #428

Merged
merged 12 commits into from
Sep 1, 2022
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Function to parse the final account balances from a transaction's metadata
- Function to parse order book changes from a transaction's metadata
- Support for Ed25519 seeds that don't use the `sEd` prefix
- Common field ticket_sequence to Transaction class
connorjchen marked this conversation as resolved.
Show resolved Hide resolved

### Fixed:
- Typing for factory classmethods on models
Expand Down
43 changes: 43 additions & 0 deletions tests/unit/models/transactions/test_transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
_ACCOUNT = "r9LqNeG6qHxjeUocjvVki2XR35weJ9mZgQ"
_FEE = "0.00001"
_SEQUENCE = 19048
_TICKET_SEQUENCE = 20510
_ACCOUNT_TXN_ID = "66F3D6158CAB6E53405F8C264DB39F07D8D0454433A63DDFB98218ED1BC99B60"


class TestTransaction(TestCase):
Expand Down Expand Up @@ -79,3 +81,44 @@ def test_to_dict_flag_list(self):
expected_flags = 0b111
value = tx.to_dict()["flags"]
self.assertEqual(value, expected_flags)

def test_to_dict_ticket_sequence(self):
tx = Transaction(
account=_ACCOUNT,
fee=_FEE,
ticket_sequence=_TICKET_SEQUENCE,
transaction_type=TransactionType.ACCOUNT_DELETE,
)
value = tx.to_dict()["ticket_sequence"]
self.assertEqual(value, _TICKET_SEQUENCE)

def test_to_dict_ticket_sequence_with_sequence_zero(self):
tx = Transaction(
account=_ACCOUNT,
fee=_FEE,
sequence=0,
ticket_sequence=_TICKET_SEQUENCE,
transaction_type=TransactionType.ACCOUNT_DELETE,
)
value = tx.to_dict()["ticket_sequence"]
self.assertEqual(value, _TICKET_SEQUENCE)

def test_throws_when_ticket_sequence_and_sequence_both_nonzero(self):
with self.assertRaises(XRPLModelException):
Transaction(
account=_ACCOUNT,
fee=_FEE,
sequence=_SEQUENCE,
ticket_sequence=_TICKET_SEQUENCE,
transaction_type=TransactionType.ACCOUNT_DELETE,
)

def test_throws_when_ticket_sequence_and_account_tx_in_both_included(self):
with self.assertRaises(XRPLModelException):
Transaction(
account=_ACCOUNT,
fee=_FEE,
account_txn_id=_ACCOUNT_TXN_ID,
ticket_sequence=_TICKET_SEQUENCE,
transaction_type=TransactionType.ACCOUNT_DELETE,
)
18 changes: 18 additions & 0 deletions xrpl/models/transactions/transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,12 +243,30 @@ class Transaction(BaseModel):
added during signing.
"""

ticket_sequence: Optional[int] = None
"""
The sequence number of the ticket to use in place of a Sequence number. If
this is provided, Sequence must be 0. Cannot be used with account_txn_id.
connorjchen marked this conversation as resolved.
Show resolved Hide resolved
"""

txn_signature: Optional[str] = None
"""
The cryptographic signature from the sender that authorizes this
transaction. Automatically added during signing.
"""

def _get_errors(self: Transaction) -> Dict[str, str]:
errors = super()._get_errors()
if self.ticket_sequence is not None and (
(self.sequence is not None and self.sequence != 0)
or self.account_txn_id is not None
):
errors[
"Transaction"
] = """If ticket_sequence is provided,
account_txn_id must be None and sequence must be None or 0"""
return errors

def to_dict(self: Transaction) -> Dict[str, Any]:
"""
Returns the dictionary representation of a Transaction.
Expand Down