-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmining.go
96 lines (77 loc) · 1.63 KB
/
mining.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
94
95
96
package Stratum
import (
"encoding/hex"
"errors"
"github.com/DanielKrawisz/go-work"
)
type WorkerName string
// Worker represents a miner who is doing work for the pool.
// This would be used in an implementation of a Stratum server and is
// not part of the Stratum protocol.
type Worker struct {
Name WorkerName
SessionID ID
ExtraNonce2Size uint32
VersionMask *uint32
}
// A share is the data returned by the worker in mining.submit.
type Share struct {
Name WorkerName
JobID ID
work.Share
}
func (p *Share) read(r *request) error {
if len(r.params) < 5 || len(r.params) > 6 {
return errors.New("Invalid format")
}
name, ok := r.params[0].(string)
if !ok {
return errors.New("Invalid format")
}
jobID, ok := r.params[1].(string)
if !ok {
return errors.New("Invalid format")
}
extraNonce2, ok := r.params[2].(string)
if !ok {
return errors.New("Invalid format")
}
time, ok := r.params[3].(string)
if !ok {
return errors.New("Invalid format")
}
nonce, ok := r.params[4].(string)
if !ok {
return errors.New("Invalid format")
}
if len(r.params) == 6 {
gpr, ok := r.params[5].(string)
if !ok {
return errors.New("Invalid format")
}
GPR, err := decodeLittleEndian(gpr)
if err != nil {
return err
}
p.GeneralPurposeBits = &GPR
}
var err error
p.Nonce, err = decodeBigEndian(nonce)
if err != nil {
return err
}
p.Time, err = decodeBigEndian(time)
if err != nil {
return err
}
p.ExtraNonce2, err = hex.DecodeString(extraNonce2)
if err != nil {
return err
}
p.JobID, err = decodeID(jobID)
if err != nil {
return err
}
p.Name = WorkerName(name)
return nil
}