-
Notifications
You must be signed in to change notification settings - Fork 135
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
[Parser] Update parser.MatchOperations to do non-negative and non-positive matching #305
[Parser] Update parser.MatchOperations to do non-negative and non-positive matching #305
Conversation
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.
looks great! left some smoll comments! 🙏
parser/match_operations.go
Outdated
PositiveAmountSign = 2 | ||
|
||
// PositiveOrZeroAmountSign is a positive or zero amount. | ||
PositiveAmountSignOrZero = 3 |
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.
Comment (PositiveOrZeroAmountSign
) and constant names (PositiveAmountSignOrZero
) don't match.
I would personally prefer PositiveOrZeroAmountSign
, for naming consistency, even though zero is not a sign.
parser/match_operations.go
Outdated
PositiveAmountSignOrZero = 3 | ||
|
||
// NegativeOrZeroAmountSign is a positive or zero amount. | ||
NegativeAmountSignOrZero = 4 |
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.
Same comment as before :)
// OppositeZeroAmounts are specified using the operation indices of | ||
// OperationDescriptions to handle out of order matches. MatchOperations | ||
// will error if all groups of operations aren't 0 or opposites. | ||
OppositeOrZeroAmounts [][]int |
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.
Name in comment (OppositeZeroAmounts
) and constant name (OppositeOrZeroAmounts
) do not match.
parser/match_operations.go
Outdated
oppositeAmountCheckers := []func(*types.Operation, *types.Operation) error{ | ||
oppositeOrZeroAmounts, | ||
oppositeAmounts, | ||
} |
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.
The 3d array makes grasping the code kinda difficult (this file is pretty difficult to read as is :( ).
Can we instead utilize a function to which we pass amountPairs
, amountChecker
and anything else that is needed (matches
) and call it twice. Once for OppositeAmounts
and once for OppositeOrZeroAmounts
? 🙏
cd25d86
to
fa48c1d
Compare
…mount operations. Also add corresponding validation function and test
…y change value of a variable just by adding a line in the wrong place.
fa48c1d
to
da643b1
Compare
Motivation
There are several cases where the matcher may expect opposite amounts but zero amounts are sent. Instead of having clients implement additional fallback logic, we want to update the sdk to be able to handle non-negative or non-positive scenarios when expecting opposite amounts.
Solution
Add a new OppositeOrZeroAmounts matcher and corresponding matching logic instead of replacing the existing OppositeAmounts matcher. This way, this isn't a breaking change for other users of the library.
Add PositiveAmountSignOrZero and NegativeAmountSignOrZero amount signs for amount matching when using
OppositeOrZeroAmounts
. We could just use AnyAmountSign, but these additional signs let us get the same order of matches as withOppositeAmounts
.Open questions
MatchOperations
matter?