Use Merkle root hash in proof-of-work
This commit is contained in:
parent
668d209f5e
commit
8cafc0ef1e
10
block.go
10
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
|
||||
|
|
Loading…
Reference in New Issue