Use Merkle root hash in proof-of-work

This commit is contained in:
Ivan Kuznetsov 2017-09-18 13:01:43 +07:00
parent 668d209f5e
commit 8cafc0ef1e
1 changed files with 4 additions and 6 deletions

View File

@ -2,7 +2,6 @@ package main
import ( import (
"bytes" "bytes"
"crypto/sha256"
"encoding/gob" "encoding/gob"
"log" "log"
"time" "time"
@ -36,15 +35,14 @@ func NewGenesisBlock(coinbase *Transaction) *Block {
// HashTransactions returns a hash of the transactions in the block // HashTransactions returns a hash of the transactions in the block
func (b *Block) HashTransactions() []byte { func (b *Block) HashTransactions() []byte {
var txHashes [][]byte var transactions [][]byte
var txHash [32]byte
for _, tx := range b.Transactions { for _, tx := range b.Transactions {
txHashes = append(txHashes, tx.Hash()) transactions = append(transactions, tx.Serialize())
} }
txHash = sha256.Sum256(bytes.Join(txHashes, []byte{})) mTree := NewMerkleTree(transactions)
return txHash[:] return mTree.RootNode.Data
} }
// Serialize serializes the block // Serialize serializes the block