Rename PrevBlock to PrevBlockHash for clarity

This commit is contained in:
Ivan Kuznetsov 2017-08-17 13:04:56 +07:00
parent 6fbf7ac6b4
commit 9104fae035
2 changed files with 6 additions and 6 deletions

View File

@ -11,14 +11,14 @@ import (
type Block struct {
Timestamp int64
Data []byte
PrevBlock []byte
PrevBlockHash []byte
Hash []byte
}
// SetHash calculates and sets block hash
func (b *Block) SetHash() {
timestamp := []byte(strconv.FormatInt(b.Timestamp, 10))
headers := bytes.Join([][]byte{b.PrevBlock, b.Data, timestamp}, []byte{})
headers := bytes.Join([][]byte{b.PrevBlockHash, b.Data, timestamp}, []byte{})
hash := sha256.Sum256(headers)
b.Hash = hash[:]

View File

@ -11,7 +11,7 @@ func main() {
bc.AddBlock("Send 2 more BTC to Ivan")
for _, block := range bc.blocks {
fmt.Printf("Prev. hash: %x\n", block.PrevBlock)
fmt.Printf("Prev. hash: %x\n", block.PrevBlockHash)
fmt.Printf("Data: %s\n", block.Data)
fmt.Printf("Hash: %x\n", block.Hash)
fmt.Println()