cosmos-sdk/schema/decoder.go
Aaron Craelius 38c1d6a5d4
refactor(indexer/base): move to cosmossdk.io/schema (#20744)
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
2024-06-26 15:46:08 +00:00

26 lines
1.1 KiB
Go

package schema
// HasModuleCodec is an interface that modules can implement to provide a ModuleCodec.
// Usually these modules would also implement appmodule.AppModule, but that is not included
// to keep this package free of any dependencies.
type HasModuleCodec interface {
// ModuleCodec returns a ModuleCodec for the module.
ModuleCodec() (ModuleCodec, error)
}
// ModuleCodec is a struct that contains the schema and a KVDecoder for a module.
type ModuleCodec struct {
// Schema is the schema for the module. It is required.
Schema ModuleSchema
// KVDecoder is a function that decodes a key-value pair into an ObjectUpdate.
// If it is nil, the module doesn't support state decoding directly.
KVDecoder KVDecoder
}
// KVDecoder is a function that decodes a key-value pair into an ObjectUpdate.
// If the KV-pair doesn't represent an object update, the function should return false
// as the second return value. Error should only be non-nil when the decoder expected
// to parse a valid update and was unable to.
type KVDecoder = func(key, value []byte) (ObjectUpdate, bool, error)