Skip to content
Open
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [[Unreleased]]

### Fixed

- Fix `Request.from_xrpl` by aliasing it to `Request.from_dict`

## [[4.4.0]] - 2025-12-16

### Added
Expand Down
12 changes: 12 additions & 0 deletions tests/unit/models/requests/test_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,18 @@ def test_from_dict(self):
}
self.assertDictEqual(obj.to_dict(), expected)

def test_from_xrpl(self):
req = {"method": "account_tx", "account": "rN6zcSynkRnf8zcgTVrRL8K7r4ovE7J4Zj"}
obj = Request.from_xrpl(req)
self.assertEqual(obj.__class__.__name__, "AccountTx")
expected = {
**req,
"binary": False,
"forward": False,
"api_version": _DEFAULT_API_VERSION,
}
self.assertDictEqual(obj.to_dict(), expected)
Comment on lines +32 to +42
Copy link

Copilot AI Dec 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test only verifies from_xrpl with a dictionary input. According to the method signature and documentation, from_xrpl also accepts a JSON string. Consider adding a test case that passes a JSON string to ensure both input types work correctly. For example: obj = Request.from_xrpl(json.dumps(req)).

Copilot uses AI. Check for mistakes.

def test_from_dict_no_method(self):
req = {"account": "rN6zcSynkRnf8zcgTVrRL8K7r4ovE7J4Zj"}
with self.assertRaises(XRPLModelException):
Expand Down
17 changes: 17 additions & 0 deletions xrpl/models/requests/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from __future__ import annotations

import json
from dataclasses import dataclass
from enum import Enum
from typing import Any, Dict, Optional, Type, Union, cast
Expand Down Expand Up @@ -162,6 +163,22 @@ def from_dict(cls: Type[Self], value: Dict[str, Any]) -> Self:

return super(Request, cls).from_dict(value)

@classmethod
def from_xrpl(cls: Type[Self], value: Union[str, Dict[str, Any]]) -> Self:
"""
Construct a new Request from a dictionary of parameters. Alias of `from_dict`.

Args:
value: The value to construct the Request from.

Returns:
A new Request object, constructed using the given parameters.

Raises:
XRPLModelException: If the dictionary provided is invalid.
"""
return cls.from_dict(value if isinstance(value, dict) else json.loads(value))

@classmethod
def get_method(cls: Type[Self], method: str) -> Type[Request]:
"""
Expand Down