mirror of
https://github.com/fluencelabs/tendermint
synced 2025-06-12 12:51:22 +00:00
initial port of cosmos-sdk basecli proxy
This commit is contained in:
40
lite/proxy/block.go
Normal file
40
lite/proxy/block.go
Normal file
@ -0,0 +1,40 @@
|
||||
package proxy
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"github.com/tendermint/tendermint/lite"
|
||||
certerr "github.com/tendermint/tendermint/lite/errors"
|
||||
"github.com/tendermint/tendermint/types"
|
||||
)
|
||||
|
||||
func ValidateBlockMeta(meta *types.BlockMeta, check lite.Commit) error {
|
||||
// TODO: check the BlockID??
|
||||
return ValidateHeader(meta.Header, check)
|
||||
}
|
||||
|
||||
func ValidateBlock(meta *types.Block, check lite.Commit) error {
|
||||
err := ValidateHeader(meta.Header, check)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !bytes.Equal(meta.Data.Hash(), meta.Header.DataHash) {
|
||||
return errors.New("Data hash doesn't match header")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func ValidateHeader(head *types.Header, check lite.Commit) error {
|
||||
// make sure they are for the same height (obvious fail)
|
||||
if head.Height != check.Height() {
|
||||
return certerr.ErrHeightMismatch(head.Height, check.Height())
|
||||
}
|
||||
// check if they are equal by using hashes
|
||||
chead := check.Header
|
||||
if !bytes.Equal(head.Hash(), chead.Hash()) {
|
||||
return errors.New("Headers don't match")
|
||||
}
|
||||
return nil
|
||||
}
|
Reference in New Issue
Block a user