Documentation ¶
Index ¶
- Constants
- Variables
- type IndexedMap
- func (i IndexedMap[PK, V, PV, I]) Delete(ctx sdk.Context, key PK) error
- func (i IndexedMap[PK, V, PV, I]) Get(ctx sdk.Context, key PK) (V, error)
- func (i IndexedMap[PK, V, PV, I]) GetOr(ctx sdk.Context, key PK, def V) V
- func (i IndexedMap[PK, V, PV, I]) Insert(ctx sdk.Context, key PK, v V)
- func (i IndexedMap[PK, V, PV, I]) Iterate(ctx sdk.Context, rng keys.Range[PK]) MapIterator[PK, V, PV]
- type Indexer
- type IndexerIterator
- func (i IndexerIterator[IK, PK]) Close()
- func (i IndexerIterator[IK, PK]) FullKey() keys.Pair[IK, PK]
- func (i IndexerIterator[IK, PK]) FullKeys() []keys.Pair[IK, PK]
- func (i IndexerIterator[IK, PK]) Next()
- func (i IndexerIterator[IK, PK]) PrimaryKey() PK
- func (i IndexerIterator[IK, PK]) PrimaryKeys() []PK
- func (i IndexerIterator[IK, PK]) Valid() bool
- type IndexersProvider
- type Item
- type KeySet
- type KeySetIterator
- type KeyValue
- type Map
- func (m Map[K, V, PV]) Delete(ctx sdk.Context, key K) error
- func (m Map[K, V, PV]) Get(ctx sdk.Context, key K) (V, error)
- func (m Map[K, V, PV]) GetOr(ctx sdk.Context, key K, def V) V
- func (m Map[K, V, PV]) Insert(ctx sdk.Context, key K, object V)
- func (m Map[K, V, PV]) Iterate(ctx sdk.Context, r keys.Range[K]) MapIterator[K, V, PV]
- type MapIterator
- func (i MapIterator[K, V, PV]) Close()
- func (i MapIterator[K, V, PV]) Key() K
- func (i MapIterator[K, V, PV]) KeyValues() []KeyValue[K, V, PV]
- func (i MapIterator[K, V, PV]) Keys() []K
- func (i MapIterator[K, V, PV]) Next()
- func (i MapIterator[K, V, PV]) Valid() bool
- func (i MapIterator[K, V, PV]) Value() V
- func (i MapIterator[K, V, PV]) Values() []V
- type MultiIndex
- func (i MultiIndex[IK, PK, V]) Delete(ctx sdk.Context, pk PK, v V)
- func (i MultiIndex[IK, PK, V]) ExactMatch(ctx sdk.Context, ik IK) IndexerIterator[IK, PK]
- func (i MultiIndex[IK, PK, V]) Insert(ctx sdk.Context, pk PK, v V)
- func (i MultiIndex[IK, PK, V]) Iterate(ctx sdk.Context, rng keys.Range[keys.Pair[IK, PK]]) IndexerIterator[IK, PK]
- func (i MultiIndex[IK, PK, V]) ReverseExactMatch(ctx sdk.Context, ik IK) IndexerIterator[IK, PK]
- type Object
- type Sequence
Constants ¶
const DefaultSequenceStart uint64 = 1
DefaultSequenceStart is the initial starting number of the Sequence.
Variables ¶
var ErrNotFound = errors.New("collections: not found")
Functions ¶
This section is empty.
Types ¶
type IndexedMap ¶
type IndexedMap[PK keys.Key, V any, PV interface { *V Object }, I IndexersProvider[PK, V]] struct { Indexes I // struct that groups together Indexer instances, implements IndexersProvider // contains filtered or unexported fields }
IndexedMap defines a map which is indexed using the IndexersProvider PK defines the primary key of the object V.
func NewIndexedMap ¶
func NewIndexedMap[PK keys.Key, V any, PV interface { *V Object }, I IndexersProvider[PK, V]](cdc codec.BinaryCodec, storeKey sdk.StoreKey, namespace uint8, indexers I) IndexedMap[PK, V, PV, I]
NewIndexedMap instantiates a new IndexedMap instance.
func (IndexedMap[PK, V, PV, I]) Delete ¶
func (i IndexedMap[PK, V, PV, I]) Delete(ctx sdk.Context, key PK) error
Delete fetches the object from the Map removes it from the Map then instructs every Indexer to remove the relationships between the object and the associated primary keys.
func (IndexedMap[PK, V, PV, I]) Get ¶
func (i IndexedMap[PK, V, PV, I]) Get(ctx sdk.Context, key PK) (V, error)
Get returns the object V given its primary key PK.
func (IndexedMap[PK, V, PV, I]) GetOr ¶
func (i IndexedMap[PK, V, PV, I]) GetOr(ctx sdk.Context, key PK, def V) V
GetOr returns the object V given its primary key PK, or if the operation fails returns the provided default.
func (IndexedMap[PK, V, PV, I]) Insert ¶
func (i IndexedMap[PK, V, PV, I]) Insert(ctx sdk.Context, key PK, v V)
Insert inserts the object v into the Map using the primary key, then iterates over every registered Indexer and instructs them to create the relationship between the primary key PK and the object v.
func (IndexedMap[PK, V, PV, I]) Iterate ¶
func (i IndexedMap[PK, V, PV, I]) Iterate(ctx sdk.Context, rng keys.Range[PK]) MapIterator[PK, V, PV]
Iterate iterates over the underlying store containing the concrete objects. The range provided filters over the primary keys.
type Indexer ¶
type Indexer[PK keys.Key, V any] interface { // Insert is called when the IndexedMap is inserting // an object into its state, so the Indexer here // creates the relationship between primary key // and the fields of the object V. Insert(ctx sdk.Context, primaryKey PK, v V) // Delete is called when the IndexedMap is removing // the object V and hence the relationship between // V and its primary keys need to be removed too. Delete(ctx sdk.Context, primaryKey PK, v V) }
Indexer defines an object which given an object V and a primary key PK, creates a relationship between one or multiple fields of the object V with the primary key PK.
type IndexerIterator ¶
type IndexerIterator[IK, PK keys.Key] KeySetIterator[keys.Pair[IK, PK]]
IndexerIterator wraps a KeySetIterator to provide more useful functionalities around index key iteration.
func (IndexerIterator[IK, PK]) Close ¶
func (i IndexerIterator[IK, PK]) Close()
func (IndexerIterator[IK, PK]) FullKey ¶
func (i IndexerIterator[IK, PK]) FullKey() keys.Pair[IK, PK]
FullKey returns the iterator current key composed of both indexing key and primary key.
func (IndexerIterator[IK, PK]) FullKeys ¶
func (i IndexerIterator[IK, PK]) FullKeys() []keys.Pair[IK, PK]
FullKeys fully consumes the iterator and returns the set of joined indexing key and primary key found.
func (IndexerIterator[IK, PK]) Next ¶
func (i IndexerIterator[IK, PK]) Next()
func (IndexerIterator[IK, PK]) PrimaryKey ¶
func (i IndexerIterator[IK, PK]) PrimaryKey() PK
PrimaryKey returns the iterator current primary key
func (IndexerIterator[IK, PK]) PrimaryKeys ¶
func (i IndexerIterator[IK, PK]) PrimaryKeys() []PK
PrimaryKeys fully consumes the iterator and returns the set of primary keys found.
func (IndexerIterator[IK, PK]) Valid ¶
func (i IndexerIterator[IK, PK]) Valid() bool
type IndexersProvider ¶
type IndexersProvider[PK keys.Key, V any] interface { // IndexerList provides the list of Indexer contained // in the struct. IndexerList() []Indexer[PK, V] }
IndexersProvider is implemented by structs containing a series of Indexer instances.
type Item ¶
Item represents a state object which will always have one instance of itself saved in the namespace. Examples are:
- config
- parameters
- a sequence
func NewItem ¶
func NewItem[V any, PV interface { *V Object }](cdc codec.BinaryCodec, sk sdk.StoreKey, prefix uint8) Item[V, PV]
NewItem instantiates a new Item instance.
type KeySet ¶
KeySet wraps the default Map, but is used only for keys.Key presence and ranging functionalities.
func (KeySet[K]) Delete ¶
Delete deletes the key from the set. Does not check if the key exists or not.
type KeySetIterator ¶
type KeySetIterator[K keys.Key] MapIterator[K, nilObject, *nilObject]
KeySetIterator wraps the default MapIterator, but is used only for keys.Key ranging.
func (KeySetIterator[K]) Close ¶
func (s KeySetIterator[K]) Close()
Close closes the KeySetIterator. No other operation is valid.
func (KeySetIterator[K]) Key ¶
func (s KeySetIterator[K]) Key() K
Key returns the current iterator key.
func (KeySetIterator[K]) Keys ¶
func (s KeySetIterator[K]) Keys() []K
Keys consumes the iterator fully and returns all the available keys. The KeySetIterator is closed after this operation.
func (KeySetIterator[K]) Next ¶
func (s KeySetIterator[K]) Next()
Next moves the iterator onto the next key.
func (KeySetIterator[K]) Valid ¶
func (s KeySetIterator[K]) Valid() bool
Valid checks if the iterator is still valid.
type Map ¶
type Map[K keys.Key, V any, PV interface { *V Object }] struct { // contains filtered or unexported fields }
Map defines a collection which simply does mappings between primary keys and objects.
type MapIterator ¶
type MapIterator[K keys.Key, V any, PV interface { *V Object }] struct { // contains filtered or unexported fields }
func (MapIterator[K, V, PV]) Close ¶
func (i MapIterator[K, V, PV]) Close()
func (MapIterator[K, V, PV]) Key ¶
func (i MapIterator[K, V, PV]) Key() K
func (MapIterator[K, V, PV]) KeyValues ¶
func (i MapIterator[K, V, PV]) KeyValues() []KeyValue[K, V, PV]
todo doc
func (MapIterator[K, V, PV]) Next ¶
func (i MapIterator[K, V, PV]) Next()
func (MapIterator[K, V, PV]) Valid ¶
func (i MapIterator[K, V, PV]) Valid() bool
func (MapIterator[K, V, PV]) Value ¶
func (i MapIterator[K, V, PV]) Value() V
type MultiIndex ¶
MultiIndex defines an Indexer with no uniqueness constraints. Meaning that given two objects V1 and V2 both can be indexed with the same secondary key. Example: Person1 { ID: 0, City: Milan } Person2 { ID: 1, City: Milan } Both can be indexed with the secondary key "Milan". The key generated are, respectively: keys.Pair[Milan, 0] keys.Pair[Milan, 1] So if we want to get all the objects whose City is Milan we prefix over keys.Pair[Milan, nil], and we get the respective primary keys: 0,1.
func NewMultiIndex ¶
func NewMultiIndex[IK, PK keys.Key, V any](cdc codec.BinaryCodec, sk sdk.StoreKey, namespace uint8, getIndexingKeyFunc func(v V) IK) MultiIndex[IK, PK, V]
NewMultiIndex instantiates a new MultiIndex instance. namespace is the unique storage namespace for the index. getIndexingKeyFunc is a function which given the object returns the key we use to index the object.
func (MultiIndex[IK, PK, V]) Delete ¶
func (i MultiIndex[IK, PK, V]) Delete(ctx sdk.Context, pk PK, v V)
Delete implements the Indexer interface.
func (MultiIndex[IK, PK, V]) ExactMatch ¶
func (i MultiIndex[IK, PK, V]) ExactMatch(ctx sdk.Context, ik IK) IndexerIterator[IK, PK]
ExactMatch returns an iterator of all the primary keys of objects which contain the provided indexing key ik.
func (MultiIndex[IK, PK, V]) Insert ¶
func (i MultiIndex[IK, PK, V]) Insert(ctx sdk.Context, pk PK, v V)
Insert implements the Indexer interface.
func (MultiIndex[IK, PK, V]) Iterate ¶
func (i MultiIndex[IK, PK, V]) Iterate(ctx sdk.Context, rng keys.Range[keys.Pair[IK, PK]]) IndexerIterator[IK, PK]
Iterate iterates over the provided range.
func (MultiIndex[IK, PK, V]) ReverseExactMatch ¶
func (i MultiIndex[IK, PK, V]) ReverseExactMatch(ctx sdk.Context, ik IK) IndexerIterator[IK, PK]
ReverseExactMatch works in the same way as ExactMatch, but the iteration happens in reverse.
type Object ¶
type Object interface { // Marshal marshals the object into bytes. Marshal() (b []byte, err error) // Unmarshal populates the object from bytes. Unmarshal(b []byte) error }
Object defines an object which can marshal and unmarshal itself to and from bytes.
type Sequence ¶
type Sequence struct {
// contains filtered or unexported fields
}
Sequence defines a collection item which contains an always increasing number. Useful for those flows which require ever raising unique ids.
func NewSequence ¶
NewSequence instantiates a new sequence object.
func (Sequence) Next ¶
Next returns the next available sequence number and also increases the sequence number count.