-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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-85d: Token-Enabled Escrows #5185
Open
dangell7
wants to merge
13
commits into
XRPLF:develop
Choose a base branch
from
Transia-RnD:iou-escrow
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
67fa360
featureTokenEscrow
dangell7 d35eba4
add additional token checks
dangell7 74f8974
fix bad test
dangell7 8f17f8a
fix escrow create
dangell7 0829085
remove frozen from EscrowFinish & EscrowCancel
dangell7 1ff6328
remove mptoken escrow test
dangell7 cf72258
add transfer rate helper func
dangell7 4c72ae2
clean tests
dangell7 0651264
clang-format
dangell7 12f432f
[refactor] escrow test framework
dangell7 54d4e2a
[review] misc comments
dangell7 b08c1c7
Merge branch 'develop' into iou-escrow
dangell7 d961dea
Merge branch 'develop' into iou-escrow
dangell7 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -684,6 +684,48 @@ isXRP(STAmount const& amount) | |
return amount.native(); | ||
} | ||
|
||
/** returns true if adding or subtracting results in less than or equal to | ||
* 0.01% precision loss **/ | ||
inline bool | ||
isAddable(STAmount const& amt1, STAmount const& amt2) | ||
{ | ||
// special case: adding anything to zero is always fine | ||
if (amt1 == beast::zero || amt2 == beast::zero) | ||
return true; | ||
|
||
// special case: adding two xrp amounts together. | ||
// this is just an overflow check | ||
if (isXRP(amt1) && isXRP(amt2)) | ||
{ | ||
XRPAmount A = (amt1.signum() == -1 ? -(amt1.xrp()) : amt1.xrp()); | ||
XRPAmount B = (amt2.signum() == -1 ? -(amt2.xrp()) : amt2.xrp()); | ||
|
||
XRPAmount finalAmt = A + B; | ||
return (finalAmt >= A && finalAmt >= B); | ||
} | ||
|
||
static const STAmount one{IOUAmount{1, 0}, noIssue()}; | ||
static const STAmount maxLoss{IOUAmount{1, -4}, noIssue()}; | ||
|
||
STAmount A = amt1; | ||
STAmount B = amt2; | ||
|
||
if (isXRP(A)) | ||
A = STAmount{IOUAmount{A.xrp().drops(), -6}, noIssue()}; | ||
|
||
if (isXRP(B)) | ||
B = STAmount{IOUAmount{B.xrp().drops(), -6}, noIssue()}; | ||
|
||
A.setIssue(noIssue()); | ||
B.setIssue(noIssue()); | ||
|
||
STAmount lhs = divide((A - B) + B, A, noIssue()) - one; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The logic behind addition / division for STAmount is a bit complicated to guess if this will work. Please add tests for |
||
STAmount rhs = divide((B - A) + A, B, noIssue()) - one; | ||
|
||
return ((rhs.negative() ? -rhs : rhs) + (lhs.negative() ? -lhs : lhs)) <= | ||
maxLoss; | ||
} | ||
|
||
// Since `canonicalize` does not have access to a ledger, this is needed to put | ||
// the low-level routine stAmountCanonicalize on an amendment switch. Only | ||
// transactions need to use this switchover. Outside of a transaction it's safe | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
As underlying type of the XRPAmount is signed, this is incorrect (undefined behavior in case of the overflow).
Consider something like