-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: check for previous height when querying
- Loading branch information
1 parent
b5b6f57
commit 253f95f
Showing
4 changed files
with
54 additions
and
2 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
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,34 @@ | ||
package types | ||
|
||
import ( | ||
"fmt" | ||
"main/pkg/utils" | ||
"net/http" | ||
) | ||
|
||
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 { | ||
currentHeight, err := utils.GetBlockHeightFromHeader(response.Header) | ||
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 | ||
} | ||
} |