-
Notifications
You must be signed in to change notification settings - Fork 85
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
incorporate DeliverMax in Payment transactions #684
Conversation
@mvadari I felt it is more appropriate to make the |
This won't work in a lot of cases (including internal uses of |
@mvadari I agree that there are limitations in my current design. If I were to make this change in
I'd like to test inputs such as
We are passing along |
That's a fair point. In that case, perhaps |
…d of Payment.from_dict
I have moved the changes to |
I disagree, because it's only ever going to be necessary when pulling from XRPL data, not from any other dictionary. |
@@ -468,3 +472,42 @@ def from_blob(tx_blob: str) -> Transaction: | |||
The formatted transaction. | |||
""" | |||
return Transaction.from_xrpl(decode(tx_blob)) | |||
|
|||
@classmethod | |||
def from_xrpl(cls: Type[T], inp_params: Union[str, Dict[str, Any]]) -> T: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def from_xrpl(cls: Type[T], inp_params: Union[str, Dict[str, Any]]) -> T: | |
def from_xrpl(cls: Type[T], value: Union[str, Dict[str, Any]]) -> T: |
This should use the same formatting as the function it's overriding.
Co-authored-by: Mayukha Vadari <mvadari@ripple.com>
Co-authored-by: Mayukha Vadari <mvadari@ripple.com>
Co-authored-by: Mayukha Vadari <mvadari@ripple.com>
Co-authored-by: Mayukha Vadari <mvadari@ripple.com>
I've addressed your comments @mvadari 👍 |
Co-authored-by: Mayukha Vadari <mvadari@ripple.com>
@mvadari does this design look okay? Can I do the same for JS too? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit changes only
xrpl/models/base_model.py
Outdated
@@ -73,6 +73,28 @@ def _value_to_json(value: XRPL_VALUE_TYPE) -> XRPL_VALUE_TYPE: | |||
return value | |||
|
|||
|
|||
def process_xrpl_json(value: Union[str, Dict[str, Any]]) -> Dict[str, Any]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like this function can return exceptions which we should note and/or handle
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know which exceptions might be thrown by this code. _key_to_json
and _value_to_json
do not throw any exceptions themselves
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you suspect that json.load
could throw a json.JSONDecodeError
exception?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function will never be directly used by end users.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mvadari Yes, I agree. Do you mean to say we don't have to document all possible exceptions?
XRPLModelException: If Payment transactions have different values for | ||
amount and deliver_max fields | ||
""" | ||
processed_value = process_xrpl_json(value) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This may not return successfully so we should likely note that in the docs
if "amount" in processed_value: | ||
if processed_value["amount"] != processed_value["deliver_max"]: | ||
raise XRPLModelException( | ||
"Error: Amount and DeliverMax fields are not identical" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there maybe a link we can give to explain why they should be equal in the error message?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, I can point to the issue discussion here: XRPLF/rippled#3484
Here is an implementation commit to the rippled codebase: XRPLF/rippled@3972683
I'm not aware of any other documents summarizing this issue.
DeliverMax
is an alias for the Amount
field. So if they contain different values, it introduces semantic ambiguity. Which one should we use? Both of them refer to the same logical quantity -- the value of transferred money
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If both fields are passed in, then they have to be equal. We can update the error message for clarity: "Error: Amount and DeliverMax fields must be equal if both are provided"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't link rippled issues from the libraries, point to the xrpl.org documentation. It's not useful to do so in error messages, because that makes the error message really long, but it can be in the docstring.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was brainstorming ideas for resource pages for this issue, I won't include it in the error message 👍
I couldn't find a statement that says "If present, DeliverMax
field must equal Amount
" in the Payments docs. https://xrpl.org/docs/references/protocol/transactions/types/payment#payment-fields
I feel it's a better developer experience to provide an elaborate error message, instead of making them search through a website.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DeliverMax
is only an RPC field, rippled doesn't care about it. It's only ever returned. That documentation should probably elaborate on that a bit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, documentation will help. DeliverMax
can also be used as an input in APIv2 rippled.
Every instance of DeliverMax
, at the protocol (or) binary-codec-level, is translated into Amount
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, it was not changed at the protocol level, just at the RPC level.
Co-authored-by: Omar Khan <khancodegt@gmail.com>
xrpl/models/base_model.py
Outdated
@@ -73,6 +73,28 @@ def _value_to_json(value: XRPL_VALUE_TYPE) -> XRPL_VALUE_TYPE: | |||
return value | |||
|
|||
|
|||
def process_xrpl_json(value: Union[str, Dict[str, Any]]) -> Dict[str, Any]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd recommend making this a helper class method, instead of a separate function - it saves you some imports. Similar to _get_only_init_args
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
okay, I have done this. But I dislike the fact that the self/cls
argument is not useful inside the process_xrpl_json
function. I'm only using it to hook into this function
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the tradeoff is worth it given that it makes it easier to use, but if someone strongly objects I'll withdraw
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, I think it's a reasonable tradeoff 👍
@khancode can you please take a look at this PR? does this design look alright? @justinr1234 I need some clarification on your prior comments. Let me know if I need to make any more changes. thnks |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, just need to change a method to be private.
the snippets tests are failing due to an unfunded account (We believe it lacks "USD" tokens). It will need to be addressed in a separate PR |
If there are no objections, I'd like to merge this PR. Thank you all for your feedback |
High Level Overview of Change
Add support for
DeliverMax
field in the Payment transactions. The following links will give you more context on theDeliverMax
field:XRPLF/rippled#4733, XRPLF/rippled#3484
Context of Change
Payment
transactions accept a new fieldDeliverMax
, which serves as an alias to theAmount
field. This is intended to prevent misinterpretation of the response ofPayment
transactions and the consequent loss of funds.Type of Change
Did you update CHANGELOG.md?
Test Plan
Additional unit tests have been added to validate the usage of
Payment
transactions.