error.go 833 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package ethchain
  2. import "fmt"
  3. // Parent error. In case a parent is unknown this error will be thrown
  4. // by the block manager
  5. type ParentErr struct {
  6. Message string
  7. }
  8. func (err *ParentErr) Error() string {
  9. return err.Message
  10. }
  11. func ParentError(hash []byte) error {
  12. return &ParentErr{Message: fmt.Sprintf("Block's parent unkown %x", hash)}
  13. }
  14. func IsParentErr(err error) bool {
  15. _, ok := err.(*ParentErr)
  16. return ok
  17. }
  18. // Block validation error. If any validation fails, this error will be thrown
  19. type ValidationErr struct {
  20. Message string
  21. }
  22. func (err *ValidationErr) Error() string {
  23. return err.Message
  24. }
  25. func ValidationError(format string, v ...interface{}) *ValidationErr {
  26. return &ValidationErr{Message: fmt.Sprintf(format, v...)}
  27. }
  28. func IsValidationErr(err error) bool {
  29. _, ok := err.(*ValidationErr)
  30. return ok
  31. }