forked from dreamerjackson/BuildingBlockChain
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli_printChain.go
More file actions
32 lines (26 loc) · 765 Bytes
/
cli_printChain.go
File metadata and controls
32 lines (26 loc) · 765 Bytes
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
package main
import (
"fmt"
"strconv"
)
func (cli *CLI) printChain(nodeID string) {
bc := NewBlockchain(nodeID)
defer bc.db.Close()
bci := bc.Iterator()
for {
block := bci.Next()
fmt.Printf("Prev. version: %s\n", strconv.FormatInt(block.Version,10))
fmt.Printf("Prev. hash: %x\n",block.PrevBlockHash)
fmt.Printf("merkleroot: %s\n", block.MerkleRoot)
fmt.Printf("time: %s\n", strconv.FormatInt(block.Timestamp,10))
fmt.Printf("nbits: %s\n", strconv.FormatInt(block.Nbits,10))
fmt.Printf("nonce: %s\n", strconv.FormatInt(block.Nonce,10))
fmt.Printf("Hash: %x\n", block.Hash)
pow := NewProofOfWork(block)
fmt.Printf("PoW: %s\n", strconv.FormatBool(pow.Validate()))
fmt.Println()
if len(block.PrevBlockHash) == 0 {
break
}
}
}