crypto: move merkle tree into the hash package

It's all about hashes, so it makes sense putting it there.
This commit is contained in:
Roman Khimov 2019-12-25 11:28:59 +03:00
parent db5555bb15
commit ee28fb08f6
3 changed files with 6 additions and 7 deletions

View file

@ -5,7 +5,7 @@ import (
"fmt" "fmt"
"github.com/CityOfZion/neo-go/pkg/core/transaction" "github.com/CityOfZion/neo-go/pkg/core/transaction"
"github.com/CityOfZion/neo-go/pkg/crypto" "github.com/CityOfZion/neo-go/pkg/crypto/hash"
"github.com/CityOfZion/neo-go/pkg/io" "github.com/CityOfZion/neo-go/pkg/io"
"github.com/CityOfZion/neo-go/pkg/util" "github.com/CityOfZion/neo-go/pkg/util"
"github.com/Workiva/go-datastructures/queue" "github.com/Workiva/go-datastructures/queue"
@ -30,13 +30,13 @@ func (b *Block) Header() *Header {
} }
} }
func merkleTreeFromTransactions(txes []*transaction.Transaction) (*crypto.MerkleTree, error) { func merkleTreeFromTransactions(txes []*transaction.Transaction) (*hash.MerkleTree, error) {
hashes := make([]util.Uint256, len(txes)) hashes := make([]util.Uint256, len(txes))
for i, tx := range txes { for i, tx := range txes {
hashes[i] = tx.Hash() hashes[i] = tx.Hash()
} }
return crypto.NewMerkleTree(hashes) return hash.NewMerkleTree(hashes)
} }
// rebuildMerkleRoot rebuilds the merkleroot of the block. // rebuildMerkleRoot rebuilds the merkleroot of the block.

View file

@ -1,9 +1,8 @@
package crypto package hash
import ( import (
"errors" "errors"
"github.com/CityOfZion/neo-go/pkg/crypto/hash"
"github.com/CityOfZion/neo-go/pkg/util" "github.com/CityOfZion/neo-go/pkg/util"
) )
@ -66,7 +65,7 @@ func buildMerkleTree(leaves []*MerkleTreeNode) (*MerkleTreeNode, error) {
b1 := parents[i].leftChild.hash.BytesBE() b1 := parents[i].leftChild.hash.BytesBE()
b2 := parents[i].rightChild.hash.BytesBE() b2 := parents[i].rightChild.hash.BytesBE()
b1 = append(b1, b2...) b1 = append(b1, b2...)
parents[i].hash = hash.DoubleSha256(b1) parents[i].hash = DoubleSha256(b1)
} }
return buildMerkleTree(parents) return buildMerkleTree(parents)

View file

@ -1,4 +1,4 @@
package crypto package hash
import ( import (
"testing" "testing"