Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: self
Browse files Browse the repository at this point in the history
Signed-off-by: Bryan White <[email protected]>
bryanchriswhite authored Jul 12, 2024
1 parent d329ba5 commit e3e6ed5
Showing 2 changed files with 7 additions and 3 deletions.
6 changes: 4 additions & 2 deletions root.go
Original file line number Diff line number Diff line change
@@ -36,7 +36,8 @@ func (r MerkleSumRoot) Sum() (uint64, error) {
}

// MustCount returns the uint64 count of the merkle root, a cryptographically secure
// count of the number of non-empty leafs in the tree.
// count of the number of non-empty leafs in the tree. It panics if the root hash length
// does not match that of the SMST hasher.
func (r MerkleSumRoot) MustCount() uint64 {
count, err := r.Count()
if err != nil {
@@ -47,7 +48,8 @@ func (r MerkleSumRoot) MustCount() uint64 {
}

// Count returns the uint64 count of the merkle root, a cryptographically secure
// count of the number of non-empty leafs in the tree.
// count of the number of non-empty leafs in the tree. It returns an error if the root hash length
// does not match that of the SMST hasher.
func (r MerkleSumRoot) Count() (uint64, error) {
if len(r) != SmstRootSizeBytes {
return 0, fmt.Errorf("MerkleSumRoot#Count: not a merkle sum trie")
4 changes: 3 additions & 1 deletion smst.go
Original file line number Diff line number Diff line change
@@ -186,7 +186,7 @@ func (smst *SMST) MustSum() uint64 {
}

// Sum returns the sum of the entire trie stored in the root.
// If the tree is not a sum tree, it will panic.
// If the tree is not a sum tree, it will return an error.
func (smst *SMST) Sum() (uint64, error) {
if !smst.Spec().sumTrie {
return 0, fmt.Errorf("SMST: not a merkle sum trie")
@@ -196,6 +196,7 @@ func (smst *SMST) Sum() (uint64, error) {
}

// MustCount returns the number of non-empty nodes in the entire trie stored in the root.
// If the tree is not a sum tree, it will panic.
func (smst *SMST) MustCount() uint64 {
count, err := smst.Count()
if err != nil {
@@ -205,6 +206,7 @@ func (smst *SMST) MustCount() uint64 {
}

// Count returns the number of non-empty nodes in the entire trie stored in the root.
// If the tree is not a sum tree, it will return an error.
func (smst *SMST) Count() (uint64, error) {
if !smst.Spec().sumTrie {
return 0, fmt.Errorf("SMST: not a merkle sum trie")

0 comments on commit e3e6ed5

Please sign in to comment.