github.com/gnolang/gno@v0.0.0-20240520182011-228e9d0192ce/tm2/pkg/crypto/merkle/types.go (about)

     1  package merkle
     2  
     3  import (
     4  	"io"
     5  
     6  	amino "github.com/gnolang/gno/tm2/pkg/amino"
     7  )
     8  
     9  // Tree is a Merkle tree interface.
    10  type Tree interface {
    11  	Size() (size int)
    12  	Height() (height int8)
    13  	Has(key []byte) (has bool)
    14  	Proof(key []byte) (value []byte, proof []byte, exists bool) // TODO make it return an index
    15  	Get(key []byte) (index int, value []byte, exists bool)
    16  	GetByIndex(index int) (key []byte, value []byte)
    17  	Set(key []byte, value []byte) (updated bool)
    18  	Remove(key []byte) (value []byte, removed bool)
    19  	HashWithCount() (hash []byte, count int)
    20  	Hash() (hash []byte)
    21  	Save() (hash []byte)
    22  	Load(hash []byte)
    23  	Copy() Tree
    24  	Iterate(func(key []byte, value []byte) (stop bool)) (stopped bool)
    25  	IterateRange(start []byte, end []byte, ascending bool, fx func(key []byte, value []byte) (stop bool)) (stopped bool)
    26  }
    27  
    28  //-----------------------------------------------------------------------
    29  
    30  // Uvarint length prefixed byteslice
    31  func encodeByteSlice(w io.Writer, bz []byte) (err error) {
    32  	return amino.EncodeByteSlice(w, bz)
    33  }
    34  
    35  //----------------------------------------
    36  
    37  type ProofOp struct {
    38  	Type string `json:"type"`
    39  	Key  []byte `json:"key"`
    40  	Data []byte `json:"data"`
    41  }
    42  
    43  type Proof struct {
    44  	Ops []ProofOp `json:"ops"`
    45  }