forked from hacash/miner
-
Notifications
You must be signed in to change notification settings - Fork 0
/
msg_reportMiningResult.go
55 lines (46 loc) · 1.09 KB
/
msg_reportMiningResult.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
package message
import (
"bytes"
"github.com/hacash/core/fields"
)
/**
向上通报挖矿的结果
*/
type MsgReportMiningResult struct {
MintSuccessed fields.Bool // Mining success or reporting computing power
BlockHeight fields.BlockHeight // Excavated block height
HeadNonce fields.Bytes4 // block head nonce
CoinbaseNonce fields.Bytes32 // coinbase nonce
}
// serialize
func (m MsgReportMiningResult) Serialize() []byte {
buf := bytes.NewBuffer([]byte{})
b1, _ := m.MintSuccessed.Serialize()
bhbts, _ := m.BlockHeight.Serialize()
buf.Write(b1)
buf.Write(bhbts)
buf.Write(m.HeadNonce)
buf.Write(m.CoinbaseNonce)
return buf.Bytes()
}
// Deserialization
func (m *MsgReportMiningResult) Parse(buf []byte, seek uint32) (uint32, error) {
var e error = nil
seek, e = m.MintSuccessed.Parse(buf, seek)
if e != nil {
return 0, e
}
seek, e = m.BlockHeight.Parse(buf, seek)
if e != nil {
return 0, e
}
seek, e = m.HeadNonce.Parse(buf, seek)
if e != nil {
return 0, e
}
seek, e = m.CoinbaseNonce.Parse(buf, seek)
if e != nil {
return 0, e
}
return seek, nil
}