Skip to content

Commit

Permalink
doc: aligns the nmt API doc with the current implementation (#215)
Browse files Browse the repository at this point in the history
  • Loading branch information
staheri14 authored Jun 28, 2023
1 parent 9f0f36e commit 48b8f96
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@ func main() {
}
}
// compute the root
root := tree.Root()
root, err := tree.Root()
if err != nil {
panic(fmt.Sprintf("unexpected error: %v", err))
}
// the root's min/max namespace is the min and max namespace of all leaves:
minNS := nmt.MinNamespace(root, tree.NamespaceSize())
maxNS := nmt.MaxNamespace(root, tree.NamespaceSize())
Expand Down
21 changes: 11 additions & 10 deletions docs/nmt-lib.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,22 +67,22 @@ func (n *NamespacedMerkleTree) Push(namespacedData namespace.PrefixedData) error
E.g.,

```go
d := append(namespace.ID{0}, []byte("leaf_0")...) // the first `tree.NamespaceSize()` bytes of each data item is treated as its namespace ID.
d := namespace.PrefixedData(append(namespace.ID{0}, []byte("leaf_0")...)) // the first `tree.NamespaceSize()` bytes of each data item is treated as its namespace.
if err := tree.Push(d); err != nil {
// something went wrong
// something went wrong
}
// add a few more data items
d1 := append(namespace.ID{0}, []byte("leaf_1")...)
d1 := namespace.PrefixedData(append(namespace.ID{0}, []byte("leaf_1")...))
if err := tree.Push(d1); err != nil {
// something went wrong
// something went wrong
}
d2 := append(namespace.ID{1}, []byte("leaf_2")...)
d2 := namespace.PrefixedData(append(namespace.ID{1}, []byte("leaf_2")...))
if err := tree.Push(d2); err != nil {
// something went wrong
// something went wrong
}
d3 := append(namespace.ID{3}, []byte("leaf_3")...)
d3 := namespace.PrefixedData(append(namespace.ID{3}, []byte("leaf_3")...))
if err := tree.Push(d3); err != nil {
// something went wrong
// something went wrong
}
```

Expand Down Expand Up @@ -116,16 +116,17 @@ Figure 1.
## Get Root

The `Root()` method calculates the NMT root based on the data that has been added through the use of the `Push` method.
The root value is valid if the method does not return an error.

```go
func (n *NamespacedMerkleTree) Root() []byte
func (n *NamespacedMerkleTree) Root() ([]byte, error)
```

For example:

```go
// compute the root
root := tree.Root()
root, err := tree.Root()
```

In the provided code example, the root would be `00 03 b1c2cc5` (as also illustrated in Figure 1).
Expand Down

0 comments on commit 48b8f96

Please sign in to comment.