Rename PrevBlock to PrevBlockHash for clarity
This commit is contained in:
parent
6fbf7ac6b4
commit
9104fae035
4
block.go
4
block.go
|
@ -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[:]
|
||||
|
|
2
main.go
2
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()
|
||||
|
|
Loading…
Reference in New Issue