github.com/koko1123/flow-go-1@v0.29.6/model/flow/entity.go (about)

     1  package flow
     2  
     3  // Entity defines how flow entities should be defined
     4  // Entities are flat data structures holding multiple data fields.
     5  // Entities don't include nested entities, they only include pointers to
     6  // other entities. For example, they keep a slice of entity commits instead
     7  // of keeping a slice of entity object itself. This simplifies storage, signature and validation
     8  // of entities.
     9  type Entity interface {
    10  
    11  	// ID returns a unique id for this entity using a hash of the immutable
    12  	// fields of the entity.
    13  	ID() Identifier
    14  
    15  	// Checksum returns a unique checksum for the entity, including the mutable
    16  	// data such as signatures.
    17  	Checksum() Identifier
    18  }
    19  
    20  // Proof contains proof that an entity is part of a EntityList
    21  type Proof []byte
    22  
    23  // EntityList is a list of entities of the same type
    24  type EntityList interface {
    25  	EntitySet
    26  
    27  	// HasIndex checks if the list has an entity at the given index.
    28  	HasIndex(i uint) bool
    29  
    30  	// ByIndex returns an entity from the list by index
    31  	ByIndex(i uint) (Entity, bool)
    32  
    33  	// ByIndexWithProof returns an entity from the list by index and proof of membership
    34  	ByIndexWithProof(i uint) (Entity, Proof, bool)
    35  }
    36  
    37  // EntitySet holds a set of entities (order doesn't matter)
    38  type EntitySet interface {
    39  
    40  	// Insert adds an entity to the data structure.
    41  	Insert(Entity) bool
    42  
    43  	// Remove removes an entity from the data structure.
    44  	Remove(Entity) bool
    45  
    46  	// Items returns all items of the collection.
    47  	Items() []Entity
    48  
    49  	// Size returns the number of entities in the data structure.
    50  	Size() uint
    51  
    52  	// Fingerprint returns a unique identifier for all entities of the data
    53  	// structure.
    54  	Fingerprint() Identifier
    55  
    56  	// ByID returns the entity with the given fingerprint.
    57  	ByID(id Identifier) (Entity, bool)
    58  
    59  	// if the set has an specific member providing proof of membership
    60  	ByIDWithProof(id Identifier) (bool, Proof, error)
    61  }