refactor(schema)!: move view interfaces from testing to schema (#21204)

This commit is contained in:
Aaron Craelius
2024-08-12 21:04:23 +00:00
committed by GitHub
parent df3b035dd8
commit 431b52309c
16 changed files with 254 additions and 124 deletions
+15
View File
@@ -0,0 +1,15 @@
package view
// AppState defines an interface for things that represent application state in schema format.
type AppState interface {
// GetModule returns the module state for the given module name. If the module does not exist, nil and no error
// should be returned.
GetModule(moduleName string) (ModuleState, error)
// Modules iterates over all the module state instances in the app. If there is an error getting a module state,
// modState may be nil and err will be non-nil.
Modules(f func(modState ModuleState, err error) bool)
// NumModules returns the number of modules in the app.
NumModules() (int, error)
}
+16
View File
@@ -0,0 +1,16 @@
package view
// AppData is an interface which indexer data targets can implement to allow their app data including
// state, blocks, transactions and events to be queried. An app's state and event store can also implement
// this interface to provide an authoritative source of data for comparing with indexed data.
type AppData interface {
// BlockNum indicates the last block that was persisted. It should be 0 if the target has no data
// stored and wants to start syncing state.
// If an indexer starts indexing after a chain's genesis (returning 0), the indexer manager
// will attempt to perform a catch-up sync of state. Historical events will not be replayed, but an accurate
// representation of the current state at the height at which indexing began can be reproduced.
BlockNum() (uint64, error)
// AppState returns the app state. If the view doesn't persist app state, nil should be returned.
AppState() AppState
}
+2
View File
@@ -0,0 +1,2 @@
// Package view defines interfaces for viewing the data stored in an indexer target or an app's original data store.
package view
+23
View File
@@ -0,0 +1,23 @@
package view
import "cosmossdk.io/schema"
// ModuleState defines an interface for things that represent module state in schema format.
type ModuleState interface {
// ModuleName returns the name of the module.
ModuleName() string
// ModuleSchema returns the schema for the module.
ModuleSchema() schema.ModuleSchema
// GetObjectCollection returns the object collection for the given object type. If the object collection
// does not exist, nil and no error should be returned
GetObjectCollection(objectType string) (ObjectCollection, error)
// ObjectCollections iterates over all the object collections in the module. If there is an error getting an object
// collection, objColl may be nil and err will be non-nil.
ObjectCollections(f func(value ObjectCollection, err error) bool)
// NumObjectCollections returns the number of object collections in the module.
NumObjectCollections() (int, error)
}
+27
View File
@@ -0,0 +1,27 @@
package view
import "cosmossdk.io/schema"
// ObjectCollection is the interface for viewing the state of a collection of objects in a module
// represented by ObjectUpdate's for an ObjectType. ObjectUpdates must not include
// ValueUpdates in the Value field. When ValueUpdates are applied they must be
// converted to individual value or array format depending on the number of fields in
// the value. For collections which retain deletions, ObjectUpdate's with the Delete
// field set to true should be returned with the latest Value still intact.
type ObjectCollection interface {
// ObjectType returns the object type for the collection.
ObjectType() schema.ObjectType
// GetObject returns the object update for the given key if it exists. And error should only be returned
// if there was an error getting the object update. If the object does not exist but there was no error,
// then found should be false and the error should be nil.
GetObject(key interface{}) (update schema.ObjectUpdate, found bool, err error)
// AllState iterates over the state of the collection by calling the given function with each item in
// state represented as an object update. If there is an error getting an object update, the error will be
// non-nil and the object update should be empty.
AllState(f func(schema.ObjectUpdate, error) bool)
// Len returns the number of objects in the collection.
Len() (int, error)
}