-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3eaccf9
commit 261a601
Showing
3 changed files
with
75 additions
and
7 deletions.
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 |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package types | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
"strconv" | ||
) | ||
|
||
type HTTPPredicate func(response *http.Response) error | ||
|
||
func HTTPPredicateAlwaysPass() HTTPPredicate { | ||
return func(response *http.Response) error { | ||
return nil | ||
} | ||
} | ||
|
||
func HTTPPredicateCheckHeightAfter(prevHeight int64) HTTPPredicate { | ||
return func(response *http.Response) error { | ||
currentHeightHeader := response.Header.Get("Grpc-Metadata-X-Cosmos-Block-Height") | ||
|
||
// not returned height is ok | ||
if currentHeightHeader == "" { | ||
return nil | ||
} | ||
|
||
currentHeight, err := strconv.ParseInt(currentHeightHeader, 10, 64) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if prevHeight > currentHeight { | ||
return fmt.Errorf( | ||
"previous height (%d) is bigger than the current height (%d)", | ||
prevHeight, | ||
currentHeight, | ||
) | ||
} | ||
|
||
return nil | ||
} | ||
} |