Skip to content

Commit

Permalink
linter
Browse files Browse the repository at this point in the history
  • Loading branch information
patrick-ogrady committed May 31, 2020
1 parent 7cdbdba commit f1b0824
Showing 1 changed file with 19 additions and 22 deletions.
41 changes: 19 additions & 22 deletions parser/match_operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -392,40 +392,37 @@ func matchIndexValid(matches []*Match, index int) error {
return nil
}

// comparisonMatch ensures collections of *types.Operations
// have either equal or opposite amounts.
func comparisonMatch(
descriptions *Descriptions,
matches []*Match,
) error {
for _, amountMatch := range descriptions.EqualAmounts {
func checkOps(requests [][]int, matches []*Match, valid func([]*types.Operation) error) error {
for _, batch := range requests {
ops := []*types.Operation{}
for _, reqIndex := range amountMatch {
for _, reqIndex := range batch {
if err := matchIndexValid(matches, reqIndex); err != nil {
return fmt.Errorf("%w: equal amounts comparison error", err)
return fmt.Errorf("%w: index %d not valid", err, reqIndex)
}

ops = append(ops, matches[reqIndex].Operations...)
}

if err := equalAmounts(ops); err != nil {
return fmt.Errorf("%w: operations not equal", err)
if err := valid(ops); err != nil {
return fmt.Errorf("%w operations not valid", err)
}
}

for _, addressMatch := range descriptions.EqualAddresses {
ops := []*types.Operation{}
for _, reqIndex := range addressMatch {
if err := matchIndexValid(matches, reqIndex); err != nil {
return fmt.Errorf("%w: equal addresses comparison error", err)
}
return nil
}

ops = append(ops, matches[reqIndex].Operations...)
}
// comparisonMatch ensures collections of *types.Operations
// have either equal or opposite amounts.
func comparisonMatch(
descriptions *Descriptions,
matches []*Match,
) error {
if err := checkOps(descriptions.EqualAmounts, matches, equalAmounts); err != nil {
return fmt.Errorf("%w: operation amounts not equal", err)
}

if err := equalAddresses(ops); err != nil {
return fmt.Errorf("%w: addresses not equal", err)
}
if err := checkOps(descriptions.EqualAddresses, matches, equalAddresses); err != nil {
return fmt.Errorf("%w: operation addresses not equal", err)
}

for _, amountMatch := range descriptions.OppositeAmounts {
Expand Down

0 comments on commit f1b0824

Please sign in to comment.