-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathextensions.go
47 lines (41 loc) · 930 Bytes
/
extensions.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
package Stratum
import (
"errors"
)
// https://github.com/slushpool/stratumprotocol/blob/master/stratum-extensions.mediawiki
type Extension uint8
const (
Unknown = iota
VersionRolling
MinimumDifficulty
SubscribeExtranonce
Info
)
func EncodeExtension(m Extension) (string, error) {
switch m {
case VersionRolling:
return "version_rolling", nil
case MinimumDifficulty:
return "minimum_difficulty", nil
case SubscribeExtranonce:
return "subscribe_extranonce", nil
case Info:
return "info", nil
default:
return "", errors.New("Unkown Stratum extension")
}
}
func DecodeExtension(m string) (Extension, error) {
switch m {
case "version_rolling":
return VersionRolling, nil
case "minimum_difficulty":
return MinimumDifficulty, nil
case "subscribe_extranonce":
return SubscribeExtranonce, nil
case "info":
return Info, nil
default:
return Unknown, errors.New("Unkown Stratum extension")
}
}