blockchain_go/cli_printchain.go

32 lines
592 B
Go
Raw Normal View History

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()
2017-09-10 02:31:01 -05:00
fmt.Printf("============ Block %x ============\n", block.Hash)
fmt.Printf("Height: %d\n", block.Height)
2017-09-10 02:31:01 -05:00
fmt.Printf("Prev. block: %x\n", block.PrevBlockHash)
pow := NewProofOfWork(block)
2017-09-10 02:31:01 -05:00
fmt.Printf("PoW: %s\n\n", strconv.FormatBool(pow.Validate()))
for _, tx := range block.Transactions {
fmt.Println(tx)
}
2017-09-10 02:31:01 -05:00
fmt.Printf("\n\n")
if len(block.PrevBlockHash) == 0 {
break
}
}
}