Skip to content

Commit

Permalink
Change which methods are exported and document exported methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Manav-Aggarwal committed Oct 28, 2022
1 parent c2b64fe commit e5b57bc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
12 changes: 8 additions & 4 deletions deepsubtree.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,17 @@ type DSTNonExistenceProof struct {
rightSiblingProof *ics23.ExistenceProof
}

func convertToDSTNonExistenceProof(
// Constructs a DSTNonExistenceProof using an ICS23 Non-Existence proof
// and sibling node proofs. Returns the constructed DSTNonExistenceProof.
func ConvertToDSTNonExistenceProof(
tree *MutableTree,
nonExistenceProof *ics23.NonExistenceProof,
) (*DSTNonExistenceProof, error) {
dstNonExistenceProof := DSTNonExistenceProof{
NonExistenceProof: nonExistenceProof,
}
if nonExistenceProof.Left != nil {
leftSibling, err := tree.GetSiblingNode(nonExistenceProof.Left.Key)
leftSibling, err := tree.getSiblingNode(nonExistenceProof.Left.Key)
if err != nil {
return nil, err
}
Expand All @@ -40,7 +42,7 @@ func convertToDSTNonExistenceProof(
}
}
if nonExistenceProof.Right != nil {
rightSibling, err := tree.GetSiblingNode(nonExistenceProof.Right.Key)
rightSibling, err := tree.getSiblingNode(nonExistenceProof.Right.Key)
if err != nil {
return nil, err
}
Expand All @@ -52,14 +54,16 @@ func convertToDSTNonExistenceProof(
return &dstNonExistenceProof, nil
}

func (tree *ImmutableTree) GetSiblingNode(key []byte) (*Node, error) {
// Returns the sibling node of a leaf node with given key
func (tree *ImmutableTree) getSiblingNode(key []byte) (*Node, error) {
siblingNode, err := tree.recursiveGetSiblingNode(tree.root, key)
if err != nil {
return nil, err
}
return siblingNode, nil
}

// Recursively iterates the tree to return the sibling node of a leaf node with given key
func (tree *ImmutableTree) recursiveGetSiblingNode(node *Node, key []byte) (*Node, error) {
if node == nil || node.isLeaf() {
return nil, nil
Expand Down
2 changes: 1 addition & 1 deletion deepsubtree_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ func TestDeepSubtreeWWithAddsAndDeletes(t *testing.T) {
for _, keyToAdd := range keysToAdd {
ics23proof, err := tree.GetNonMembershipProof(keyToAdd)
require.NoError(err)
dst_nonExistenceProof, err := convertToDSTNonExistenceProof(tree, ics23proof.GetNonexist())
dst_nonExistenceProof, err := ConvertToDSTNonExistenceProof(tree, ics23proof.GetNonexist())
require.NoError(err)
dst.AddNonExistenceProof(dst_nonExistenceProof)
require.NoError(err)
Expand Down

0 comments on commit e5b57bc

Please sign in to comment.