-
Notifications
You must be signed in to change notification settings - Fork 1
/
bft.go
66 lines (48 loc) · 951 Bytes
/
bft.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
package main
import "fmt"
type Node struct {
Name string
Status int
Votes []*Node
}
var nodes = make([]*Node, 0)
func createNodes() {
A := Node{"A", 1, make([]*Node, 0)}
B := Node{"B", 1, make([]*Node, 0)}
C := Node{"C", 1, make([]*Node, 0)}
D := Node{"D", 0, make([]*Node, 0)}
nodes = append(nodes, &A)
nodes = append(nodes, &B)
nodes = append(nodes, &C)
nodes = append(nodes, &D)
}
func votes() {
for i := 0; i < len(nodes); i++ {
node := nodes[i]
fmt.Println(node.Status)
for j := 0; j < len(nodes); j++ {
inode := nodes[j]
node.Votes = append(node.Votes, inode)
}
}
}
func isValid() bool {
node := nodes[len(nodes)-1]
votes := node.Votes
cnt := 0
for _, n := range votes {
fmt.Println(n.Status)
if n.Status == 0 {
cnt++
}
}
if float32(cnt) < float32(len(nodes))/float32(3.0) {
return true
}
return false
}
func main() {
createNodes()
votes()
fmt.Println(isValid())
}