-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
51 lines (39 loc) · 937 Bytes
/
main.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
package main
import (
"log"
"time"
"github.com/ElioenaiFerrari/8bits/lib/block"
"github.com/ElioenaiFerrari/8bits/lib/network"
"github.com/ElioenaiFerrari/8bits/lib/node"
)
func main() {
g := &block.Block{
Timestamp: time.Now().String(),
PrevHash: "",
ValidatorAddress: "",
}
g.Hash = g.Sum()
n := &network.Network{
Chain: []*block.Block{
g,
},
}
n.ChainHead = n.Chain[0]
n.Validators = n.AddNode(node.New(60))
n.Validators = n.AddNode(node.New(40))
for i := 0; i < 5; i++ {
w, err := n.GetWinner()
if err != nil {
log.Fatal(err)
}
w.Stake += 10
n.Chain, n.ChainHead, err = n.GenerateNewBlock(w)
if err != nil {
log.Fatal(err)
}
log.Println("Round ", i)
log.Println("\tAddress:", n.Validators[0].Address, "-Stake:", n.Validators[0].Stake)
log.Println("\tAddress:", n.Validators[1].Address, "-Stake:", n.Validators[1].Stake)
}
log.Printf("%+v", n.Chain)
}