From ee28fb08f63d76c2a63a5cd10d9ed18aef47862c Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Wed, 25 Dec 2019 11:28:59 +0300 Subject: [PATCH] crypto: move merkle tree into the hash package It's all about hashes, so it makes sense putting it there. --- pkg/core/block.go | 6 +++--- pkg/crypto/{ => hash}/merkle_tree.go | 5 ++--- pkg/crypto/{ => hash}/merkle_tree_test.go | 2 +- 3 files changed, 6 insertions(+), 7 deletions(-) rename pkg/crypto/{ => hash}/merkle_tree.go (94%) rename pkg/crypto/{ => hash}/merkle_tree_test.go (98%) diff --git a/pkg/core/block.go b/pkg/core/block.go index 1561a3fa5..a7e2b4791 100644 --- a/pkg/core/block.go +++ b/pkg/core/block.go @@ -5,7 +5,7 @@ import ( "fmt" "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/util" "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)) for i, tx := range txes { hashes[i] = tx.Hash() } - return crypto.NewMerkleTree(hashes) + return hash.NewMerkleTree(hashes) } // rebuildMerkleRoot rebuilds the merkleroot of the block. diff --git a/pkg/crypto/merkle_tree.go b/pkg/crypto/hash/merkle_tree.go similarity index 94% rename from pkg/crypto/merkle_tree.go rename to pkg/crypto/hash/merkle_tree.go index b1d289806..6e980d0b1 100644 --- a/pkg/crypto/merkle_tree.go +++ b/pkg/crypto/hash/merkle_tree.go @@ -1,9 +1,8 @@ -package crypto +package hash import ( "errors" - "github.com/CityOfZion/neo-go/pkg/crypto/hash" "github.com/CityOfZion/neo-go/pkg/util" ) @@ -66,7 +65,7 @@ func buildMerkleTree(leaves []*MerkleTreeNode) (*MerkleTreeNode, error) { b1 := parents[i].leftChild.hash.BytesBE() b2 := parents[i].rightChild.hash.BytesBE() b1 = append(b1, b2...) - parents[i].hash = hash.DoubleSha256(b1) + parents[i].hash = DoubleSha256(b1) } return buildMerkleTree(parents) diff --git a/pkg/crypto/merkle_tree_test.go b/pkg/crypto/hash/merkle_tree_test.go similarity index 98% rename from pkg/crypto/merkle_tree_test.go rename to pkg/crypto/hash/merkle_tree_test.go index dbd65c03a..89bb573fc 100644 --- a/pkg/crypto/merkle_tree_test.go +++ b/pkg/crypto/hash/merkle_tree_test.go @@ -1,4 +1,4 @@ -package crypto +package hash import ( "testing"