forked from cosmos/iavl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
doc.go
45 lines (45 loc) · 1.24 KB
/
doc.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// Basic usage of VersionedTree.
//
// import "github.com/tendermint/iavl"
// import "github.com/tendermint/tendermint/libs/db"
// ...
//
// tree := iavl.NewVersionedTree(db.NewMemDB(), 128)
//
// tree.IsEmpty() // true
//
// tree.Set([]byte("alice"), []byte("abc"))
// tree.SaveVersion(1)
//
// tree.Set([]byte("alice"), []byte("xyz"))
// tree.Set([]byte("bob"), []byte("xyz"))
// tree.SaveVersion(2)
//
// tree.LatestVersion() // 2
//
// tree.GetVersioned([]byte("alice"), 1) // "abc"
// tree.GetVersioned([]byte("alice"), 2) // "xyz"
//
// Proof of existence:
//
// root := tree.Hash()
// val, proof, err := tree.GetVersionedWithProof([]byte("bob"), 2) // "xyz", KeyProof, nil
// proof.Verify([]byte("bob"), val, root) // nil
//
// Proof of absence:
//
// _, proof, err = tree.GetVersionedWithProof([]byte("tom"), 2) // nil, KeyProof, nil
// proof.Verify([]byte("tom"), nil, root) // nil
//
// Now we delete an old version:
//
// tree.DeleteVersion(1)
// tree.VersionExists(1) // false
// tree.Get([]byte("alice")) // "xyz"
// tree.GetVersioned([]byte("alice"), 1) // nil
//
// Can't create a proof of absence for a version we no longer have:
//
// _, proof, err = tree.GetVersionedWithProof([]byte("tom"), 1) // nil, nil, error
//
package iavl