-
Notifications
You must be signed in to change notification settings - Fork 104
/
Errors.go
93 lines (81 loc) · 3.46 KB
/
Errors.go
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package main
import "errors"
// StratumError Stratum错误
type StratumError struct {
// 错误号
ErrNo int
// 错误信息
ErrMsg string
}
// NewStratumError 新建一个StratumError
func NewStratumError(errNo int, errMsg string) *StratumError {
err := new(StratumError)
err.ErrNo = errNo
err.ErrMsg = errMsg
return err
}
// Error 实现StratumError的Error()接口以便其被当做error类型使用
func (err *StratumError) Error() string {
return err.ErrMsg
}
// ToJSONRPCArray 转换为JSONRPCArray
func (err *StratumError) ToJSONRPCArray(extData interface{}) interface{} {
if err == nil {
return nil
}
return JSONRPCArray{err.ErrNo, err.ErrMsg, extData}
}
var (
// ErrBufIOReadTimeout 从bufio.Reader中读取数据时超时
ErrBufIOReadTimeout = errors.New("bufIO read timeout")
// ErrSessionIDFull SessionID已满(所有可用值均已分配)
ErrSessionIDFull = errors.New("session id is full")
// ErrSessionIDOccupied SessionID已被占用(恢复SessionID时)
ErrSessionIDOccupied = errors.New("session id has been occupied")
// ErrParseSubscribeResponseFailed 解析订阅响应失败
ErrParseSubscribeResponseFailed = errors.New("parse subscribe response failed")
// ErrSessionIDInconformity 返回的会话ID和当前保存的不匹配
ErrSessionIDInconformity = errors.New("session id inconformity")
// ErrAuthorizeFailed 认证失败
ErrAuthorizeFailed = errors.New("authorize failed")
// ErrTooMuchPendingAutoRegReq 太多等待中的自动注册请求
ErrTooMuchPendingAutoRegReq = errors.New("too much pending auto reg request")
)
var (
// StratumErrJobNotFound 任务不存在
StratumErrJobNotFound = NewStratumError(21, "Job not found (=stale)")
// StratumErrNeedAuthorized 需要认证
StratumErrNeedAuthorized = NewStratumError(24, "Unauthorized worker")
// StratumErrNeedSubscribed 需要订阅
StratumErrNeedSubscribed = NewStratumError(25, "Not subscribed")
// StratumErrIllegalParams 参数非法
StratumErrIllegalParams = NewStratumError(27, "Illegal params")
// StratumErrTooFewParams 参数太少
StratumErrTooFewParams = NewStratumError(27, "Too few params")
// StratumErrDuplicateSubscribed 重复订阅
StratumErrDuplicateSubscribed = NewStratumError(102, "Duplicate Subscribed")
// StratumErrWorkerNameMustBeString 矿工名必须是字符串
StratumErrWorkerNameMustBeString = NewStratumError(104, "Worker Name Must be a String")
// StratumErrSubAccountNameEmpty 子账户名为空
StratumErrSubAccountNameEmpty = NewStratumError(105, "Sub-account Name Cannot be Empty")
// StratumErrStratumServerNotFound 找不到对应币种的Stratum Server
StratumErrStratumServerNotFound = NewStratumError(301, "Stratum Server Not Found")
// StratumErrConnectStratumServerFailed 对应币种的Stratum Server连接失败
StratumErrConnectStratumServerFailed = NewStratumError(302, "Connect Stratum Server Failed")
// StratumErrUnknownChainType 未知区块链类型
StratumErrUnknownChainType = NewStratumError(500, "Unknown Chain Type")
)
var (
// ErrReadFailed IO读错误
ErrReadFailed = errors.New("read failed")
// ErrWriteFailed IO写错误
ErrWriteFailed = errors.New("write failed")
// ErrInvalidReader 非法Reader
ErrInvalidReader = errors.New("invalid reader")
// ErrInvalidWritter 非法Writter
ErrInvalidWritter = errors.New("invalid writter")
// ErrInvalidBuffer 非法Buffer
ErrInvalidBuffer = errors.New("invalid buffer")
// ErrConnectionClosed 连接已关闭
ErrConnectionClosed = errors.New("connection closed")
)