corecompat

package
v1.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 1, 2025 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package corecompat defines the store, codec and genesis interface that collections expects or implements. These interfaces are all redefined from cosmossdk.io/core in order to avoid a direct dependency on cosmossdk.io/core.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BinaryCodec

type BinaryCodec interface {
	Marshal(ProtoMsg) ([]byte, error)
	Unmarshal([]byte, ProtoMsg) error
}

BinaryCodec defines a binary encoding and decoding interface for modules to encode and decode data.

type Codec

type Codec interface {
	BinaryCodec
	JSONCodec
}

Codec defines a Binary Codec and JSON Codec for modules to encode and decode data.

type GenesisSource

type GenesisSource = func(field string) (io.ReadCloser, error)

GenesisSource is a source for genesis data in JSON format. It may abstract over a single JSON object or separate files for each field in a JSON object that can be streamed over. Modules should open a separate io.ReadCloser for each field that is required. When fields represent arrays they can efficiently be streamed over. If there is no data for a field, this function should return nil, nil. It is important that the caller closes the reader when done with it.

type GenesisTarget

type GenesisTarget = func(field string) (io.WriteCloser, error)

GenesisTarget is a target for writing genesis data in JSON format. It may abstract over a single JSON object or JSON in separate files that can be streamed over. Modules should open a separate io.WriteCloser for each field and should prefer writing fields as arrays when possible to support efficient iteration. It is important the caller closers the writer AND checks the error when done with it. It is expected that a stream of JSON data is written to the writer.

type Iterator

type Iterator = interface {
	// Domain returns the start (inclusive) and end (exclusive) limits of the iterator.
	Domain() (start, end []byte)

	// Valid returns whether the current iterator is valid. Once invalid, the Iterator remains
	// invalid forever.
	Valid() bool

	// Next moves the iterator to the next key in the database, as defined by order of iteration.
	// If Valid returns false, this method will panic.
	Next()

	// Key returns the key at the current position. Panics if the iterator is invalid.
	// Note, the key returned should be a copy and thus safe for modification.
	Key() []byte

	// Value returns the value at the current position. Panics if the iterator is
	// invalid.
	// Note, the value returned should be a copy and thus safe for modification.
	Value() []byte

	// Error returns the last error encountered by the iterator, if any.
	Error() error

	// Close closes the iterator, releasing any allocated resources.
	Close() error
}

Iterator represents an iterator over a domain of keys. Callers must call Close when done. No writes can happen to a domain while there exists an iterator over it. Some backends may take out database locks to ensure this will not happen.

Callers must make sure the iterator is valid before calling any methods on it, otherwise these methods will panic.

type JSONCodec

type JSONCodec interface {
	MarshalJSON(ProtoMsg) ([]byte, error)
	UnmarshalJSON([]byte, ProtoMsg) error
}

JSONCodec defines a JSON encoding and decoding interface for modules to encode and decode data.

type KVStore

type KVStore = interface {
	// Get returns nil iff key doesn't exist. Errors on nil key.
	Get(key []byte) ([]byte, error)

	// Has checks if a key exists. Errors on nil key.
	Has(key []byte) (bool, error)

	// Set sets the key. Errors on nil key or value.
	Set(key, value []byte) error

	// Delete deletes the key. Errors on nil key.
	Delete(key []byte) error

	// Iterator iterates over a domain of keys in ascending order. End is exclusive.
	// Start must be less than end, or the Iterator is invalid.
	// Iterator must be closed by caller.
	// To iterate over entire domain, use store.Iterator(nil, nil)
	// CONTRACT: No writes may happen within a domain while an iterator exists over it.
	// Exceptionally allowed for cachekv.Store, safe to write in the modules.
	Iterator(start, end []byte) (Iterator, error)

	// ReverseIterator iterates over a domain of keys in descending order. End is exclusive.
	// Start must be less than end, or the Iterator is invalid.
	// Iterator must be closed by caller.
	// CONTRACT: No writes may happen within a domain while an iterator exists over it.
	// Exceptionally allowed for cachekv.Store, safe to write in the modules.
	ReverseIterator(start, end []byte) (Iterator, error)
}

KVStore describes the basic interface for interacting with key-value stores.

type KVStoreService

type KVStoreService = interface {
	// OpenKVStore retrieves the KVStore from the context.
	OpenKVStore(context.Context) KVStore
}

KVStoreService represents a unique, non-forgeable handle to a regular merkle-tree backed KVStore. It should be provided as a module-scoped dependency by the runtime module being used to build the app.

type MemoryStoreService

type MemoryStoreService = interface {
	// OpenMemoryStore retrieves the memory store from the context.
	OpenMemoryStore(context.Context) KVStore
}

MemoryStoreService represents a unique, non-forgeable handle to a memory-backed KVStore. It should be provided as a module-scoped dependency by the runtime module being used to build the app.

type ProtoMsg

type ProtoMsg = interface {
	Reset()
	String() string
	ProtoMessage()
}

ProtoMsg defines the legacy golang proto message interface.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳