/
types.go
67 lines (51 loc) · 1.74 KB
/
types.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
package chainduobftpb
import (
"crypto/sha512"
fmt "fmt"
proto "github.com/gogo/protobuf/proto"
)
type Height uint64
type View uint64
type BlockHash [sha512.Size]byte
type BlockHashSlice []byte
func (bh BlockHash) Slice() []byte {
return bh[:]
}
func (bh BlockHash) String() string {
return fmt.Sprintf("%.4x", bh.Slice())
}
func (bhs BlockHashSlice) Array() [sha512.Size]byte {
return *(*[sha512.Size]byte)(bhs)
}
func (sig *Signature) String() string {
return fmt.Sprintf("<Counter: %d, Signer: %d>", sig.Counter, sig.Signer)
}
func (qc *QuorumCert) String() string {
return fmt.Sprintf("BlockHash: %.4x, Height: %d, Signature: %v", qc.BlockHash, qc.Height, qc.Sigs)
}
func (fs *FastChainState) String() string {
var cmd string
if fs.Command != nil {
cmd = string(fs.Command.ConflictKey)
}
return fmt.Sprintf("Height: %d, Parent: %.4x, QC: <<%v>>, Command: %v", fs.Height, fs.Parent, fs.QC, cmd)
}
func (ss *SlowChainState) String() string {
return fmt.Sprintf("Height: %d, Parent: %.4x, QC: <<%v>>, ProposeBlockHash: %.4x, ProposeBlockHeight: %d, SelfPropose: %v", ss.Height, ss.Parent, ss.QC, ss.ProposeBlockHash, ss.ProposeBlockHeight, ss.SelfPropose)
}
func (bs *BlockState) String() string {
return fmt.Sprintf("View: %d, FastState: <<%v>>, SlowState: <<%v>>", bs.View, bs.FastState, bs.SlowState)
}
func WrapMessageInner(msg proto.Message) isChainDuoBFTMessage_Type {
switch t := msg.(type) {
case *ProposeMessage:
return &ChainDuoBFTMessage_Propose{Propose: t}
case *VoteMessage:
return &ChainDuoBFTMessage_Vote{Vote: t}
default:
panic(fmt.Sprintf("proto: unexpected type %T in WrapMessageInner", t))
}
}
func WrapChainDuoBFTMessage(msg proto.Message) *ChainDuoBFTMessage {
return &ChainDuoBFTMessage{Type: WrapMessageInner(msg)}
}