Skip to content

Commit

Permalink
nits
Browse files Browse the repository at this point in the history
  • Loading branch information
patrick-ogrady committed May 22, 2020
1 parent 0690a43 commit 40a6db7
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 4 deletions.
36 changes: 32 additions & 4 deletions parser/match_operations.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// Copyright 2020 Coinbase, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package parser

import (
Expand Down Expand Up @@ -158,7 +172,11 @@ func accountMatch(req *AccountDescription, account *types.AccountIdentifier) err

// Optionally can require a certain subaccount address
if len(req.SubAccountAddress) > 0 && account.SubAccount.Address != req.SubAccountAddress {
return fmt.Errorf("SubAccountIdentifier.Address is %s not %s", account.SubAccount.Address, req.SubAccountAddress)
return fmt.Errorf(
"SubAccountIdentifier.Address is %s not %s",
account.SubAccount.Address,
req.SubAccountAddress,
)
}

if err := metadataMatch(req.SubAccountMetadataKeys, account.SubAccount.Metadata); err != nil {
Expand Down Expand Up @@ -205,7 +223,12 @@ func amountMatch(req *AmountDescription, amount *types.Amount) error {

// operationMatch returns an error if a *types.Operation does not match a
// *OperationDescription.
func operationMatch(groupIndex int, operation *types.Operation, descriptions []*OperationDescription, matches []int) {
func operationMatch(
groupIndex int,
operation *types.Operation,
descriptions []*OperationDescription,
matches []int,
) {
for i, req := range descriptions {
if matches[i] != -1 { // already matched
continue
Expand Down Expand Up @@ -328,8 +351,13 @@ func MatchOperations(
return nil, errors.New("unable to match 0 descriptions")
}

if descriptions.RejectExtraOperations && len(descriptions.OperationDescriptions) != len(operations) {
return nil, fmt.Errorf("expected %d operations, got %d", len(descriptions.OperationDescriptions), len(operations))
if descriptions.RejectExtraOperations &&
len(descriptions.OperationDescriptions) != len(operations) {
return nil, fmt.Errorf(
"expected %d operations, got %d",
len(descriptions.OperationDescriptions),
len(operations),
)
}

operationDescriptions := descriptions.OperationDescriptions
Expand Down
14 changes: 14 additions & 0 deletions parser/match_operations_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// Copyright 2020 Coinbase, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package parser

import (
Expand Down

0 comments on commit 40a6db7

Please sign in to comment.