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

Add Ledger Objects #663

Closed
wants to merge 63 commits into from
Closed

Add Ledger Objects #663

wants to merge 63 commits into from

Conversation

LimpidCrypto
Copy link
Contributor

@LimpidCrypto LimpidCrypto commented Oct 27, 2023

High Level Overview of Change

This PR adds (some) Ledger Object models:

  • AccountRoot
  • Amendment
  • AMM
  • Bridge
  • Check
  • DepositPreauth
  • DID
  • DirectoryNode
  • Escrow
  • FeeSettings
  • LedgerHashes
  • LedgerObject
  • NegativeUNL
  • NFTokenOffer
  • NFTokenPage
  • Offer
  • PayChannel
  • RippleState
  • SignerList
  • Ticket
  • XChainOwnedClaimID
  • XChainOwnedCreateAccountClaimID

You might want to look over the fields if they are still correct as it's been a while since I wrote them.

TODO

Context of Change

@JST5000 and I had a great chat this week. He told me one thing you might prioritize as a coming feature would be response models. I remembered I once had a PR adding Ledger Object and Metadata models and was told to split it up into two PRs, but somehow I forgot about it. This PR adds the Ledger objects. I could imagine there are some objects missing or are a bit deprecated but I still wanted to leave the progress made here for you to use.

Type of Change

  • New feature (non-breaking change which adds functionality)

Did you update CHANGELOG.md?

  • TODO: Yes

Test Plan

I wrote tests trying to de-/serialize them from/to json.

@LimpidCrypto LimpidCrypto mentioned this pull request Oct 27, 2023
2 tasks
@khancode khancode requested a review from ckeshava January 19, 2024 17:41
Copy link
Collaborator

@ckeshava ckeshava left a comment

Choose a reason for hiding this comment

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

Hi Omar and @LimpidCrypto , nice work! thanks for putting all the ledger objects together.

I used this file as the source of truth (https://github.com/XRPLF/rippled/blob/develop/src/ripple/protocol/impl/LedgerFormats.cpp), so I found a few differences in the python implementation.

Let me know my suggestions make sense

xrpl/models/ledger_objects/check.py Outdated Show resolved Hide resolved
xrpl/models/ledger_objects/check.py Show resolved Hide resolved
xrpl/models/ledger_objects/account_root.py Show resolved Hide resolved
xrpl/models/ledger_objects/directory_node.py Show resolved Hide resolved
xrpl/models/ledger_objects/offer.py Outdated Show resolved Hide resolved
xrpl/models/ledger_objects/nftoken_page.py Outdated Show resolved Hide resolved
xrpl/models/ledger_objects/nftoken_offer.py Outdated Show resolved Hide resolved
xrpl/models/ledger_objects/amm.py Show resolved Hide resolved
xrpl/models/ledger_objects/amm.py Show resolved Hide resolved
xrpl/models/ledger_objects/__init__.py Show resolved Hide resolved
@khancode khancode requested a review from mvadari February 13, 2024 19:18
provided or the type mismatches the constructor type.
"""
if cls.__name__ == "LedgerObject":
if "ledger_entry_type" not in value:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why are you not verifying this condition in the upper level else (last branch)?
Shouldn't we throw an exception here: if cls.__name__ != "LedgerObject" and cls.__name__ not in ["FinalFields", "PreviousFields", "NewFields"] and "ledger_entry_type" not in value ?

Copy link
Collaborator

Choose a reason for hiding this comment

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

As a follow-up question: I notice that 21 unit tests in test_ledger_object.py do not have a LedgerObjectEntry in their expected json. Isn't that an issue? Shouldn't all necessarily LedgerObjects contain this field?

@@ -54,6 +56,10 @@ def interface_to_flag_list(
f[:-4]: _flag_enum_to_dict(getattr(transactions.pseudo_transactions, f))
for f in pseudo_tx_flag_enums
},
**{
Copy link
Collaborator

Choose a reason for hiding this comment

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

interface_to_flag_list appears to be used in conjunction with Transaction class. Why are we including LedgerObject flags in this list?

"TransferRate": 1004999999,
"index": "13F1A95D7AAB7108D5CE7EEAF504B2894B8C674E6D68499076441C4837282BF8",
}
actual = LedgerObject.from_xrpl(account_root_json)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can the tests also check to_xrpl, since that's just adding one line? Just to make sure that everything's correct.

Comment on lines +127 to +130
wallet_size: Optional[int] = None
"""
Unused. (The code supports this field but there is no way to set it.)
"""
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should this field be included?

Comment on lines +26 to +28
API method. (Note, even though this is specified as "optional" in the code, every
ledger entry should have one unless it's legacy data from very early in the XRP
Ledger's history.)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should this just be specified as required here?

Comment on lines +35 to +37
API method. (Note, even though this is specified as "optional" in the code, every
ledger entry should have one unless it's legacy data from very early in the XRP
Ledger's history.)
Copy link
Collaborator

Choose a reason for hiding this comment

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

ditto

Comment on lines +73 to +80
elif cls.__name__ in ["FinalFields", "PreviousFields", "NewFields"]:
if "ledger_entry_type" not in value:
raise XRPLModelException(
"Ledger Object does not include ledger_entry_type."
)
correct_type = cls.get_md_ledger_object_type(value["ledger_entry_type"])
del value["ledger_entry_type"]
return correct_type.from_dict(value) # type: ignore
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why is this part included? FinalFields, PreviousFields and NewFields don't inherit from LedgerObject, and therefore this elif will never be hit.

)

@classmethod
def get_md_ledger_object_type(
Copy link
Collaborator

@mvadari mvadari Feb 23, 2024

Choose a reason for hiding this comment

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

I don't understand what the objective/purpose of this function is

f"{ledger_object_type} is not a valid Ledger Object type."
)

def __getitem__(self: LedgerObject, field_name: str) -> Any:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is there a reason why this function exists for this base class and not for transactions or requests? It seems unnecessary.

@khancode khancode removed their request for review June 26, 2024 13:38
@mvadari
Copy link
Collaborator

mvadari commented Jun 27, 2024

@khancode this PR should also add support for the fixPreviousTxnID amendment, which was added in rippled 2.2.0.

XRPLF/rippled#4751

@khancode
Copy link
Collaborator

@khancode this PR should also add support for the fixPreviousTxnID amendment, which was added in rippled 2.2.0.

XRPLF/rippled#4751

Update: this PR is deprioritized and I'm no longer working on it. Feel free to pick it up or anyone else.

@LimpidCrypto LimpidCrypto closed this by deleting the head repository Aug 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants