Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(examples): add merkle tree package #631

Merged
merged 7 commits into from
May 24, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
chore: optimize memory consumption
  • Loading branch information
albttx committed May 24, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 3235818d56532b05a2f9afd0d4a7f234c80a31cc
6 changes: 3 additions & 3 deletions examples/gno.land/p/demo/merkle/merkle.gno
Original file line number Diff line number Diff line change
@@ -50,7 +50,7 @@ func NewTree(data []Hashable) *Tree {
tree.layers = []nodes{nodes(leaves)}

for len(leaves) > 1 {
var level []Node
level := make([]Node, 0, len(leaves)/2+1)
for i := 0; i < len(leaves); i += 2 {
var buff bytes.Buffer

@@ -87,7 +87,7 @@ func (t *Tree) Proof(data Hashable) ([]Node, error) {
return nil, errors.New("target not found")
}

var proofs []Node
proofs := make([]Node, 0, len(t.layers))

for _, layer := range t.layers {
var pairIndex int
@@ -103,7 +103,7 @@ func (t *Tree) Proof(data Hashable) ([]Node, error) {
position: uint8(targetIndex) % 2,
})
}
targetIndex = int(math.Floor(float64(targetIndex) / 2))
targetIndex /= 2
}
return proofs, nil
}