mirror of
https://github.com/tendermint/tendermint.git
synced 2026-04-28 19:36:57 +00:00
remove validate
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
package blocksync
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/gogo/protobuf/proto"
|
||||
@@ -60,48 +59,3 @@ func (m *Message) Unwrap() (proto.Message, error) {
|
||||
return nil, fmt.Errorf("unknown message: %T", msg)
|
||||
}
|
||||
}
|
||||
|
||||
// Validate validates the message returning an error upon failure.
|
||||
func (m *Message) Validate() error {
|
||||
if m == nil {
|
||||
return errors.New("message cannot be nil")
|
||||
}
|
||||
|
||||
switch msg := m.Sum.(type) {
|
||||
case *Message_BlockRequest:
|
||||
if m.GetBlockRequest().Height < 0 {
|
||||
return errors.New("negative Height")
|
||||
}
|
||||
|
||||
case *Message_BlockResponse:
|
||||
// validate basic is called later when converting from proto
|
||||
return nil
|
||||
|
||||
case *Message_NoBlockResponse:
|
||||
if m.GetNoBlockResponse().Height < 0 {
|
||||
return errors.New("negative Height")
|
||||
}
|
||||
|
||||
case *Message_StatusResponse:
|
||||
if m.GetStatusResponse().Base < 0 {
|
||||
return errors.New("negative Base")
|
||||
}
|
||||
if m.GetStatusResponse().Height < 0 {
|
||||
return errors.New("negative Height")
|
||||
}
|
||||
if m.GetStatusResponse().Base > m.GetStatusResponse().Height {
|
||||
return fmt.Errorf(
|
||||
"base %v cannot be greater than height %v",
|
||||
m.GetStatusResponse().Base, m.GetStatusResponse().Height,
|
||||
)
|
||||
}
|
||||
|
||||
case *Message_StatusRequest:
|
||||
return nil
|
||||
|
||||
default:
|
||||
return fmt.Errorf("unknown message type: %T", msg)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user