From c8931089f5b735e518e0da144f691158ea9ec903 Mon Sep 17 00:00:00 2001 From: Daniel Olshansky Date: Thu, 11 Apr 2024 16:33:38 -0700 Subject: [PATCH] Enabled NewTrieSpec to accept options --- proofs.go | 2 +- types.go | 7 ++++++- utils.go | 4 ++-- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/proofs.go b/proofs.go index 6a09fe9..be33a8f 100644 --- a/proofs.go +++ b/proofs.go @@ -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, } diff --git a/types.go b/types.go index f860bba..61b0638 100644 --- a/types.go +++ b/types.go @@ -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 } diff --git a/utils.go b/utils.go index cc5bca8..64e98cb 100644 --- a/utils.go +++ b/utils.go @@ -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} }