-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.go
executable file
·67 lines (58 loc) · 1.57 KB
/
init.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 main
import (
"fmt"
"goBlockchain/p2p/handlers"
"goBlockchain/blockchain"
"goBlockchain/webserver"
"log"
"time"
)
//CalculateHash hashes the values of a TestContent
func main() {
//nodeHash := utility.Hash("MainNodeId1")
//nodeKey := security.GenerateKey(nodeHash)
//tx1 := transactions.Tx(nodeKey, "Tomer", 1, "mm")
//tx2 := transactions.Tx(nodeKey, "Yaki", 1, "mm")
//tx3 := transactions.Tx(nodeKey, "Koko", 1, "mm")
//tx4 := transactions.Tx(nodeKey, "Momo", 1, "mm")
//
//sign1 := security.Sign(tx1.GetHash(), nodeHash)
//sign2 := security.Sign(tx2.GetHash(), nodeHash)
//sign3 := security.Sign(tx3.GetHash(), nodeHash)
//sign4 := security.Sign(tx4.GetHash(), nodeHash)
//
//valid1 := security.VerifySignature(sign1, tx1.GetHash(), nodeKey)
//valid2 := security.VerifySignature(sign2, tx2.GetHash(), nodeKey)
//valid3 := security.VerifySignature(sign3, tx3.GetHash(), nodeKey)
//valid4 := security.VerifySignature(sign4, tx4.GetHash(), nodeKey)
//
//fmt.Println(valid1)
//fmt.Println(valid2)
//fmt.Println(valid3)
//fmt.Println(valid4)
//bc := blockchain.GetInstance()
//
//bc.AddTransaction(tx1, sign1)
//bc.AddTransaction(tx2, sign2)
//bc.AddTransaction(tx3, sign3)
//bc.AddTransaction(tx4, sign4)
//////////
//bc.MineNextBlock()
//
//fmt.Println(bc.GetLastBlock())
//
go Runner()
go handlers.StartServer()
//
go log.Fatal(webserver.Run())
}
func Runner() {
bc := blockchain.GetInstance()
for {
time.Sleep(4 * time.Second)
if len(bc.GetPendingTransactions()) > 0 {
fmt.Printf("Mining new Block......\n")
bc.MineNextBlock()
}
}
}