-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnodeMiner.go
53 lines (46 loc) · 1.33 KB
/
nodeMiner.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
package main
import (
"bytes"
"fmt"
"net"
"strings"
)
func minerSendMsg(conn net.Conn, msg []byte) (reply []byte) {
_, err := conn.Write(msg)
if err != nil {
fmt.Println("Miner: Error writing:")
fmt.Println("Miner: ", err)
return
}
fmt.Println("Miner: ...sending message to nearby node")
buf := make([]byte, 8192)
_, err = conn.Read(buf)
if err != nil {
fmt.Println("Miner: ...Error Reading:")
fmt.Println("Miner: ...", err)
return
}
fmt.Println("Miner: ...received message from nearby node")
return bytes.TrimRight(buf, "\x00")
}
func minerGetData() []string {
var dataRaw string
var dataString []string
fmt.Println("Miner: Enter data to be packed in blockchain (seperated by ',')")
fmt.Scan(&dataRaw)
dataString = strings.Split(dataRaw, ",")
return dataString
}
func minerPrintBlock(block *Block) {
fmt.Printf("Miner: > TimeStamp : %d\n", block.Timestamp)
fmt.Printf("Miner: > PrevBlockHash : %x\n", block.PrevBlockHash)
fmt.Printf("Miner: > Merkle Root : %x\n", block.MerkleTreeRoot)
fmt.Printf("Miner: > Nonce : %d\n", block.Nonce)
fmt.Printf("Miner: > CurrBlockHash : %x\n", block.CurrentBlockHash)
if len(block.Data) > 0 {
fmt.Printf("Miner: > Data : %s\n", block.Data)
} else {
fmt.Printf("Miner: > Data : Not Disclose\n")
}
return
}