-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
64 lines (48 loc) · 2.04 KB
/
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
52
53
54
55
56
57
58
59
60
61
62
63
64
package main
import (
"fmt"
"math/rand"
"runtime"
"time"
"github.com/zohaibadnan137/assignment01bca"
"github.com/zohaibadnan137/assignment02bca"
)
func main() {
rand.Seed(time.Now().UnixNano())
fmt.Println("\nCreating two nodes...")
node_1 := assignment02bca.CreateNode("NODE_1")
network := assignment02bca.CreateNetwork("BLKC", &node_1)
_ = network
node_2 := assignment02bca.CreateNode("NODE_2")
node_2.JoinNetwork(assignment02bca.GetBootstrapData(0))
fmt.Println("\nDisplaying node data...")
node_1.DisplayNodeData()
node_2.DisplayNodeData()
go node_1.Run()
go node_2.Run()
fmt.Println("\nCreating a block with three transactions using NODE_2...")
var transactions [3]assignment01bca.Transaction
transactions[0] = assignment01bca.CreateTransaction("Zohaib", "Hussain", 10)
transactions[1] = assignment01bca.CreateTransaction("Zohaib", "Hussain", 15)
transactions[2] = assignment01bca.CreateTransaction("Zohaib", "Hussain", 15)
block := assignment01bca.NewBlock(node_2.GetBlockchain(), transactions[:])
go node_2.PropogateBlock(block)
fmt.Println("\nCreating two more nodes...")
node_3 := assignment02bca.CreateNode("NODE_3")
node_3.JoinNetwork(assignment02bca.GetBootstrapData(0))
node_4 := assignment02bca.CreateNode("NODE_4")
node_4.JoinNetwork(assignment02bca.GetBootstrapData(0))
fmt.Println("\nDisplaying node data...")
node_3.DisplayNodeData()
node_4.DisplayNodeData()
fmt.Println("\nCreating a block with five transactions using NODE_3...")
var transactions_2 [5]assignment01bca.Transaction
transactions_2[0] = assignment01bca.CreateTransaction("Zohaib", "Huzaifa", 10)
transactions_2[1] = assignment01bca.CreateTransaction("Zohaib", "Hussain", 15)
transactions_2[2] = assignment01bca.CreateTransaction("Zohaib", "Huzaifa", 25)
transactions_2[3] = assignment01bca.CreateTransaction("Zohaib", "Hussain", 30)
transactions_2[4] = assignment01bca.CreateTransaction("Zohaib", "Hussain", 50)
block_2 := assignment01bca.NewBlock(node_2.GetBlockchain(), transactions_2[:])
go node_3.PropogateBlock(block_2)
runtime.Goexit()
}