Rename PrevBlock to PrevBlockHash for clarity
This commit is contained in:
parent
6fbf7ac6b4
commit
9104fae035
10
block.go
10
block.go
|
@ -9,16 +9,16 @@ import (
|
||||||
|
|
||||||
// Block keeps block headers
|
// Block keeps block headers
|
||||||
type Block struct {
|
type Block struct {
|
||||||
Timestamp int64
|
Timestamp int64
|
||||||
Data []byte
|
Data []byte
|
||||||
PrevBlock []byte
|
PrevBlockHash []byte
|
||||||
Hash []byte
|
Hash []byte
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetHash calculates and sets block hash
|
// SetHash calculates and sets block hash
|
||||||
func (b *Block) SetHash() {
|
func (b *Block) SetHash() {
|
||||||
timestamp := []byte(strconv.FormatInt(b.Timestamp, 10))
|
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)
|
hash := sha256.Sum256(headers)
|
||||||
|
|
||||||
b.Hash = hash[:]
|
b.Hash = hash[:]
|
||||||
|
|
2
main.go
2
main.go
|
@ -11,7 +11,7 @@ func main() {
|
||||||
bc.AddBlock("Send 2 more BTC to Ivan")
|
bc.AddBlock("Send 2 more BTC to Ivan")
|
||||||
|
|
||||||
for _, block := range bc.blocks {
|
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("Data: %s\n", block.Data)
|
||||||
fmt.Printf("Hash: %x\n", block.Hash)
|
fmt.Printf("Hash: %x\n", block.Hash)
|
||||||
fmt.Println()
|
fmt.Println()
|
||||||
|
|
Loading…
Reference in New Issue