aboutsummaryrefslogtreecommitdiffstats
path: root/ethchain/error.go
blob: 0f1d061c0db8dbb9f814414c4499d1825492db5c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package ethchain

import "fmt"

// Parent error. In case a parent is unknown this error will be thrown
// by the block manager
type ParentErr struct {
    Message string
}

func (err *ParentErr) Error() string {
    return err.Message
}

func ParentError(hash []byte) error {
    return &ParentErr{Message: fmt.Sprintf("Block's parent unkown %x", hash)}
}

func IsParentErr(err error) bool {
    _, ok := err.(*ParentErr)

    return ok
}

// Block validation error. If any validation fails, this error will be thrown
type ValidationErr struct {
    Message string
}

func (err *ValidationErr) Error() string {
    return err.Message
}

func ValidationError(format string, v ...interface{}) *ValidationErr {
    return &ValidationErr{Message: fmt.Sprintf(format, v...)}
}

func IsValidationErr(err error) bool {
    _, ok := err.(*ValidationErr)

    return ok
}