Skip to content

Commit

Permalink
chore: new GetLatestVersion api (#961)
Browse files Browse the repository at this point in the history
  • Loading branch information
cool-develope authored Jul 9, 2024
1 parent 0b6f1b6 commit a514883
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

### Improvements

- [#961](https://github.com/cosmos/iavl/pull/961) Add new `GetLatestVersion` API to get the latest version.

## v1.2.0 May 13, 2024

### Improvements
Expand Down
5 changes: 5 additions & 0 deletions mutable_tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ func (tree *MutableTree) IsEmpty() bool {
return tree.ImmutableTree.Size() == 0
}

// GetLatestVersion returns the latest version of the tree.
func (tree *MutableTree) GetLatestVersion() (int64, error) {
return tree.ndb.getLatestVersion()
}

// VersionExists returns whether or not a version exists.
func (tree *MutableTree) VersionExists(version int64) bool {
legacyLatestVersion, err := tree.ndb.getLegacyLatestVersion()
Expand Down
6 changes: 5 additions & 1 deletion mutable_tree_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -347,11 +347,15 @@ func prepareTree(t *testing.T) *MutableTree {
return newTree
}

func TestMutableTree_VersionExists(t *testing.T) {
func TestMutableTree_Version(t *testing.T) {
tree := prepareTree(t)
require.True(t, tree.VersionExists(1))
require.True(t, tree.VersionExists(2))
require.False(t, tree.VersionExists(3))

v, err := tree.GetLatestVersion()
require.NoError(t, err)
require.Equal(t, int64(2), v)
}

func checkGetVersioned(t *testing.T, tree *MutableTree, version int64, key, value []byte) {
Expand Down

0 comments on commit a514883

Please sign in to comment.