hash: simplify merkle tree error handling

buildMerkleTree() is internal to the hash package and if anyone calls it with
`len(leaves) == 0` he deserves a panic. As it's the only error case in it, we
can remove error value return from this function and simplify NewMerkleTree().
This commit is contained in:
Roman Khimov 2019-12-25 14:38:48 +03:00
parent ee28fb08f6
commit ddad9ac9a3

View file

@ -25,13 +25,8 @@ func NewMerkleTree(hashes []util.Uint256) (*MerkleTree, error) {
}
}
root, err := buildMerkleTree(nodes)
if err != nil {
return nil, err
}
return &MerkleTree{
root: root,
root: buildMerkleTree(nodes),
depth: 1,
}, nil
}
@ -41,12 +36,12 @@ func (t *MerkleTree) Root() util.Uint256 {
return t.root.hash
}
func buildMerkleTree(leaves []*MerkleTreeNode) (*MerkleTreeNode, error) {
func buildMerkleTree(leaves []*MerkleTreeNode) *MerkleTreeNode {
if len(leaves) == 0 {
return nil, errors.New("length of the leaves cannot be zero")
panic("length of leaves cannot be zero")
}
if len(leaves) == 1 {
return leaves[0], nil
return leaves[0]
}
parents := make([]*MerkleTreeNode, (len(leaves)+1)/2)