forked from hacash/miner
-
Notifications
You must be signed in to change notification settings - Fork 0
/
status.go
46 lines (39 loc) · 1.12 KB
/
status.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
package minerpool
import (
"bytes"
"fmt"
"github.com/hacash/core/fields"
)
const (
MinerPoolStatusSize = 4 * 12
)
type MinerPoolStatus struct {
FindBlockHashHeightTableLastestNumber fields.VarUint4 // Latest value of excavated block ID table
TransferHashTableLastestNumber fields.VarUint4 // Latest value of transfer serial number table
}
func NewEmptyMinerPoolStatus() *MinerPoolStatus {
return &MinerPoolStatus{
0, 0,
}
}
func (s *MinerPoolStatus) Serialize() ([]byte, error) {
buf := bytes.NewBuffer([]byte{})
b1, _ := s.FindBlockHashHeightTableLastestNumber.Serialize()
b2, _ := s.TransferHashTableLastestNumber.Serialize()
buf.Write(b1)
buf.Write(b2)
resbuf := make([]byte, MinerPoolStatusSize)
copy(resbuf, buf.Bytes())
return resbuf, nil
}
func (s *MinerPoolStatus) Parse(buf []byte, seek uint32) (uint32, error) {
if uint32(len(buf))-seek < 4+4 {
return 0, fmt.Errorf("size error.")
}
seek, _ = s.FindBlockHashHeightTableLastestNumber.Parse(buf, seek)
seek, _ = s.TransferHashTableLastestNumber.Parse(buf, seek)
return seek, nil
}
func (s *MinerPoolStatus) Size() uint32 {
return MinerPoolStatusSize
}