remove validate

This commit is contained in:
William Banfield
2022-10-20 15:43:09 -04:00
parent 2b7b2f2012
commit 61834bb5fc

View File

@@ -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
}