diff --git a/block.go b/block.go index b635d92..a172b0b 100644 --- a/block.go +++ b/block.go @@ -9,16 +9,16 @@ import ( // Block keeps block headers type Block struct { - Timestamp int64 - Data []byte - PrevBlock []byte - Hash []byte + Timestamp int64 + Data []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[:] diff --git a/main.go b/main.go index 3232451..68e4642 100644 --- a/main.go +++ b/main.go @@ -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()