Documentation
¶
Overview ¶
To prevent namespace collision between consumer modules, we define a type Subspace. A Subspace can only be generated by the keeper, and the keeper checks the existence of the Subspace having the same name before generating the Subspace.
Consumer modules must take a Subspace (via Keeper.Subspace), not the keeper itself. This isolates each modules from the others and make them modify their respective parameters safely. Keeper can be treated as master permission for all Subspaces (via Keeper.GetSubspace), so should be passed to proper modules (ex. x/governance).
Index ¶
- Constants
- Variables
- func RegisterCodec(cdc *codec.Codec)
- func ValidateChanges(changes []ParamChange) error
- type KeyTable
- type ParamChange
- type ParamSet
- type ParamSetPair
- type ParamSetPairs
- type ParameterChangeProposal
- func (pcp ParameterChangeProposal) GetDescription() string
- func (pcp ParameterChangeProposal) GetTitle() string
- func (pcp ParameterChangeProposal) ProposalRoute() string
- func (pcp ParameterChangeProposal) ProposalType() string
- func (pcp ParameterChangeProposal) String() string
- func (pcp ParameterChangeProposal) ValidateBasic() error
- type QuerySubspaceParams
- type ReadOnlySubspace
- func (ros ReadOnlySubspace) Get(ctx sdk.Context, key []byte, ptr interface{})
- func (ros ReadOnlySubspace) GetRaw(ctx sdk.Context, key []byte) []byte
- func (ros ReadOnlySubspace) Has(ctx sdk.Context, key []byte) bool
- func (ros ReadOnlySubspace) Modified(ctx sdk.Context, key []byte) bool
- func (ros ReadOnlySubspace) Name() string
- type Subspace
- func (s Subspace) Get(ctx sdk.Context, key []byte, ptr interface{})
- func (s Subspace) GetIfExists(ctx sdk.Context, key []byte, ptr interface{})
- func (s Subspace) GetParamSet(ctx sdk.Context, ps ParamSet)
- func (s Subspace) GetRaw(ctx sdk.Context, key []byte) []byte
- func (s Subspace) Has(ctx sdk.Context, key []byte) bool
- func (s Subspace) HasKeyTable() bool
- func (s Subspace) Modified(ctx sdk.Context, key []byte) bool
- func (s Subspace) Name() string
- func (s Subspace) Set(ctx sdk.Context, key []byte, value interface{})
- func (s Subspace) SetParamSet(ctx sdk.Context, ps ParamSet)
- func (s Subspace) Update(ctx sdk.Context, key, value []byte) error
- func (s Subspace) Validate(ctx sdk.Context, key []byte, value interface{}) error
- func (s Subspace) WithKeyTable(table KeyTable) Subspace
- type SubspaceParamsResponse
- type ValueValidatorFn
Constants ¶
const ( // ModuleName defines the name of the module ModuleName = "params" // RouterKey defines the routing key for a ParameterChangeProposal RouterKey = "params" )
const ( // StoreKey is the string store key for the param store StoreKey = "params" // TStoreKey is the string store key for the param transient store TStoreKey = "transient_params" )
const (
// ProposalTypeChange defines the type for a ParameterChangeProposal
ProposalTypeChange = "ParameterChange"
)
const (
QueryParams = "params"
)
Querier path constants
Variables ¶
var ( ErrUnknownSubspace = sdkerrors.Register(ModuleName, 1, "unknown subspace") ErrSettingParameter = sdkerrors.Register(ModuleName, 2, "failed to set parameter") ErrEmptyChanges = sdkerrors.Register(ModuleName, 3, "submitted parameter changes are empty") ErrEmptySubspace = sdkerrors.Register(ModuleName, 4, "parameter subspace is empty") ErrEmptyKey = sdkerrors.Register(ModuleName, 5, "parameter key is empty") ErrEmptyValue = sdkerrors.Register(ModuleName, 6, "parameter value is empty") )
x/params module sentinel errors
var ModuleCdc *codec.Codec
Functions ¶
func RegisterCodec ¶
RegisterCodec registers all necessary param module types with a given codec.
func ValidateChanges ¶
func ValidateChanges(changes []ParamChange) error
ValidateChanges performs basic validation checks over a set of ParamChange. It returns an error if any ParamChange is invalid.
Types ¶
type KeyTable ¶ added in v0.0.2
type KeyTable struct {
// contains filtered or unexported fields
}
KeyTable subspaces appropriate type for each parameter key
func NewKeyTable ¶ added in v0.0.2
func NewKeyTable(pairs ...ParamSetPair) KeyTable
func (KeyTable) RegisterParamSet ¶ added in v0.0.2
RegisterParamSet registers multiple ParamSetPairs from a ParamSet in a KeyTable.
func (KeyTable) RegisterType ¶ added in v0.0.2
func (t KeyTable) RegisterType(psp ParamSetPair) KeyTable
RegisterType registers a single ParamSetPair (key-type pair) in a KeyTable.
type ParamChange ¶
type ParamChange struct {
Subspace string `json:"subspace" yaml:"subspace"`
Key string `json:"key" yaml:"key"`
Value string `json:"value" yaml:"value"`
}
ParamChange defines a parameter change.
func NewParamChange ¶
func NewParamChange(subspace, key, value string) ParamChange
func (ParamChange) String ¶
func (pc ParamChange) String() string
String implements the Stringer interface.
type ParamSet ¶ added in v0.0.2
type ParamSet interface {
ParamSetPairs() ParamSetPairs
}
ParamSet defines an interface for structs containing parameters for a module
type ParamSetPair ¶ added in v0.0.2
type ParamSetPair struct {
Key []byte
Value interface{}
ValidatorFn ValueValidatorFn
}
ParamSetPair is used for associating paramsubspace key and field of param structs.
func NewParamSetPair ¶ added in v0.0.2
func NewParamSetPair(key []byte, value interface{}, vfn ValueValidatorFn) ParamSetPair
NewParamSetPair creates a new ParamSetPair instance.
type ParamSetPairs ¶ added in v0.0.2
type ParamSetPairs []ParamSetPair
ParamSetPairs Slice of KeyFieldPair
type ParameterChangeProposal ¶
type ParameterChangeProposal struct {
Title string `json:"title" yaml:"title"`
Description string `json:"description" yaml:"description"`
Changes []ParamChange `json:"changes" yaml:"changes"`
}
ParameterChangeProposal defines a proposal which contains multiple parameter changes.
func NewParameterChangeProposal ¶
func NewParameterChangeProposal(title, description string, changes []ParamChange) ParameterChangeProposal
func (ParameterChangeProposal) GetDescription ¶
func (pcp ParameterChangeProposal) GetDescription() string
GetDescription returns the description of a parameter change proposal.
func (ParameterChangeProposal) GetTitle ¶
func (pcp ParameterChangeProposal) GetTitle() string
GetTitle returns the title of a parameter change proposal.
func (ParameterChangeProposal) ProposalRoute ¶
func (pcp ParameterChangeProposal) ProposalRoute() string
ProposalRoute returns the routing key of a parameter change proposal.
func (ParameterChangeProposal) ProposalType ¶
func (pcp ParameterChangeProposal) ProposalType() string
ProposalType returns the type of a parameter change proposal.
func (ParameterChangeProposal) String ¶
func (pcp ParameterChangeProposal) String() string
String implements the Stringer interface.
func (ParameterChangeProposal) ValidateBasic ¶
func (pcp ParameterChangeProposal) ValidateBasic() error
ValidateBasic validates the parameter change proposal
type QuerySubspaceParams ¶ added in v0.0.2
QuerySubspaceParams defines the params for querying module params by a given subspace and key.
func NewQuerySubspaceParams ¶ added in v0.0.2
func NewQuerySubspaceParams(ss, key string) QuerySubspaceParams
type ReadOnlySubspace ¶ added in v0.0.2
type ReadOnlySubspace struct {
// contains filtered or unexported fields
}
Wrapper of Subspace, provides immutable functions only
func (ReadOnlySubspace) Get ¶ added in v0.0.2
func (ros ReadOnlySubspace) Get(ctx sdk.Context, key []byte, ptr interface{})
Get delegates a read-only Get call to the Subspace.
func (ReadOnlySubspace) GetRaw ¶ added in v0.0.2
func (ros ReadOnlySubspace) GetRaw(ctx sdk.Context, key []byte) []byte
GetRaw delegates a read-only GetRaw call to the Subspace.
func (ReadOnlySubspace) Has ¶ added in v0.0.2
func (ros ReadOnlySubspace) Has(ctx sdk.Context, key []byte) bool
Has delegates a read-only Has call to the Subspace.
func (ReadOnlySubspace) Modified ¶ added in v0.0.2
func (ros ReadOnlySubspace) Modified(ctx sdk.Context, key []byte) bool
Modified delegates a read-only Modified call to the Subspace.
func (ReadOnlySubspace) Name ¶ added in v0.0.2
func (ros ReadOnlySubspace) Name() string
Name delegates a read-only Name call to the Subspace.
type Subspace ¶ added in v0.0.2
type Subspace struct {
// contains filtered or unexported fields
}
Individual parameter store for each keeper Transient store persists for a block, so we use it for recording whether the parameter has been changed or not
func NewSubspace ¶ added in v0.0.2
NewSubspace constructs a store with namestore
func (Subspace) Get ¶ added in v0.0.2
Get queries for a parameter by key from the Subspace's KVStore and sets the value to the provided pointer. If the value does not exist, it will panic.
func (Subspace) GetIfExists ¶ added in v0.0.2
GetIfExists queries for a parameter by key from the Subspace's KVStore and sets the value to the provided pointer. If the value does not exist, it will perform a no-op.
func (Subspace) GetParamSet ¶ added in v0.0.2
GetParamSet iterates through each ParamSetPair where for each pair, it will retrieve the value and set it to the corresponding value pointer provided in the ParamSetPair by calling Subspace#Get.
func (Subspace) GetRaw ¶ added in v0.0.2
GetRaw queries for the raw values bytes for a parameter by key.
func (Subspace) Has ¶ added in v0.0.2
Has returns if a parameter key exists or not in the Subspace's KVStore.
func (Subspace) HasKeyTable ¶ added in v0.0.2
HasKeyTable returns if the Subspace has a KeyTable registered.
func (Subspace) Modified ¶ added in v0.0.2
Modified returns true if the parameter key is set in the Subspace's transient KVStore.
func (Subspace) Set ¶ added in v0.0.2
Set stores a value for given a parameter key assuming the parameter type has been registered. It will panic if the parameter type has not been registered or if the value cannot be encoded. A change record is also set in the Subspace's transient KVStore to mark the parameter as modified.
func (Subspace) SetParamSet ¶ added in v0.0.2
SetParamSet iterates through each ParamSetPair and sets the value with the corresponding parameter key in the Subspace's KVStore.
func (Subspace) Update ¶ added in v0.0.2
Update stores an updated raw value for a given parameter key assuming the parameter type has been registered. It will panic if the parameter type has not been registered or if the value cannot be encoded. An error is returned if the raw value is not compatible with the registered type for the parameter key or if the new value is invalid as determined by the registered type's validation function.
func (Subspace) Validate ¶ added in v0.0.2
Validate attempts to validate a parameter value by its key. If the key is not registered or if the validation of the value fails, an error is returned.
func (Subspace) WithKeyTable ¶ added in v0.0.2
WithKeyTable initializes KeyTable and returns modified Subspace
type SubspaceParamsResponse ¶ added in v0.0.2
SubspaceParamsResponse defines the response for quering parameters by subspace.
func NewSubspaceParamsResponse ¶ added in v0.0.2
func NewSubspaceParamsResponse(ss, key, value string) SubspaceParamsResponse
type ValueValidatorFn ¶ added in v0.0.2
type ValueValidatorFn func(value interface{}) error