You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

33 lines
1015 B

  1. package merkle
  2. import (
  3. "io"
  4. amino "github.com/tendermint/go-amino"
  5. )
  6. // Tree is a Merkle tree interface.
  7. type Tree interface {
  8. Size() (size int)
  9. Height() (height int8)
  10. Has(key []byte) (has bool)
  11. Proof(key []byte) (value []byte, proof []byte, exists bool) // TODO make it return an index
  12. Get(key []byte) (index int, value []byte, exists bool)
  13. GetByIndex(index int) (key []byte, value []byte)
  14. Set(key []byte, value []byte) (updated bool)
  15. Remove(key []byte) (value []byte, removed bool)
  16. HashWithCount() (hash []byte, count int)
  17. Hash() (hash []byte)
  18. Save() (hash []byte)
  19. Load(hash []byte)
  20. Copy() Tree
  21. Iterate(func(key []byte, value []byte) (stop bool)) (stopped bool)
  22. IterateRange(start []byte, end []byte, ascending bool, fx func(key []byte, value []byte) (stop bool)) (stopped bool)
  23. }
  24. //-----------------------------------------------------------------------
  25. // Uvarint length prefixed byteslice
  26. func encodeByteSlice(w io.Writer, bz []byte) (err error) {
  27. return amino.EncodeByteSlice(w, bz)
  28. }