Skip to content

Commit

Permalink
Enabled NewTrieSpec to accept options
Browse files Browse the repository at this point in the history
  • Loading branch information
Olshansk committed Apr 11, 2024
1 parent de3749f commit c893108
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion proofs.go
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ func VerifyClosestProof(proof *SparseMerkleClosestProof, root []byte, spec *Trie
// will invalidate the proof.
nilSpec := &TrieSpec{
th: spec.th,
ph: newNilPathHasher(spec.ph.PathSize()),
ph: NewNilPathHasher(spec.ph.PathSize()),
vh: spec.vh,
sumTrie: spec.sumTrie,
}
Expand Down
7 changes: 6 additions & 1 deletion types.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,16 @@ type TrieSpec struct {
sumTrie bool
}

func NewTrieSpec(hasher hash.Hash, sumTrie bool) TrieSpec {
func NewTrieSpec(hasher hash.Hash, sumTrie bool, opts ...Option) TrieSpec {
spec := TrieSpec{th: *newTrieHasher(hasher)}
spec.ph = &pathHasher{spec.th}
spec.vh = &valueHasher{spec.th}
spec.sumTrie = sumTrie

for _, opt := range opts {
opt(&spec)
}

return spec
}

Expand Down
4 changes: 2 additions & 2 deletions utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ type nilPathHasher struct {

func (n *nilPathHasher) Path(key []byte) []byte { return key[:n.hashSize] }
func (n *nilPathHasher) PathSize() int { return n.hashSize }

func newNilPathHasher(hashSize int) PathHasher {
func NewNilPathHasher(hashSize int) PathHasher {
return &nilPathHasher{hashSize: hashSize}
}

Expand Down

0 comments on commit c893108

Please sign in to comment.