Skip to content

Commit

Permalink
Merge pull request #82 from boecklim/fix/rm_build_merkle_tree_err
Browse files Browse the repository at this point in the history
remove unused returned error
  • Loading branch information
boecklim authored Dec 21, 2023
2 parents c3f817f + b916284 commit 4b39571
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 16 deletions.
15 changes: 5 additions & 10 deletions bump_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ func TestNewBUMPFromMerkleTreeWithOnlyOneTxid(t *testing.T) {
hash, err := chainhash.NewHashFromStr(txidSmallBlock)
require.NoError(t, err)
chainHashBlock = append(chainHashBlock, hash)
merkles, err := BuildMerkleTreeStoreChainHash(chainHashBlock)
require.NoError(t, err)
merkles := BuildMerkleTreeStoreChainHash(chainHashBlock)
bump, err := NewBUMPFromMerkleTreeAndIndex(fakeMadeUpNum, merkles, uint64(0))
require.NoError(t, err)
root, err := bump.CalculateRootGivenTxid(txidSmallBlock)
Expand All @@ -66,8 +65,7 @@ func TestNewBUMPFromMerkleTree(t *testing.T) {
require.NoError(t, err)
chainHashBlock = append(chainHashBlock, hash)
}
merkles, err := BuildMerkleTreeStoreChainHash(chainHashBlock)
require.NoError(t, err)
merkles := BuildMerkleTreeStoreChainHash(chainHashBlock)
for txIndex, txid := range blockTxExample {
bump, err := NewBUMPFromMerkleTreeAndIndex(fakeMadeUpNum, merkles, uint64(txIndex))
require.NoError(t, err)
Expand Down Expand Up @@ -108,8 +106,7 @@ func TestTestnetCalculateRootGivenTxid(t *testing.T) {
require.NoError(t, err)
chainHashBlock = append(chainHashBlock, hash)
}
merkles, err := BuildMerkleTreeStoreChainHash(chainHashBlock)
require.NoError(t, err)
merkles := BuildMerkleTreeStoreChainHash(chainHashBlock)
for txIndex, txid := range testnetBlockExample {
bump, err := NewBUMPFromMerkleTreeAndIndex(1575794, merkles, uint64(txIndex))
require.NoError(t, err)
Expand Down Expand Up @@ -161,8 +158,7 @@ func TestTxids(t *testing.T) {
require.NoError(t, err)
chainHashBlock = append(chainHashBlock, hash)
}
merkles, err := BuildMerkleTreeStoreChainHash(chainHashBlock)
require.NoError(t, err)
merkles := BuildMerkleTreeStoreChainHash(chainHashBlock)

bump, err := NewBUMPFromMerkleTreeAndIndex(1575794, merkles, uint64(0))
require.NoError(t, err)
Expand All @@ -177,8 +173,7 @@ func TestOnlySpecifiedPathsStored(t *testing.T) {
require.NoError(t, err)
chainHashBlock = append(chainHashBlock, hash)
}
merkles, err := BuildMerkleTreeStoreChainHash(chainHashBlock)
require.NoError(t, err)
merkles := BuildMerkleTreeStoreChainHash(chainHashBlock)

for idx := range blockTxExample {
bump, err := NewBUMPFromMerkleTreeAndIndex(1575794, merkles, uint64(idx))
Expand Down
4 changes: 2 additions & 2 deletions merkleroot.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ func BuildMerkleTreeStore(txids []string) ([]string, error) {
}

// BuildMerkleTreeStoreChainHash has the same functionality as BuildMerkleTreeStore but uses chainhash as a type to avoid string conversions.
func BuildMerkleTreeStoreChainHash(txids []*chainhash.Hash) ([]*chainhash.Hash, error) {
func BuildMerkleTreeStoreChainHash(txids []*chainhash.Hash) []*chainhash.Hash {
// // Calculate how many entries are re?n array of that size.
nextPoT := nextPowerOfTwo(len(txids))
arraySize := nextPoT*2 - 1
Expand Down Expand Up @@ -161,7 +161,7 @@ func BuildMerkleTreeStoreChainHash(txids []*chainhash.Hash) ([]*chainhash.Hash,
offset++
}

return merkles, nil
return merkles
}

// nextPowerOfTwo returns the next highest power of two from a given number if
Expand Down
6 changes: 2 additions & 4 deletions merkleroot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,7 @@ func TestBuildMerkleTreeStoreChainHash(t *testing.T) {
transactionHashes[i], _ = chainhash.NewHashFromStr(txid)
}

merkleTreeChainStore, err := bc.BuildMerkleTreeStoreChainHash(transactionHashes)
require.NoError(t, err)
merkleTreeChainStore := bc.BuildMerkleTreeStoreChainHash(transactionHashes)

actual := merkleTreeChainStore[len(merkleTreeChainStore)-1].String()

Expand Down Expand Up @@ -114,8 +113,7 @@ func TestBuildMerkleTreeStoreChainHashDifferentSizes(t *testing.T) {
transactionHashes[idx] = h
}

merkleTreeChainStore, err := bc.BuildMerkleTreeStoreChainHash(transactionHashes)
require.NoError(t, err)
merkleTreeChainStore := bc.BuildMerkleTreeStoreChainHash(transactionHashes)

actual := merkleTreeChainStore[len(merkleTreeChainStore)-1].String()

Expand Down

0 comments on commit 4b39571

Please sign in to comment.