2018-07-17 21:23:07 +00:00
|
|
|
package history
|
|
|
|
|
|
|
|
import (
|
|
|
|
"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-07-20 16:37:46 +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,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (validator HeaderValidator) ValidateHeaders() ValidationWindow {
|
|
|
|
window := MakeValidationWindow(validator.blockChain, validator.windowSize)
|
|
|
|
blockNumbers := MakeRange(window.LowerBound, window.UpperBound)
|
|
|
|
RetrieveAndUpdateHeaders(validator.blockChain, validator.headerRepository, blockNumbers)
|
|
|
|
return window
|
|
|
|
}
|