-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix!: UnmarshalJSON is limited to the default Tree bug (#277)
<!-- Please read and fill out this form before submitting your PR. Please make sure you have reviewed our contributors guide before submitting your first PR. --> ## Overview Closed: #275 <!-- Please provide an explanation of the PR, including the appropriate context, background, goal, and rationale. If there is an issue with this information, please provide a tl;dr and link the issue. --> ## Checklist <!-- Please complete the checklist to ensure that the PR is ready to be reviewed. IMPORTANT: PRs should be left in Draft until the below checklist is completed. --> - [x] New and updated code has appropriate documentation - [x] New and updated code has new and/or updated testing - [x] Required CI checks are passing - [ ] Visual proof for any user facing features like CLI or documentation updates - [x] Linked issues closed with keywords --------- Co-authored-by: Rootul P <[email protected]> Co-authored-by: Sanaz Taheri <[email protected]>
- Loading branch information
1 parent
7fcdfd1
commit bb5e119
Showing
6 changed files
with
410 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package rsmt2d | ||
|
||
import ( | ||
"crypto/sha256" | ||
"fmt" | ||
|
||
"github.com/celestiaorg/merkletree" | ||
) | ||
|
||
var DefaultTreeName = "default-tree" | ||
|
||
func init() { | ||
err := RegisterTree(DefaultTreeName, NewDefaultTree) | ||
if err != nil { | ||
panic(fmt.Sprintf("%s already registered", DefaultTreeName)) | ||
} | ||
} | ||
|
||
var _ Tree = &DefaultTree{} | ||
|
||
type DefaultTree struct { | ||
*merkletree.Tree | ||
leaves [][]byte | ||
root []byte | ||
} | ||
|
||
func NewDefaultTree(_ Axis, _ uint) Tree { | ||
return &DefaultTree{ | ||
Tree: merkletree.New(sha256.New()), | ||
leaves: make([][]byte, 0, 128), | ||
} | ||
} | ||
|
||
func (d *DefaultTree) Push(data []byte) error { | ||
// ignore the idx, as this implementation doesn't need that info | ||
d.leaves = append(d.leaves, data) | ||
return nil | ||
} | ||
|
||
func (d *DefaultTree) Root() ([]byte, error) { | ||
if d.root == nil { | ||
for _, l := range d.leaves { | ||
d.Tree.Push(l) | ||
} | ||
d.root = d.Tree.Root() | ||
} | ||
return d.root, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.