2018-07-17 21:23:07 +00:00
|
|
|
package history
|
|
|
|
|
|
|
|
import (
|
2019-01-11 09:58:41 +00:00
|
|
|
log "github.com/sirupsen/logrus"
|
2018-07-17 21:23:07 +00:00
|
|
|
"github.com/vulcanize/vulcanizedb/pkg/core"
|
|
|
|
"github.com/vulcanize/vulcanizedb/pkg/datastore"
|
|
|
|
)
|
|
|
|
|
|
|
|
type HeaderValidator struct {
|
2018-07-20 16:37:46 +00:00
|
|
|
blockChain core.BlockChain
|
2018-07-17 21:23:07 +00:00
|
|
|
headerRepository datastore.HeaderRepository
|
|
|
|
windowSize int
|
|
|
|
}
|
|
|
|
|
2018-08-14 21:59:41 +00:00
|
|
|
func NewHeaderValidator(blockChain core.BlockChain, repository datastore.HeaderRepository, windowSize int) HeaderValidator {
|
2018-07-17 21:23:07 +00:00
|
|
|
return HeaderValidator{
|
|
|
|
blockChain: blockChain,
|
|
|
|
headerRepository: repository,
|
|
|
|
windowSize: windowSize,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-11 09:58:41 +00:00
|
|
|
func (validator HeaderValidator) ValidateHeaders() (ValidationWindow, error) {
|
2018-07-17 21:23:07 +00:00
|
|
|
window := MakeValidationWindow(validator.blockChain, validator.windowSize)
|
|
|
|
blockNumbers := MakeRange(window.LowerBound, window.UpperBound)
|
2019-01-11 09:58:41 +00:00
|
|
|
_, err := RetrieveAndUpdateHeaders(validator.blockChain, validator.headerRepository, blockNumbers)
|
|
|
|
if err != nil {
|
|
|
|
log.Error("Error in ValidateHeaders: ", err)
|
|
|
|
return ValidationWindow{}, err
|
|
|
|
}
|
|
|
|
return window, nil
|
2018-07-17 21:23:07 +00:00
|
|
|
}
|