From 8cafc0ef1ef5b14a835ae2278b58c99d5ba5b7c6 Mon Sep 17 00:00:00 2001 From: Ivan Kuznetsov Date: Mon, 18 Sep 2017 13:01:43 +0700 Subject: [PATCH] Use Merkle root hash in proof-of-work --- block.go | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/block.go b/block.go index b98c79c..65a0a6e 100644 --- a/block.go +++ b/block.go @@ -2,7 +2,6 @@ package main import ( "bytes" - "crypto/sha256" "encoding/gob" "log" "time" @@ -36,15 +35,14 @@ func NewGenesisBlock(coinbase *Transaction) *Block { // HashTransactions returns a hash of the transactions in the block func (b *Block) HashTransactions() []byte { - var txHashes [][]byte - var txHash [32]byte + var transactions [][]byte 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