chain.AddBlock("First Block after Genesis") chain.AddBlock("Second Block after Genesis") chain.AddBlock("Third Block after Genesis")
for _, block := range chain.Blocks { fmt.Printf("Previous Hash: %x\n", block.PrevHash) fmt.Printf("Data in Block: %s\n", block.Data) fmt.Printf("Hash: %x\n", block.Hash) } }
執行程式。
1
go run main.go
顯示結果如下:
1 2 3 4 5 6 7 8 9 10 11 12
Previous Hash: Data in Block: Genesis Hash: 81ddc8d248b2dccdd3fdd5e84f0cad62b08f2d10b57f9a831c13451e5c5c80a5 Previous Hash: 81ddc8d248b2dccdd3fdd5e84f0cad62b08f2d10b57f9a831c13451e5c5c80a5 Data in Block: First Block after Genesis Hash: 50493b76a2b7bec8d33620d6310d5578b1dda079684405ed5e6bd55510146daf Previous Hash: 50493b76a2b7bec8d33620d6310d5578b1dda079684405ed5e6bd55510146daf Data in Block: Second Block after Genesis Hash: 213e91a4ae1be45a651695ede0e75cba50818dce027dd4f0fe35742dc90158e1 Previous Hash: 213e91a4ae1be45a651695ede0e75cba50818dce027dd4f0fe35742dc90158e1 Data in Block: Third Block after Genesis Hash: e22b76962d23ed3e327b9ababac19270b56c4d70d8878446609b13fa72ebc0e1