Skip to content

Commit

Permalink
remove interface
Browse files Browse the repository at this point in the history
  • Loading branch information
aljo242 committed Aug 26, 2024
1 parent 3274608 commit e561897
Showing 1 changed file with 3 additions and 12 deletions.
15 changes: 3 additions & 12 deletions providers/apis/defi/types/block_age.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,15 @@ import "time"
// BlockAgeChecker is a utility type to check if incoming block heights are validly updating.
// If the block heights are not increasing and the time since the last update has exceeded
// a configurable duration, this type will report that the updates are invalid.
//
//go:generate mockery --name BlockAgeChecker --output ./mocks/ --case underscore
type BlockAgeChecker interface {
IsHeightValid(newHeight uint64) bool
}

var _ BlockAgeChecker = &BlockAgeCheckerImpl{}

// BlockAgeCheckerImpl is an implementation of the BlockAgeChecker interface.
type BlockAgeCheckerImpl struct {
type BlockAgeChecker struct {
lastHeight uint64
lastTimeStamp time.Time
maxAge time.Duration
}

// NewBlockAgeChecker returns a zeroed BlockAgeChecker using the provided maxAge.
func NewBlockAgeChecker(maxAge time.Duration) BlockAgeChecker {
return &BlockAgeCheckerImpl{
return BlockAgeChecker{
lastHeight: 0,
lastTimeStamp: time.Now(),
maxAge: maxAge,
Expand All @@ -34,7 +25,7 @@ func NewBlockAgeChecker(maxAge time.Duration) BlockAgeChecker {
// - the time past the last block height update is less than the configured max age
// returns false if:
// - the time is past the configured max age.
func (bc *BlockAgeCheckerImpl) IsHeightValid(newHeight uint64) bool {
func (bc *BlockAgeChecker) IsHeightValid(newHeight uint64) bool {
now := time.Now()

if newHeight > bc.lastHeight {
Expand Down

0 comments on commit e561897

Please sign in to comment.