blockchain_go/cli_printchain.go

31 lines
549 B
Go

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